summaryrefslogtreecommitdiff
path: root/internal/cache/gts.go
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2023-03-03 23:02:23 +0000
committerLibravatar GitHub <noreply@github.com>2023-03-03 23:02:23 +0000
commita8e6bdfa33f3232ebc8f241b9c90e4da9191a627 (patch)
tree087eca372fb13093f39837683682ca9e11b96188 /internal/cache/gts.go
parent[bugfix] Federate status delete using just the URI (#1584) (diff)
downloadgotosocial-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/cache/gts.go')
-rw-r--r--internal/cache/gts.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/internal/cache/gts.go b/internal/cache/gts.go
index f3f7a33ef..253dc47b2 100644
--- a/internal/cache/gts.go
+++ b/internal/cache/gts.go
@@ -54,6 +54,9 @@ type GTSCaches interface {
// Mention provides access to the gtsmodel Mention database cache.
Mention() *result.Cache[*gtsmodel.Mention]
+ // Media provides access to the gtsmodel Media database cache.
+ Media() *result.Cache[*gtsmodel.MediaAttachment]
+
// Notification provides access to the gtsmodel Notification database cache.
Notification() *result.Cache[*gtsmodel.Notification]
@@ -81,6 +84,7 @@ type gtsCaches struct {
domainBlock *domain.BlockCache
emoji *result.Cache[*gtsmodel.Emoji]
emojiCategory *result.Cache[*gtsmodel.EmojiCategory]
+ media *result.Cache[*gtsmodel.MediaAttachment]
mention *result.Cache[*gtsmodel.Mention]
notification *result.Cache[*gtsmodel.Notification]
report *result.Cache[*gtsmodel.Report]
@@ -95,6 +99,7 @@ func (c *gtsCaches) Init() {
c.initDomainBlock()
c.initEmoji()
c.initEmojiCategory()
+ c.initMedia()
c.initMention()
c.initNotification()
c.initReport()
@@ -119,6 +124,9 @@ func (c *gtsCaches) Start() {
tryUntil("starting gtsmodel.EmojiCategory cache", 5, func() bool {
return c.emojiCategory.Start(config.GetCacheGTSEmojiCategorySweepFreq())
})
+ tryUntil("starting gtsmodel.MediaAttachment cache", 5, func() bool {
+ return c.media.Start(config.GetCacheGTSMediaSweepFreq())
+ })
tryUntil("starting gtsmodel.Mention cache", 5, func() bool {
return c.mention.Start(config.GetCacheGTSMentionSweepFreq())
})
@@ -145,6 +153,7 @@ func (c *gtsCaches) Stop() {
tryUntil("stopping gtsmodel.DomainBlock cache", 5, c.domainBlock.Stop)
tryUntil("stopping gtsmodel.Emoji cache", 5, c.emoji.Stop)
tryUntil("stopping gtsmodel.EmojiCategory cache", 5, c.emojiCategory.Stop)
+ tryUntil("stopping gtsmodel.MediaAttachment cache", 5, c.media.Stop)
tryUntil("stopping gtsmodel.Mention cache", 5, c.mention.Stop)
tryUntil("stopping gtsmodel.Notification cache", 5, c.notification.Stop)
tryUntil("stopping gtsmodel.Report cache", 5, c.report.Stop)
@@ -173,6 +182,10 @@ func (c *gtsCaches) EmojiCategory() *result.Cache[*gtsmodel.EmojiCategory] {
return c.emojiCategory
}
+func (c *gtsCaches) Media() *result.Cache[*gtsmodel.MediaAttachment] {
+ return c.media
+}
+
func (c *gtsCaches) Mention() *result.Cache[*gtsmodel.Mention] {
return c.mention
}
@@ -258,6 +271,17 @@ func (c *gtsCaches) initEmojiCategory() {
c.emojiCategory.SetTTL(config.GetCacheGTSEmojiCategoryTTL(), true)
}
+func (c *gtsCaches) initMedia() {
+ c.media = result.New([]result.Lookup{
+ {Name: "ID"},
+ }, func(m1 *gtsmodel.MediaAttachment) *gtsmodel.MediaAttachment {
+ m2 := new(gtsmodel.MediaAttachment)
+ *m2 = *m1
+ return m2
+ }, config.GetCacheGTSMediaMaxSize())
+ c.media.SetTTL(config.GetCacheGTSMediaTTL(), true)
+}
+
func (c *gtsCaches) initMention() {
c.mention = result.New([]result.Lookup{
{Name: "ID"},