diff options
author | 2023-07-27 01:30:39 -0700 | |
---|---|---|
committer | 2023-07-27 10:30:39 +0200 | |
commit | 22ac4607a1c283a719eea95844e07513b8a67570 (patch) | |
tree | 61baf7949b62f84d2dff29c4d99614d946774f64 /internal/cache/gts.go | |
parent | [performance] retry db queries on busy errors (#2025) (diff) | |
download | gotosocial-22ac4607a1c283a719eea95844e07513b8a67570.tar.xz |
[feature] Support setting private notes on accounts (#1982)
* Support setting private notes on accounts
* Reformat comment whitespace
* Add missing license headers
* Use apiutil.ParseID
* Rename Note model and cache to AccountNote
* Update golden cache config in test/envparsing.sh
* Rename gtsmodel/note.go to gtsmodel/accountnote.go
* Update AccountNote uniqueness constraint name
Now has same prefix as other indexes on this table.
---------
Co-authored-by: tobi <31960611+tsmethurst@users.noreply.github.com>
Diffstat (limited to 'internal/cache/gts.go')
-rw-r--r-- | internal/cache/gts.go | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/internal/cache/gts.go b/internal/cache/gts.go index 8082a9fdf..81c6e9f9e 100644 --- a/internal/cache/gts.go +++ b/internal/cache/gts.go @@ -26,8 +26,9 @@ import ( ) type GTSCaches struct { - account *result.Cache[*gtsmodel.Account] - block *result.Cache[*gtsmodel.Block] + account *result.Cache[*gtsmodel.Account] + accountNote *result.Cache[*gtsmodel.AccountNote] + block *result.Cache[*gtsmodel.Block] // TODO: maybe should be moved out of here since it's // not actually doing anything with gtsmodel.DomainBlock. domainBlock *domain.BlockCache @@ -54,6 +55,7 @@ type GTSCaches struct { // NOTE: the cache MUST NOT be in use anywhere, this is not thread-safe. func (c *GTSCaches) Init() { c.initAccount() + c.initAccountNote() c.initBlock() c.initDomainBlock() c.initEmoji() @@ -77,6 +79,7 @@ func (c *GTSCaches) Init() { // Start will attempt to start all of the gtsmodel caches, or panic. func (c *GTSCaches) Start() { tryStart(c.account, config.GetCacheGTSAccountSweepFreq()) + tryStart(c.accountNote, config.GetCacheGTSAccountNoteSweepFreq()) tryStart(c.block, config.GetCacheGTSBlockSweepFreq()) tryStart(c.emoji, config.GetCacheGTSEmojiSweepFreq()) tryStart(c.emojiCategory, config.GetCacheGTSEmojiCategorySweepFreq()) @@ -104,6 +107,7 @@ func (c *GTSCaches) Start() { // Stop will attempt to stop all of the gtsmodel caches, or panic. func (c *GTSCaches) Stop() { tryStop(c.account, config.GetCacheGTSAccountSweepFreq()) + tryStop(c.accountNote, config.GetCacheGTSAccountNoteSweepFreq()) tryStop(c.block, config.GetCacheGTSBlockSweepFreq()) tryStop(c.emoji, config.GetCacheGTSEmojiSweepFreq()) tryStop(c.emojiCategory, config.GetCacheGTSEmojiCategorySweepFreq()) @@ -128,6 +132,11 @@ func (c *GTSCaches) Account() *result.Cache[*gtsmodel.Account] { return c.account } +// AccountNote provides access to the gtsmodel Note database cache. +func (c *GTSCaches) AccountNote() *result.Cache[*gtsmodel.AccountNote] { + return c.accountNote +} + // Block provides access to the gtsmodel Block (account) database cache. func (c *GTSCaches) Block() *result.Cache[*gtsmodel.Block] { return c.block @@ -238,6 +247,19 @@ func (c *GTSCaches) initAccount() { c.account.IgnoreErrors(ignoreErrors) } +func (c *GTSCaches) initAccountNote() { + c.accountNote = result.New([]result.Lookup{ + {Name: "ID"}, + {Name: "AccountID.TargetAccountID"}, + }, func(n1 *gtsmodel.AccountNote) *gtsmodel.AccountNote { + n2 := new(gtsmodel.AccountNote) + *n2 = *n1 + return n2 + }, config.GetCacheGTSAccountNoteMaxSize()) + c.accountNote.SetTTL(config.GetCacheGTSAccountNoteTTL(), true) + c.accountNote.IgnoreErrors(ignoreErrors) +} + func (c *GTSCaches) initBlock() { c.block = result.New([]result.Lookup{ {Name: "ID"}, |