mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2025-06-05 21:59:39 +02:00
[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)
This commit is contained in:
21
internal/cache/emoji.go
vendored
21
internal/cache/emoji.go
vendored
@@ -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
|
||||
|
Reference in New Issue
Block a user