mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2026-01-06 00:43:19 -06:00
add support for status edits in the database, and update status dereferencer to handle them
This commit is contained in:
parent
fc8d3742c9
commit
3e131f5da6
21 changed files with 623 additions and 172 deletions
1
internal/cache/cache.go
vendored
1
internal/cache/cache.go
vendored
|
|
@ -105,6 +105,7 @@ func (c *Caches) Init() {
|
|||
c.initStatus()
|
||||
c.initStatusBookmark()
|
||||
c.initStatusBookmarkIDs()
|
||||
c.initStatusEdit()
|
||||
c.initStatusFave()
|
||||
c.initStatusFaveIDs()
|
||||
c.initTag()
|
||||
|
|
|
|||
35
internal/cache/db.go
vendored
35
internal/cache/db.go
vendored
|
|
@ -226,6 +226,9 @@ type DBCaches struct {
|
|||
// StatusBookmarkIDs provides access to the status bookmark IDs list database cache.
|
||||
StatusBookmarkIDs SliceCache[string]
|
||||
|
||||
// StatusEdit provides access to the gtsmodel StatusEdit database cache.
|
||||
StatusEdit StructCache[*gtsmodel.StatusEdit]
|
||||
|
||||
// StatusFave provides access to the gtsmodel StatusFave database cache.
|
||||
StatusFave StructCache[*gtsmodel.StatusFave]
|
||||
|
||||
|
|
@ -1385,6 +1388,38 @@ func (c *Caches) initStatusBookmarkIDs() {
|
|||
c.DB.StatusBookmarkIDs.Init(0, cap)
|
||||
}
|
||||
|
||||
func (c *Caches) initStatusEdit() {
|
||||
// Calculate maximum cache size.
|
||||
cap := calculateResultCacheMax(
|
||||
sizeofStatusEdit(), // model in-mem size.
|
||||
config.GetCacheStatusEditMemRatio(),
|
||||
)
|
||||
|
||||
log.Infof(nil, "cache size = %d", cap)
|
||||
|
||||
copyF := func(s1 *gtsmodel.StatusEdit) *gtsmodel.StatusEdit {
|
||||
s2 := new(gtsmodel.StatusEdit)
|
||||
*s2 = *s1
|
||||
|
||||
// Don't include ptr fields that
|
||||
// will be populated separately.
|
||||
s2.Attachments = nil
|
||||
|
||||
return s2
|
||||
}
|
||||
|
||||
c.DB.StatusEdit.Init(structr.CacheConfig[*gtsmodel.StatusEdit]{
|
||||
Indices: []structr.IndexConfig{
|
||||
{Fields: "ID"},
|
||||
{Fields: "StatusID", Multiple: true},
|
||||
},
|
||||
MaxSize: cap,
|
||||
IgnoreErr: ignoreErrors,
|
||||
Copy: copyF,
|
||||
Invalidate: c.OnInvalidateStatusEdit,
|
||||
})
|
||||
}
|
||||
|
||||
func (c *Caches) initStatusFave() {
|
||||
// Calculate maximum cache size.
|
||||
cap := calculateResultCacheMax(
|
||||
|
|
|
|||
5
internal/cache/invalidate.go
vendored
5
internal/cache/invalidate.go
vendored
|
|
@ -273,6 +273,11 @@ func (c *Caches) OnInvalidateStatusBookmark(bookmark *gtsmodel.StatusBookmark) {
|
|||
c.DB.StatusBookmarkIDs.Invalidate(bookmark.StatusID)
|
||||
}
|
||||
|
||||
func (c *Caches) OnInvalidateStatusEdit(edit *gtsmodel.StatusEdit) {
|
||||
// Invalidate cache of related status model.
|
||||
c.DB.Status.Invalidate("ID", edit.StatusID)
|
||||
}
|
||||
|
||||
func (c *Caches) OnInvalidateStatusFave(fave *gtsmodel.StatusFave) {
|
||||
// Invalidate status fave ID list for this status.
|
||||
c.DB.StatusFaveIDs.Invalidate(fave.StatusID)
|
||||
|
|
|
|||
17
internal/cache/size.go
vendored
17
internal/cache/size.go
vendored
|
|
@ -674,6 +674,23 @@ func sizeofStatusBookmark() uintptr {
|
|||
}))
|
||||
}
|
||||
|
||||
func sizeofStatusEdit() uintptr {
|
||||
return uintptr(size.Of(>smodel.StatusEdit{
|
||||
ID: exampleID,
|
||||
Content: exampleText,
|
||||
ContentWarning: exampleUsername, // similar length
|
||||
Text: exampleText,
|
||||
Language: "en",
|
||||
Sensitive: func() *bool { ok := false; return &ok }(),
|
||||
AttachmentIDs: []string{exampleID, exampleID, exampleID},
|
||||
Attachments: nil,
|
||||
PollOptions: []string{exampleTextSmall, exampleTextSmall, exampleTextSmall, exampleTextSmall},
|
||||
PollVotes: []int{69, 420, 1337, 1969},
|
||||
StatusID: exampleID,
|
||||
CreatedAt: exampleTime,
|
||||
}))
|
||||
}
|
||||
|
||||
func sizeofStatusFave() uintptr {
|
||||
return uintptr(size.Of(>smodel.StatusFave{
|
||||
ID: exampleID,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue