mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-10-29 10:02:24 -05:00
[feature] do not uncache status / emoji media if attached status is bookmarked (#2956)
* do not uncache status / emoji media if attached status is bookmarked
* add status bookmark and bookmark IDs caches
* update status bookmark tests
* move IsStatusBookmarkedBy() to StatusBookmark{} interface, rely on cache
* fix envparsing.sh test
This commit is contained in:
parent
6f26b32ec3
commit
5dcc954072
17 changed files with 501 additions and 215 deletions
8
internal/cache/cache.go
vendored
8
internal/cache/cache.go
vendored
|
|
@ -85,6 +85,8 @@ func (c *Caches) Init() {
|
|||
c.initPollVoteIDs()
|
||||
c.initReport()
|
||||
c.initStatus()
|
||||
c.initStatusBookmark()
|
||||
c.initStatusBookmarkIDs()
|
||||
c.initStatusFave()
|
||||
c.initStatusFaveIDs()
|
||||
c.initTag()
|
||||
|
|
@ -101,7 +103,7 @@ func (c *Caches) Init() {
|
|||
func (c *Caches) Start() {
|
||||
log.Infof(nil, "start: %p", c)
|
||||
|
||||
tryUntil("starting *gtsmodel.Webfinger cache", 5, func() bool {
|
||||
tryUntil("starting webfinger cache", 5, func() bool {
|
||||
return c.GTS.Webfinger.Start(5 * time.Minute)
|
||||
})
|
||||
}
|
||||
|
|
@ -111,7 +113,7 @@ func (c *Caches) Start() {
|
|||
func (c *Caches) Stop() {
|
||||
log.Infof(nil, "stop: %p", c)
|
||||
|
||||
tryUntil("stopping *gtsmodel.Webfinger cache", 5, c.GTS.Webfinger.Stop)
|
||||
tryUntil("stopping webfinger cache", 5, c.GTS.Webfinger.Stop)
|
||||
}
|
||||
|
||||
// Sweep will sweep all the available caches to ensure none
|
||||
|
|
@ -153,6 +155,8 @@ func (c *Caches) Sweep(threshold float64) {
|
|||
c.GTS.PollVoteIDs.Trim(threshold)
|
||||
c.GTS.Report.Trim(threshold)
|
||||
c.GTS.Status.Trim(threshold)
|
||||
c.GTS.StatusBookmark.Trim(threshold)
|
||||
c.GTS.StatusBookmarkIDs.Trim(threshold)
|
||||
c.GTS.StatusFave.Trim(threshold)
|
||||
c.GTS.StatusFaveIDs.Trim(threshold)
|
||||
c.GTS.Tag.Trim(threshold)
|
||||
|
|
|
|||
54
internal/cache/db.go
vendored
54
internal/cache/db.go
vendored
|
|
@ -139,6 +139,12 @@ type GTSCaches struct {
|
|||
// Status provides access to the gtsmodel Status database cache.
|
||||
Status StructCache[*gtsmodel.Status]
|
||||
|
||||
// StatusBookmark ...
|
||||
StatusBookmark StructCache[*gtsmodel.StatusBookmark]
|
||||
|
||||
// StatusBookmarkIDs ...
|
||||
StatusBookmarkIDs SliceCache[string]
|
||||
|
||||
// StatusFave provides access to the gtsmodel StatusFave database cache.
|
||||
StatusFave StructCache[*gtsmodel.StatusFave]
|
||||
|
||||
|
|
@ -1102,6 +1108,54 @@ func (c *Caches) initStatus() {
|
|||
})
|
||||
}
|
||||
|
||||
func (c *Caches) initStatusBookmark() {
|
||||
// Calculate maximum cache size.
|
||||
cap := calculateResultCacheMax(
|
||||
sizeofStatusBookmark(), // model in-mem size.
|
||||
config.GetCacheStatusBookmarkMemRatio(),
|
||||
)
|
||||
|
||||
log.Infof(nil, "cache size = %d", cap)
|
||||
|
||||
copyF := func(s1 *gtsmodel.StatusBookmark) *gtsmodel.StatusBookmark {
|
||||
s2 := new(gtsmodel.StatusBookmark)
|
||||
*s2 = *s1
|
||||
|
||||
// Don't include ptr fields that
|
||||
// will be populated separately.
|
||||
s2.Account = nil
|
||||
s2.TargetAccount = nil
|
||||
s2.Status = nil
|
||||
|
||||
return s2
|
||||
}
|
||||
|
||||
c.GTS.StatusBookmark.Init(structr.CacheConfig[*gtsmodel.StatusBookmark]{
|
||||
Indices: []structr.IndexConfig{
|
||||
{Fields: "ID"},
|
||||
{Fields: "AccountID,StatusID"},
|
||||
{Fields: "AccountID", Multiple: true},
|
||||
{Fields: "TargetAccountID", Multiple: true},
|
||||
{Fields: "StatusID", Multiple: true},
|
||||
},
|
||||
MaxSize: cap,
|
||||
IgnoreErr: ignoreErrors,
|
||||
Copy: copyF,
|
||||
Invalidate: c.OnInvalidateStatusBookmark,
|
||||
})
|
||||
}
|
||||
|
||||
func (c *Caches) initStatusBookmarkIDs() {
|
||||
// Calculate maximum cache size.
|
||||
cap := calculateSliceCacheMax(
|
||||
config.GetCacheStatusBookmarkIDsMemRatio(),
|
||||
)
|
||||
|
||||
log.Infof(nil, "cache size = %d", cap)
|
||||
|
||||
c.GTS.StatusBookmarkIDs.Init(0, cap)
|
||||
}
|
||||
|
||||
func (c *Caches) initStatusFave() {
|
||||
// Calculate maximum cache size.
|
||||
cap := calculateResultCacheMax(
|
||||
|
|
|
|||
5
internal/cache/invalidate.go
vendored
5
internal/cache/invalidate.go
vendored
|
|
@ -198,6 +198,11 @@ func (c *Caches) OnInvalidateStatus(status *gtsmodel.Status) {
|
|||
}
|
||||
}
|
||||
|
||||
func (c *Caches) OnInvalidateStatusBookmark(bookmark *gtsmodel.StatusBookmark) {
|
||||
// Invalidate status bookmark ID list for this status.
|
||||
c.GTS.StatusBookmarkIDs.Invalidate(bookmark.StatusID)
|
||||
}
|
||||
|
||||
func (c *Caches) OnInvalidateStatusFave(fave *gtsmodel.StatusFave) {
|
||||
// Invalidate status fave ID list for this status.
|
||||
c.GTS.StatusFaveIDs.Invalidate(fave.StatusID)
|
||||
|
|
|
|||
18
internal/cache/size.go
vendored
18
internal/cache/size.go
vendored
|
|
@ -201,6 +201,8 @@ func totalOfRatios() float64 {
|
|||
config.GetCachePollVoteMemRatio() +
|
||||
config.GetCacheReportMemRatio() +
|
||||
config.GetCacheStatusMemRatio() +
|
||||
config.GetCacheStatusBookmarkMemRatio() +
|
||||
config.GetCacheStatusBookmarkIDsMemRatio() +
|
||||
config.GetCacheStatusFaveMemRatio() +
|
||||
config.GetCacheStatusFaveIDsMemRatio() +
|
||||
config.GetCacheTagMemRatio() +
|
||||
|
|
@ -566,7 +568,7 @@ func sizeofReport() uintptr {
|
|||
|
||||
func sizeofStatus() uintptr {
|
||||
return uintptr(size.Of(>smodel.Status{
|
||||
ID: exampleURI,
|
||||
ID: exampleID,
|
||||
URI: exampleURI,
|
||||
URL: exampleURI,
|
||||
Content: exampleText,
|
||||
|
|
@ -599,6 +601,20 @@ func sizeofStatus() uintptr {
|
|||
}))
|
||||
}
|
||||
|
||||
func sizeofStatusBookmark() uintptr {
|
||||
return uintptr(size.Of(>smodel.StatusBookmark{
|
||||
ID: exampleID,
|
||||
AccountID: exampleID,
|
||||
Account: nil,
|
||||
TargetAccountID: exampleID,
|
||||
TargetAccount: nil,
|
||||
StatusID: exampleID,
|
||||
Status: nil,
|
||||
CreatedAt: exampleTime,
|
||||
UpdatedAt: exampleTime,
|
||||
}))
|
||||
}
|
||||
|
||||
func sizeofStatusFave() uintptr {
|
||||
return uintptr(size.Of(>smodel.StatusFave{
|
||||
ID: exampleID,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue