summaryrefslogtreecommitdiff
path: root/internal/cache
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2024-11-21 14:09:58 +0100
committerLibravatar GitHub <noreply@github.com>2024-11-21 13:09:58 +0000
commit301543616b5376585a7caff097499421acdf1806 (patch)
tree4cac6aea2c33687b1339fc3bc18e6eb64def6f9a /internal/cache
parent[feature] Allow emoji shortcode to be 1-character length (#3556) (diff)
downloadgotosocial-301543616b5376585a7caff097499421acdf1806.tar.xz
[feature] Add domain permission drafts and excludes (#3547)
* [feature] Add domain permission drafts and excludes * fix typescript complaining * lint * make filenames more consistent * test own domain excluded
Diffstat (limited to 'internal/cache')
-rw-r--r--internal/cache/cache.go2
-rw-r--r--internal/cache/db.go42
-rw-r--r--internal/cache/size.go15
3 files changed, 59 insertions, 0 deletions
diff --git a/internal/cache/cache.go b/internal/cache/cache.go
index 09e505ff5..a4f9f2044 100644
--- a/internal/cache/cache.go
+++ b/internal/cache/cache.go
@@ -74,6 +74,8 @@ func (c *Caches) Init() {
c.initConversationLastStatusIDs()
c.initDomainAllow()
c.initDomainBlock()
+ c.initDomainPermissionDraft()
+ c.initDomainPermissionExclude()
c.initEmoji()
c.initEmojiCategory()
c.initFilter()
diff --git a/internal/cache/db.go b/internal/cache/db.go
index dd4e8b212..aac11236a 100644
--- a/internal/cache/db.go
+++ b/internal/cache/db.go
@@ -67,6 +67,12 @@ type DBCaches struct {
// DomainBlock provides access to the domain block database cache.
DomainBlock *domain.Cache
+ // DomainPermissionDraft provides access to the domain permission draft database cache.
+ DomainPermissionDraft StructCache[*gtsmodel.DomainPermissionDraft]
+
+ // DomainPermissionExclude provides access to the domain permission exclude database cache.
+ DomainPermissionExclude *domain.Cache
+
// Emoji provides access to the gtsmodel Emoji database cache.
Emoji StructCache[*gtsmodel.Emoji]
@@ -548,6 +554,42 @@ func (c *Caches) initDomainBlock() {
c.DB.DomainBlock = new(domain.Cache)
}
+func (c *Caches) initDomainPermissionDraft() {
+ // Calculate maximum cache size.
+ cap := calculateResultCacheMax(
+ sizeofDomainPermissionDraft(), // model in-mem size.
+ config.GetCacheDomainPermissionDraftMemRation(),
+ )
+
+ log.Infof(nil, "cache size = %d", cap)
+
+ copyF := func(d1 *gtsmodel.DomainPermissionDraft) *gtsmodel.DomainPermissionDraft {
+ d2 := new(gtsmodel.DomainPermissionDraft)
+ *d2 = *d1
+
+ // Don't include ptr fields that
+ // will be populated separately.
+ d2.CreatedByAccount = nil
+
+ return d2
+ }
+
+ c.DB.DomainPermissionDraft.Init(structr.CacheConfig[*gtsmodel.DomainPermissionDraft]{
+ Indices: []structr.IndexConfig{
+ {Fields: "ID"},
+ {Fields: "Domain", Multiple: true},
+ {Fields: "SubscriptionID", Multiple: true},
+ },
+ MaxSize: cap,
+ IgnoreErr: ignoreErrors,
+ Copy: copyF,
+ })
+}
+
+func (c *Caches) initDomainPermissionExclude() {
+ c.DB.DomainPermissionExclude = new(domain.Cache)
+}
+
func (c *Caches) initEmoji() {
// Calculate maximum cache size.
cap := calculateResultCacheMax(
diff --git a/internal/cache/size.go b/internal/cache/size.go
index 8367e4c46..26f4096ed 100644
--- a/internal/cache/size.go
+++ b/internal/cache/size.go
@@ -342,6 +342,21 @@ func sizeofConversation() uintptr {
}))
}
+func sizeofDomainPermissionDraft() uintptr {
+ return uintptr(size.Of(&gtsmodel.DomainPermissionDraft{
+ ID: exampleID,
+ CreatedAt: exampleTime,
+ UpdatedAt: exampleTime,
+ PermissionType: gtsmodel.DomainPermissionBlock,
+ Domain: "example.org",
+ CreatedByAccountID: exampleID,
+ PrivateComment: exampleTextSmall,
+ PublicComment: exampleTextSmall,
+ Obfuscate: util.Ptr(false),
+ SubscriptionID: exampleID,
+ }))
+}
+
func sizeofEmoji() uintptr {
return uintptr(size.Of(&gtsmodel.Emoji{
ID: exampleID,