mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-10-29 07:12:25 -05:00
[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:
parent
0767647056
commit
7f4a0a1aeb
36 changed files with 525 additions and 191 deletions
2
internal/cache/cache.go
vendored
2
internal/cache/cache.go
vendored
|
|
@ -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
27
internal/cache/db.go
vendored
|
|
@ -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(
|
||||
|
|
|
|||
22
internal/cache/size.go
vendored
22
internal/cache/size.go
vendored
|
|
@ -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(>smodel.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(>smodel.Application{
|
||||
ID: exampleID,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue