mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-30 17:23:31 -06: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:
parent
3ca7164455
commit
70d65b683f
22 changed files with 413 additions and 74 deletions
|
|
@ -21,6 +21,7 @@ package bundb
|
|||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/superseriousbusiness/gotosocial/internal/cache"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/db"
|
||||
|
|
@ -50,6 +51,23 @@ func (e *emojiDB) PutEmoji(ctx context.Context, emoji *gtsmodel.Emoji) db.Error
|
|||
return nil
|
||||
}
|
||||
|
||||
func (e *emojiDB) UpdateEmoji(ctx context.Context, emoji *gtsmodel.Emoji, columns ...string) (*gtsmodel.Emoji, db.Error) {
|
||||
// Update the emoji's last-updated
|
||||
emoji.UpdatedAt = time.Now()
|
||||
|
||||
if _, err := e.conn.
|
||||
NewUpdate().
|
||||
Model(emoji).
|
||||
Where("? = ?", bun.Ident("emoji.id"), emoji.ID).
|
||||
Column(columns...).
|
||||
Exec(ctx); err != nil {
|
||||
return nil, e.conn.ProcessError(err)
|
||||
}
|
||||
|
||||
e.cache.Invalidate(emoji.ID)
|
||||
return emoji, nil
|
||||
}
|
||||
|
||||
func (e *emojiDB) GetEmojis(ctx context.Context, domain string, includeDisabled bool, includeEnabled bool, shortcode string, maxShortcodeDomain string, minShortcodeDomain string, limit int) ([]*gtsmodel.Emoji, db.Error) {
|
||||
emojiIDs := []string{}
|
||||
|
||||
|
|
@ -232,6 +250,21 @@ func (e *emojiDB) GetEmojiByShortcodeDomain(ctx context.Context, shortcode strin
|
|||
)
|
||||
}
|
||||
|
||||
func (e *emojiDB) GetEmojiByStaticURL(ctx context.Context, imageStaticURL string) (*gtsmodel.Emoji, db.Error) {
|
||||
return e.getEmoji(
|
||||
ctx,
|
||||
func() (*gtsmodel.Emoji, bool) {
|
||||
return e.cache.GetByImageStaticURL(imageStaticURL)
|
||||
},
|
||||
func(emoji *gtsmodel.Emoji) error {
|
||||
return e.
|
||||
newEmojiQ(emoji).
|
||||
Where("? = ?", bun.Ident("emoji.image_static_url"), imageStaticURL).
|
||||
Scan(ctx)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func (e *emojiDB) getEmoji(ctx context.Context, cacheGet func() (*gtsmodel.Emoji, bool), dbQuery func(*gtsmodel.Emoji) error) (*gtsmodel.Emoji, db.Error) {
|
||||
// Attempt to fetch cached emoji
|
||||
emoji, cached := cacheGet()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue