diff options
author | 2022-12-08 17:35:14 +0000 | |
---|---|---|
committer | 2022-12-08 18:35:14 +0100 | |
commit | e58d2d81226c4cc4110747305d083b67903d621c (patch) | |
tree | 249f8b3f4732ccdb1e77b2d4243fafb4ee4c1c86 /internal/db/bundb/notification.go | |
parent | [chore] Remove deprecated linters (#1228) (diff) | |
download | gotosocial-e58d2d81226c4cc4110747305d083b67903d621c.tar.xz |
[chore] move caches to a separate State{} structure (#1078)
* move caches to a separate State{} structure
Signed-off-by: kim <grufwub@gmail.com>
* fix call to log.Panic not using formatted call
Signed-off-by: kim <grufwub@gmail.com>
* move caches to use interfaces, to make switchouts easier in future
Signed-off-by: kim <grufwub@gmail.com>
* fix rebase issue
Signed-off-by: kim <grufwub@gmail.com>
* improve code comment
Signed-off-by: kim <grufwub@gmail.com>
* fix further issues after rebase
Signed-off-by: kim <grufwub@gmail.com>
* heh
Signed-off-by: kim <grufwub@gmail.com>
* add missing license text
Signed-off-by: kim <grufwub@gmail.com>
Signed-off-by: kim <grufwub@gmail.com>
Diffstat (limited to 'internal/db/bundb/notification.go')
-rw-r--r-- | internal/db/bundb/notification.go | 24 |
1 files changed, 4 insertions, 20 deletions
diff --git a/internal/db/bundb/notification.go b/internal/db/bundb/notification.go index 6a8fab464..a65d799c3 100644 --- a/internal/db/bundb/notification.go +++ b/internal/db/bundb/notification.go @@ -20,37 +20,21 @@ package bundb import ( "context" - "time" - "codeberg.org/gruf/go-cache/v3/result" "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" "github.com/superseriousbusiness/gotosocial/internal/log" + "github.com/superseriousbusiness/gotosocial/internal/state" "github.com/uptrace/bun" ) type notificationDB struct { conn *DBConn - cache *result.Cache[*gtsmodel.Notification] -} - -func (n *notificationDB) init() { - // Initialize notification result cache - n.cache = result.NewSized([]result.Lookup{ - {Name: "ID"}, - }, func(n1 *gtsmodel.Notification) *gtsmodel.Notification { - n2 := new(gtsmodel.Notification) - *n2 = *n1 - return n2 - }, 1000) - - // Set cache TTL and start sweep routine - n.cache.SetTTL(time.Minute*5, false) - n.cache.Start(time.Second * 10) + state *state.State } func (n *notificationDB) GetNotification(ctx context.Context, id string) (*gtsmodel.Notification, db.Error) { - return n.cache.Load("ID", func() (*gtsmodel.Notification, error) { + return n.state.Caches.GTS.Notification().Load("ID", func() (*gtsmodel.Notification, error) { var notif gtsmodel.Notification q := n.conn.NewSelect(). @@ -130,6 +114,6 @@ func (n *notificationDB) ClearNotifications(ctx context.Context, accountID strin return n.conn.ProcessError(err) } - n.cache.Clear() + n.state.Caches.GTS.Notification().Clear() return nil } |