diff options
author | 2022-10-13 15:16:24 +0200 | |
---|---|---|
committer | 2022-10-13 15:16:24 +0200 | |
commit | 70d65b683fa963d2a8761182a2ddd2f4f9a86bb4 (patch) | |
tree | 9cbd8f6870569b2514683c0e8ff6ea32e6e81780 /internal/cache | |
parent | [frontend] Use new GET custom_emoji admin api (#908) (diff) | |
download | gotosocial-70d65b683fa963d2a8761182a2ddd2f4f9a86bb4.tar.xz |
[feature] Refetch emojis when they change on remote instances (#905)
* select emoji using image_static_url
* use updated on AP emojis
* allow refetch of updated emojis
* cheeky workaround for test
* clean up old files for refreshed emoji
* check error for originalPostData
* shorten GetEmojiByStaticImageURL
* delete kirby (sorry nintendo)
Diffstat (limited to 'internal/cache')
-rw-r--r-- | internal/cache/emoji.go | 21 |
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 |