diff options
author | 2024-07-11 16:44:29 +0200 | |
---|---|---|
committer | 2024-07-11 15:44:29 +0100 | |
commit | 5bc567196bf2204272950c525e8592e56057c3bd (patch) | |
tree | 24aec5e75d2a0208505da16ee2c55efd887d3e25 /internal/cache | |
parent | [bugfix] Don't throw error when parent statuses are missing (#2011) (#3088) (diff) | |
download | gotosocial-5bc567196bf2204272950c525e8592e56057c3bd.tar.xz |
[chore] Add interaction policy gtsmodels (#3075)
* [chore] introduce interaction policy gts models
* update migration a smidge
* fix copy paste typo
* update migration
* use int for InteractionType
Diffstat (limited to 'internal/cache')
-rw-r--r-- | internal/cache/cache.go | 2 | ||||
-rw-r--r-- | internal/cache/db.go | 37 | ||||
-rw-r--r-- | internal/cache/size.go | 17 |
3 files changed, 53 insertions, 3 deletions
diff --git a/internal/cache/cache.go b/internal/cache/cache.go index bb910f3e6..5a8a92ca3 100644 --- a/internal/cache/cache.go +++ b/internal/cache/cache.go @@ -73,6 +73,7 @@ func (c *Caches) Init() { c.initFollowRequestIDs() c.initInReplyToIDs() c.initInstance() + c.initInteractionApproval() c.initList() c.initListEntry() c.initMarker() @@ -145,6 +146,7 @@ func (c *Caches) Sweep(threshold float64) { c.GTS.FollowRequestIDs.Trim(threshold) c.GTS.InReplyToIDs.Trim(threshold) c.GTS.Instance.Trim(threshold) + c.GTS.InteractionApproval.Trim(threshold) c.GTS.List.Trim(threshold) c.GTS.ListEntry.Trim(threshold) c.GTS.Marker.Trim(threshold) diff --git a/internal/cache/db.go b/internal/cache/db.go index d0fe77649..50acf00d1 100644 --- a/internal/cache/db.go +++ b/internal/cache/db.go @@ -100,6 +100,9 @@ type GTSCaches struct { // Instance provides access to the gtsmodel Instance database cache. Instance StructCache[*gtsmodel.Instance] + // InteractionApproval provides access to the gtsmodel InteractionApproval database cache. + InteractionApproval StructCache[*gtsmodel.InteractionApproval] + // InReplyToIDs provides access to the status in reply to IDs list database cache. InReplyToIDs SliceCache[string] @@ -737,6 +740,39 @@ func (c *Caches) initInstance() { }) } +func (c *Caches) initInteractionApproval() { + // Calculate maximum cache size. + cap := calculateResultCacheMax( + sizeofInteractionApproval(), + config.GetCacheInteractionApprovalMemRatio(), + ) + + log.Infof(nil, "cache size = %d", cap) + + copyF := func(i1 *gtsmodel.InteractionApproval) *gtsmodel.InteractionApproval { + i2 := new(gtsmodel.InteractionApproval) + *i2 = *i1 + + // Don't include ptr fields that + // will be populated separately. + // See internal/db/bundb/interaction.go. + i2.Account = nil + i2.InteractingAccount = nil + + return i2 + } + + c.GTS.InteractionApproval.Init(structr.CacheConfig[*gtsmodel.InteractionApproval]{ + Indices: []structr.IndexConfig{ + {Fields: "ID"}, + {Fields: "URI"}, + }, + MaxSize: cap, + IgnoreErr: ignoreErrors, + Copy: copyF, + }) +} + func (c *Caches) initList() { // Calculate maximum cache size. cap := calculateResultCacheMax( @@ -1188,6 +1224,7 @@ func (c *Caches) initStatusFave() { c.GTS.StatusFave.Init(structr.CacheConfig[*gtsmodel.StatusFave]{ Indices: []structr.IndexConfig{ {Fields: "ID"}, + {Fields: "URI"}, {Fields: "AccountID,StatusID"}, {Fields: "StatusID", Multiple: true}, }, diff --git a/internal/cache/size.go b/internal/cache/size.go index fb1f165c2..4ec30fbb7 100644 --- a/internal/cache/size.go +++ b/internal/cache/size.go @@ -189,6 +189,7 @@ func totalOfRatios() float64 { config.GetCacheFollowRequestMemRatio() + config.GetCacheFollowRequestIDsMemRatio() + config.GetCacheInstanceMemRatio() + + config.GetCacheInteractionApprovalMemRatio() + config.GetCacheInReplyToIDsMemRatio() + config.GetCacheListMemRatio() + config.GetCacheListEntryMemRatio() + @@ -425,6 +426,19 @@ func sizeofInstance() uintptr { })) } +func sizeofInteractionApproval() uintptr { + return uintptr(size.Of(>smodel.InteractionApproval{ + ID: exampleID, + CreatedAt: exampleTime, + UpdatedAt: exampleTime, + AccountID: exampleID, + InteractingAccountID: exampleID, + InteractionURI: exampleURI, + InteractionType: gtsmodel.InteractionAnnounce, + URI: exampleURI, + })) +} + func sizeofList() uintptr { return uintptr(size.Of(>smodel.List{ ID: exampleID, @@ -591,9 +605,6 @@ func sizeofStatus() uintptr { Language: "en", CreatedWithApplicationID: exampleID, Federated: func() *bool { ok := true; return &ok }(), - Boostable: func() *bool { ok := true; return &ok }(), - Replyable: func() *bool { ok := true; return &ok }(), - Likeable: func() *bool { ok := true; return &ok }(), ActivityStreamsType: ap.ObjectNote, })) } |