summaryrefslogtreecommitdiff
path: root/internal/cache
diff options
context:
space:
mode:
Diffstat (limited to 'internal/cache')
-rw-r--r--internal/cache/emoji.go21
1 files changed, 18 insertions, 3 deletions
diff --git a/internal/cache/emoji.go b/internal/cache/emoji.go
index eda7583ea..117f5475e 100644
--- a/internal/cache/emoji.go
+++ b/internal/cache/emoji.go
@@ -37,19 +37,26 @@ func NewEmojiCache() *EmojiCache {
RegisterLookups: func(lm *cache.LookupMap[string, string]) {
lm.RegisterLookup("uri")
lm.RegisterLookup("shortcodedomain")
+ lm.RegisterLookup("imagestaticurl")
},
AddLookups: func(lm *cache.LookupMap[string, string], emoji *gtsmodel.Emoji) {
+ lm.Set("shortcodedomain", shortcodeDomainKey(emoji.Shortcode, emoji.Domain), emoji.ID)
if uri := emoji.URI; uri != "" {
- lm.Set("uri", uri, emoji.URI)
- lm.Set("shortcodedomain", shortcodeDomainKey(emoji.Shortcode, emoji.Domain), emoji.ID)
+ lm.Set("uri", uri, emoji.ID)
+ }
+ if imageStaticURL := emoji.ImageStaticURL; imageStaticURL != "" {
+ lm.Set("imagestaticurl", imageStaticURL, emoji.ID)
}
},
DeleteLookups: func(lm *cache.LookupMap[string, string], emoji *gtsmodel.Emoji) {
+ lm.Delete("shortcodedomain", shortcodeDomainKey(emoji.Shortcode, emoji.Domain))
if uri := emoji.URI; uri != "" {
lm.Delete("uri", uri)
- lm.Delete("shortcodedomain", shortcodeDomainKey(emoji.Shortcode, emoji.Domain))
+ }
+ if imageStaticURL := emoji.ImageStaticURL; imageStaticURL != "" {
+ lm.Delete("imagestaticurl", imageStaticURL)
}
},
})
@@ -72,6 +79,10 @@ func (c *EmojiCache) GetByShortcodeDomain(shortcode string, domain string) (*gts
return c.cache.GetBy("shortcodedomain", shortcodeDomainKey(shortcode, domain))
}
+func (c *EmojiCache) GetByImageStaticURL(imageStaticURL string) (*gtsmodel.Emoji, bool) {
+ return c.cache.GetBy("imagestaticurl", imageStaticURL)
+}
+
// Put places an emoji in the cache, ensuring that the object place is a copy for thread-safety
func (c *EmojiCache) Put(emoji *gtsmodel.Emoji) {
if emoji == nil || emoji.ID == "" {
@@ -80,6 +91,10 @@ func (c *EmojiCache) Put(emoji *gtsmodel.Emoji) {
c.cache.Set(emoji.ID, copyEmoji(emoji))
}
+func (c *EmojiCache) Invalidate(emojiID string) {
+ c.cache.Invalidate(emojiID)
+}
+
// copyEmoji performs a surface-level copy of emoji, only keeping attached IDs intact, not the objects.
// due to all the data being copied being 99% primitive types or strings (which are immutable and passed by ptr)
// this should be a relatively cheap process