[chore] local instance count query caching, improved status context endpoint logging, don't log ErrHideStatus when timelining (#3330)

* ensure that errors checking status visibility / converting aren't dropped

* add some more context to error messages

* include calling function name in log entries

* don't error on timelining hidden status

* further code to ignore statusfilter.ErrHideStatus type errors

* remove unused error type

* add local instance status / domain / user counts

* add checks for localhost

* rename from InstanceCounts to LocalInstance

* improved code comment
This commit is contained in:
kim 2024-09-23 11:53:42 +00:00 committed by GitHub
commit 4592e29087
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 214 additions and 91 deletions

View file

@ -104,18 +104,20 @@ func (f *Filter) isStatusVisible(
return false, nil
}
if util.PtrOrValue(status.PendingApproval, false) {
if util.PtrOrZero(status.PendingApproval) {
// Use a different visibility heuristic
// for pending approval statuses.
return f.isPendingStatusVisible(ctx,
return isPendingStatusVisible(
requester, status,
)
), nil
}
if requester == nil {
// Use a different visibility
// heuristic for unauthed requests.
return f.isStatusVisibleUnauthed(ctx, status)
return f.isStatusVisibleUnauthed(
ctx, status,
)
}
/*
@ -210,45 +212,42 @@ func (f *Filter) isStatusVisible(
}
}
func (f *Filter) isPendingStatusVisible(
_ context.Context,
requester *gtsmodel.Account,
status *gtsmodel.Status,
) (bool, error) {
// isPendingStatusVisible returns whether a status pending approval is visible to requester.
func isPendingStatusVisible(requester *gtsmodel.Account, status *gtsmodel.Status) bool {
if requester == nil {
// Any old tom, dick, and harry can't
// see pending-approval statuses,
// no matter what their visibility.
return false, nil
return false
}
if status.AccountID == requester.ID {
// This is requester's status,
// so they can always see it.
return true, nil
return true
}
if status.InReplyToAccountID == requester.ID {
// This status replies to requester,
// so they can always see it (else
// they can't approve it).
return true, nil
return true
}
if status.BoostOfAccountID == requester.ID {
// This status boosts requester,
// so they can always see it.
return true, nil
return true
}
// Nobody else can see this.
return false, nil
// Nobody else
// can see this.
return false
}
func (f *Filter) isStatusVisibleUnauthed(
ctx context.Context,
status *gtsmodel.Status,
) (bool, error) {
// isStatusVisibleUnauthed returns whether status is visible without any unauthenticated account.
func (f *Filter) isStatusVisibleUnauthed(ctx context.Context, status *gtsmodel.Status) (bool, error) {
// For remote accounts, only show
// Public statuses via the web.
if status.Account.IsRemote() {
@ -275,8 +274,7 @@ func (f *Filter) isStatusVisibleUnauthed(
}
}
webVisibility := status.Account.Settings.WebVisibility
switch webVisibility {
switch webvis := status.Account.Settings.WebVisibility; webvis {
// public_only: status must be Public.
case gtsmodel.VisibilityPublic:
@ -296,7 +294,7 @@ func (f *Filter) isStatusVisibleUnauthed(
default:
return false, gtserror.Newf(
"unrecognized web visibility for account %s: %s",
status.Account.ID, webVisibility,
status.Account.ID, webvis,
)
}
}