diff options
author | 2024-09-23 11:53:42 +0000 | |
---|---|---|
committer | 2024-09-23 11:53:42 +0000 | |
commit | 4592e290872e0208d03189aea4f410cd47a5dc1d (patch) | |
tree | 00df4221fc924e8fdcafc985f33c0395687a711c /internal/cache | |
parent | [chore] header filter improvements (#3329) (diff) | |
download | gotosocial-4592e290872e0208d03189aea4f410cd47a5dc1d.tar.xz |
[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
Diffstat (limited to 'internal/cache')
-rw-r--r-- | internal/cache/db.go | 17 | ||||
-rw-r--r-- | internal/cache/invalidate.go | 14 |
2 files changed, 28 insertions, 3 deletions
diff --git a/internal/cache/db.go b/internal/cache/db.go index fe9085613..dd4e8b212 100644 --- a/internal/cache/db.go +++ b/internal/cache/db.go @@ -18,6 +18,8 @@ package cache import ( + "sync/atomic" + "codeberg.org/gruf/go-structr" "github.com/superseriousbusiness/gotosocial/internal/cache/domain" "github.com/superseriousbusiness/gotosocial/internal/config" @@ -136,6 +138,14 @@ type DBCaches struct { // Instance provides access to the gtsmodel Instance database cache. Instance StructCache[*gtsmodel.Instance] + // LocalInstance provides caching for + // simple + common local instance queries. + LocalInstance struct { + Domains atomic.Pointer[int] + Statuses atomic.Pointer[int] + Users atomic.Pointer[int] + } + // InteractionRequest provides access to the gtsmodel InteractionRequest database cache. InteractionRequest StructCache[*gtsmodel.InteractionRequest] @@ -849,9 +859,10 @@ func (c *Caches) initInstance() { {Fields: "ID"}, {Fields: "Domain"}, }, - MaxSize: cap, - IgnoreErr: ignoreErrors, - Copy: copyF, + MaxSize: cap, + IgnoreErr: ignoreErrors, + Copy: copyF, + Invalidate: c.OnInvalidateInstance, }) } diff --git a/internal/cache/invalidate.go b/internal/cache/invalidate.go index ca12e412c..9b42e88f6 100644 --- a/internal/cache/invalidate.go +++ b/internal/cache/invalidate.go @@ -19,6 +19,7 @@ package cache import ( "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" + "github.com/superseriousbusiness/gotosocial/internal/util" ) // Below are cache invalidation hooks between other caches, @@ -178,6 +179,11 @@ func (c *Caches) OnInvalidateFollowRequest(followReq *gtsmodel.FollowRequest) { ) } +func (c *Caches) OnInvalidateInstance(instance *gtsmodel.Instance) { + // Invalidate the local domains count. + c.DB.LocalInstance.Domains.Store(nil) +} + func (c *Caches) OnInvalidateList(list *gtsmodel.List) { // Invalidate list IDs cache. c.DB.ListIDs.Invalidate( @@ -255,6 +261,11 @@ func (c *Caches) OnInvalidateStatus(status *gtsmodel.Status) { // Invalidate cache of attached poll ID. c.DB.Poll.Invalidate("ID", status.PollID) } + + if util.PtrOrZero(status.Local) { + // Invalidate the local statuses count. + c.DB.LocalInstance.Statuses.Store(nil) + } } func (c *Caches) OnInvalidateStatusBookmark(bookmark *gtsmodel.StatusBookmark) { @@ -271,6 +282,9 @@ func (c *Caches) OnInvalidateUser(user *gtsmodel.User) { // Invalidate local account ID cached visibility. c.Visibility.Invalidate("ItemID", user.AccountID) c.Visibility.Invalidate("RequesterID", user.AccountID) + + // Invalidate the local users count. + c.DB.LocalInstance.Users.Store(nil) } func (c *Caches) OnInvalidateUserMute(mute *gtsmodel.UserMute) { |