mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-16 17:57:29 -06:00
[performance] remove last of relational queries to instead rely on caches (#2091)
This commit is contained in:
parent
9770d54237
commit
91cbcd589e
19 changed files with 507 additions and 107 deletions
27
internal/cache/gts.go
vendored
27
internal/cache/gts.go
vendored
|
|
@ -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(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue