summaryrefslogtreecommitdiff
path: root/internal/cache
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2024-03-22 14:03:46 +0100
committerLibravatar GitHub <noreply@github.com>2024-03-22 14:03:46 +0100
commit7f4a0a1aeb8a294ee967c63d7a48446df013ec44 (patch)
treeb9b3836fa0abe1d7a5758d07d6ebb6486a353d56 /internal/cache
parent[bugfix] add all possible busy result codes to the sqlite errBusy catching ch... (diff)
downloadgotosocial-7f4a0a1aeb8a294ee967c63d7a48446df013ec44.tar.xz
[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
Diffstat (limited to 'internal/cache')
-rw-r--r--internal/cache/cache.go2
-rw-r--r--internal/cache/db.go27
-rw-r--r--internal/cache/size.go22
3 files changed, 46 insertions, 5 deletions
diff --git a/internal/cache/cache.go b/internal/cache/cache.go
index e2fe43a1f..fd715b8e6 100644
--- a/internal/cache/cache.go
+++ b/internal/cache/cache.go
@@ -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)
diff --git a/internal/cache/db.go b/internal/cache/db.go
index 00dfe204a..ff38c1d93 100644
--- a/internal/cache/db.go
+++ b/internal/cache/db.go
@@ -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(
diff --git a/internal/cache/size.go b/internal/cache/size.go
index b1c431c55..080fefea3 100644
--- a/internal/cache/size.go
+++ b/internal/cache/size.go
@@ -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,