[chore] Move local account settings to separate db table (#2770)

* [chore] Move local account settings to separate database model

* don't use separate settings_id
This commit is contained in:
tobi 2024-03-22 14:03:46 +01:00 committed by GitHub
commit 7f4a0a1aeb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
36 changed files with 525 additions and 191 deletions

View file

@ -53,6 +53,7 @@ func (c *Caches) Init() {
c.initAccount()
c.initAccountCounts()
c.initAccountNote()
c.initAccountSettings()
c.initApplication()
c.initBlock()
c.initBlockIDs()
@ -119,6 +120,7 @@ func (c *Caches) Stop() {
func (c *Caches) Sweep(threshold float64) {
c.GTS.Account.Trim(threshold)
c.GTS.AccountNote.Trim(threshold)
c.GTS.AccountSettings.Trim(threshold)
c.GTS.Block.Trim(threshold)
c.GTS.BlockIDs.Trim(threshold)
c.GTS.Emoji.Trim(threshold)

27
internal/cache/db.go vendored
View file

@ -43,6 +43,9 @@ type GTSCaches struct {
Pinned int
}]
// AccountSettings provides access to the gtsmodel AccountSettings database cache.
AccountSettings structr.Cache[*gtsmodel.AccountSettings]
// Application provides access to the gtsmodel Application database cache.
Application structr.Cache[*gtsmodel.Application]
@ -190,6 +193,7 @@ func (c *Caches) initAccount() {
a2.Emojis = nil
a2.AlsoKnownAs = nil
a2.Move = nil
a2.Settings = nil
return a2
}
@ -262,6 +266,29 @@ func (c *Caches) initAccountNote() {
})
}
func (c *Caches) initAccountSettings() {
// Calculate maximum cache size.
cap := calculateResultCacheMax(
sizeofAccountSettings(), // model in-mem size.
config.GetCacheAccountSettingsMemRatio(),
)
log.Infof(nil, "cache size = %d", cap)
c.GTS.AccountSettings.Init(structr.Config[*gtsmodel.AccountSettings]{
Indices: []structr.IndexConfig{
{Fields: "AccountID"},
},
MaxSize: cap,
IgnoreErr: ignoreErrors,
CopyValue: func(s1 *gtsmodel.AccountSettings) *gtsmodel.AccountSettings {
s2 := new(gtsmodel.AccountSettings)
*s2 = *s1
return s2
},
})
}
func (c *Caches) initApplication() {
// Calculate maximum cache size.
cap := calculateResultCacheMax(

View file

@ -28,6 +28,7 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/id"
"github.com/superseriousbusiness/gotosocial/internal/util"
)
const (
@ -219,9 +220,6 @@ func sizeofAccount() uintptr {
Bot: func() *bool { ok := true; return &ok }(),
Locked: func() *bool { ok := true; return &ok }(),
Discoverable: func() *bool { ok := false; return &ok }(),
Privacy: gtsmodel.VisibilityFollowersOnly,
Sensitive: func() *bool { ok := true; return &ok }(),
Language: "fr",
URI: exampleURI,
URL: exampleURI,
InboxURI: exampleURI,
@ -236,9 +234,7 @@ func sizeofAccount() uintptr {
SensitizedAt: exampleTime,
SilencedAt: exampleTime,
SuspendedAt: exampleTime,
HideCollections: func() *bool { ok := true; return &ok }(),
SuspensionOrigin: exampleID,
EnableRSS: func() *bool { ok := true; return &ok }(),
}))
}
@ -251,6 +247,22 @@ func sizeofAccountNote() uintptr {
}))
}
func sizeofAccountSettings() uintptr {
return uintptr(size.Of(&gtsmodel.AccountSettings{
AccountID: exampleID,
CreatedAt: exampleTime,
UpdatedAt: exampleTime,
Reason: exampleText,
Privacy: gtsmodel.VisibilityFollowersOnly,
Sensitive: util.Ptr(true),
Language: "fr",
StatusContentType: "text/plain",
CustomCSS: exampleText,
EnableRSS: util.Ptr(true),
HideCollections: util.Ptr(false),
}))
}
func sizeofApplication() uintptr {
return uintptr(size.Of(&gtsmodel.Application{
ID: exampleID,