summaryrefslogtreecommitdiff
path: root/internal/cache
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2023-08-10 15:08:41 +0100
committerLibravatar GitHub <noreply@github.com>2023-08-10 15:08:41 +0100
commit91cbcd589e7c4ab87e5994e4d0276ea1248dc5c2 (patch)
treea6b12c30168eb5fed4267dcb6a1f385b86afdcdf /internal/cache
parent[feature] List replies policy, refactor async workers (#2087) (diff)
downloadgotosocial-91cbcd589e7c4ab87e5994e4d0276ea1248dc5c2.tar.xz
[performance] remove last of relational queries to instead rely on caches (#2091)
Diffstat (limited to 'internal/cache')
-rw-r--r--internal/cache/gts.go27
-rw-r--r--internal/cache/size.go45
2 files changed, 70 insertions, 2 deletions
diff --git a/internal/cache/gts.go b/internal/cache/gts.go
index f120bcf4e..8d7ebcd98 100644
--- a/internal/cache/gts.go
+++ b/internal/cache/gts.go
@@ -32,6 +32,7 @@ import (
type GTSCaches struct {
account *result.Cache[*gtsmodel.Account]
accountNote *result.Cache[*gtsmodel.AccountNote]
+ application *result.Cache[*gtsmodel.Application]
block *result.Cache[*gtsmodel.Block]
blockIDs *SliceCache[string]
boostOfIDs *SliceCache[string]
@@ -67,6 +68,7 @@ type GTSCaches struct {
func (c *GTSCaches) Init() {
c.initAccount()
c.initAccountNote()
+ c.initApplication()
c.initBlock()
c.initBlockIDs()
c.initBoostOfIDs()
@@ -117,6 +119,11 @@ func (c *GTSCaches) AccountNote() *result.Cache[*gtsmodel.AccountNote] {
return c.accountNote
}
+// Application provides access to the gtsmodel Application database cache.
+func (c *GTSCaches) Application() *result.Cache[*gtsmodel.Application] {
+ return c.application
+}
+
// Block provides access to the gtsmodel Block (account) database cache.
func (c *GTSCaches) Block() *result.Cache[*gtsmodel.Block] {
return c.block
@@ -303,6 +310,26 @@ func (c *GTSCaches) initAccountNote() {
c.accountNote.IgnoreErrors(ignoreErrors)
}
+func (c *GTSCaches) initApplication() {
+ // Calculate maximum cache size.
+ cap := calculateResultCacheMax(
+ sizeofApplication(), // model in-mem size.
+ config.GetCacheApplicationMemRatio(),
+ )
+ log.Infof(nil, "Application cache size = %d", cap)
+
+ c.application = result.New([]result.Lookup{
+ {Name: "ID"},
+ {Name: "ClientID"},
+ }, func(a1 *gtsmodel.Application) *gtsmodel.Application {
+ a2 := new(gtsmodel.Application)
+ *a2 = *a1
+ return a2
+ }, cap)
+
+ c.application.IgnoreErrors(ignoreErrors)
+}
+
func (c *GTSCaches) initBlock() {
// Calculate maximum cache size.
cap := calculateResultCacheMax(
diff --git a/internal/cache/size.go b/internal/cache/size.go
index ec7c554c0..34586b0b1 100644
--- a/internal/cache/size.go
+++ b/internal/cache/size.go
@@ -155,6 +155,7 @@ func totalOfRatios() float64 {
return 0 +
config.GetCacheAccountMemRatio() +
config.GetCacheAccountNoteMemRatio() +
+ config.GetCacheApplicationMemRatio() +
config.GetCacheBlockMemRatio() +
config.GetCacheBlockIDsMemRatio() +
config.GetCacheBoostOfIDsMemRatio() +
@@ -217,7 +218,7 @@ func sizeofAccount() uintptr {
SilencedAt: time.Now(),
SuspendedAt: time.Now(),
HideCollections: func() *bool { ok := true; return &ok }(),
- SuspensionOrigin: "",
+ SuspensionOrigin: exampleID,
EnableRSS: func() *bool { ok := true; return &ok }(),
}))
}
@@ -231,6 +232,20 @@ func sizeofAccountNote() uintptr {
}))
}
+func sizeofApplication() uintptr {
+ return uintptr(size.Of(&gtsmodel.Application{
+ ID: exampleID,
+ CreatedAt: time.Now(),
+ UpdatedAt: time.Now(),
+ Name: exampleUsername,
+ Website: exampleURI,
+ RedirectURI: exampleURI,
+ ClientID: exampleID,
+ ClientSecret: exampleID,
+ Scopes: exampleTextSmall,
+ }))
+}
+
func sizeofBlock() uintptr {
return uintptr(size.Of(&gtsmodel.Block{
ID: exampleID,
@@ -500,5 +515,31 @@ func sizeofVisibility() uintptr {
}
func sizeofUser() uintptr {
- return uintptr(size.Of(&gtsmodel.User{}))
+ return uintptr(size.Of(&gtsmodel.User{
+ ID: exampleID,
+ CreatedAt: time.Now(),
+ UpdatedAt: time.Now(),
+ Email: exampleURI,
+ AccountID: exampleID,
+ EncryptedPassword: exampleTextSmall,
+ CurrentSignInAt: time.Now(),
+ LastSignInAt: time.Now(),
+ InviteID: exampleID,
+ ChosenLanguages: []string{"en", "fr", "jp"},
+ FilteredLanguages: []string{"en", "fr", "jp"},
+ Locale: "en",
+ CreatedByApplicationID: exampleID,
+ LastEmailedAt: time.Now(),
+ ConfirmationToken: exampleTextSmall,
+ ConfirmationSentAt: time.Now(),
+ ConfirmedAt: time.Now(),
+ UnconfirmedEmail: exampleURI,
+ Moderator: func() *bool { ok := true; return &ok }(),
+ Admin: func() *bool { ok := true; return &ok }(),
+ Disabled: func() *bool { ok := true; return &ok }(),
+ Approved: func() *bool { ok := true; return &ok }(),
+ ResetPasswordToken: exampleTextSmall,
+ ResetPasswordSentAt: time.Now(),
+ ExternalID: exampleID,
+ }))
}