mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-12-09 14:58:08 -06:00
Add preview card storing to the database
This commit is contained in:
parent
85c32526f2
commit
6169351d22
12 changed files with 228 additions and 55 deletions
1
internal/cache/cache.go
vendored
1
internal/cache/cache.go
vendored
|
|
@ -70,6 +70,7 @@ func (c *Caches) Init() {
|
|||
c.initBlock()
|
||||
c.initBlockIDs()
|
||||
c.initBoostOfIDs()
|
||||
c.initCard()
|
||||
c.initConversation()
|
||||
c.initConversationLastStatusIDs()
|
||||
c.initDomainAllow()
|
||||
|
|
|
|||
29
internal/cache/db.go
vendored
29
internal/cache/db.go
vendored
|
|
@ -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(
|
||||
|
|
|
|||
7
internal/cache/size.go
vendored
7
internal/cache/size.go
vendored
|
|
@ -395,6 +395,13 @@ func sizeofEmoji() uintptr {
|
|||
}))
|
||||
}
|
||||
|
||||
func sizeofCard() uintptr {
|
||||
// TODO: this implementation need to be extended to contain other fields also.
|
||||
return uintptr(size.Of(>smodel.Card{
|
||||
ID: exampleID,
|
||||
}))
|
||||
}
|
||||
|
||||
func sizeofEmojiCategory() uintptr {
|
||||
return uintptr(size.Of(>smodel.EmojiCategory{
|
||||
ID: exampleID,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue