diff options
author | 2023-03-03 23:02:23 +0000 | |
---|---|---|
committer | 2023-03-03 23:02:23 +0000 | |
commit | a8e6bdfa33f3232ebc8f241b9c90e4da9191a627 (patch) | |
tree | 087eca372fb13093f39837683682ca9e11b96188 /internal/db/bundb/status.go | |
parent | [bugfix] Federate status delete using just the URI (#1584) (diff) | |
download | gotosocial-a8e6bdfa33f3232ebc8f241b9c90e4da9191a627.tar.xz |
[performance] cache media attachments (#1525)
* replace concurrency worker pools with base models in State.Workers, update code and tests accordingly
* add media attachment caching, slightly tweak default cache config
* further tweak default cache config values
* replace other media attachment db calls to go through cache
* update envparsing test
* fix delete media attachment sql
* fix media sql query
* invalidate cached media entries during status create / update
* fix envparsing test
* fix typo in panic log message...
* add 'updated_at' column during UpdateAttachment
* remove unused func
---------
Signed-off-by: kim <grufwub@gmail.com>
Diffstat (limited to 'internal/db/bundb/status.go')
-rw-r--r-- | internal/db/bundb/status.go | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/internal/db/bundb/status.go b/internal/db/bundb/status.go index 72e44068d..3bbf67657 100644 --- a/internal/db/bundb/status.go +++ b/internal/db/bundb/status.go @@ -188,7 +188,7 @@ func (s *statusDB) getStatus(ctx context.Context, lookup string, dbQuery func(*g } func (s *statusDB) PutStatus(ctx context.Context, status *gtsmodel.Status) db.Error { - return s.state.Caches.GTS.Status().Store(status, func() error { + err := s.state.Caches.GTS.Status().Store(status, func() error { // It is safe to run this database transaction within cache.Store // as the cache does not attempt a mutex lock until AFTER hook. // @@ -248,6 +248,17 @@ func (s *statusDB) PutStatus(ctx context.Context, status *gtsmodel.Status) db.Er return err }) }) + if err != nil { + // already processed + return err + } + + for _, id := range status.AttachmentIDs { + // Clear updated media attachment IDs from cache + s.state.Caches.GTS.Media().Invalidate("ID", id) + } + + return nil } func (s *statusDB) UpdateStatus(ctx context.Context, status *gtsmodel.Status, columns ...string) db.Error { @@ -317,11 +328,18 @@ func (s *statusDB) UpdateStatus(ctx context.Context, status *gtsmodel.Status, co Exec(ctx) return err }); err != nil { + // already processed return err } - // Drop any old value from cache by this ID + for _, id := range status.AttachmentIDs { + // Clear updated media attachment IDs from cache + s.state.Caches.GTS.Media().Invalidate("ID", id) + } + + // Drop any old status value from cache by this ID s.state.Caches.GTS.Status().Invalidate("ID", status.ID) + return nil } |