Add preview card storing to the database

This commit is contained in:
kaimanhub 2025-03-30 20:24:15 +03:00
commit 6169351d22
12 changed files with 228 additions and 55 deletions

29
internal/cache/db.go vendored
View file

@ -52,6 +52,9 @@ type DBCaches struct {
// BoostOfIDs provides access to the boost of IDs list database cache.
BoostOfIDs SliceCache[string]
// Card provides access to the gtsmodel Card database cache.
Card StructCache[*gtsmodel.Card]
// Conversation provides access to the gtsmodel Conversation database cache.
Conversation StructCache[*gtsmodel.Conversation]
@ -637,6 +640,32 @@ func (c *Caches) initEmoji() {
})
}
func (c *Caches) initCard() {
// Calculate maximum cache size.
cap := calculateResultCacheMax(
sizeofCard(), // model in-mem size.
config.GetCacheEmojiMemRatio(), // TODO: this need to be replaced with GetCacheCardMemRatio
)
log.Infof(nil, "cache size = %d", cap)
copyF := func(e1 *gtsmodel.Card) *gtsmodel.Card {
e2 := new(gtsmodel.Card)
*e2 = *e1
return e2
}
c.DB.Card.Init(structr.CacheConfig[*gtsmodel.Card]{
Indices: []structr.IndexConfig{
{Fields: "ID"},
},
MaxSize: cap,
IgnoreErr: ignoreErrors,
Copy: copyF,
})
}
func (c *Caches) initEmojiCategory() {
// Calculate maximum cache size.
cap := calculateResultCacheMax(