summaryrefslogtreecommitdiff
path: root/internal/cache/db.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2025-01-05 13:20:33 +0100
committerLibravatar GitHub <noreply@github.com>2025-01-05 13:20:33 +0100
commite9bb7ddd3aa11da5c48a75c4a600f8fe5cc1c990 (patch)
treea2897775112a821aa093b6e2686044814912001f /internal/cache/db.go
parent[chore] Update robots.txt with more AI bots (#3634) (diff)
downloadgotosocial-e9bb7ddd3aa11da5c48a75c4a600f8fe5cc1c990.tar.xz
[feature] Create/update/remove domain permission subscriptions (#3623)
* [feature] Create/update/remove domain permission subscriptions * lint * envparsing * remove errant fmt.Println * create drafts, subs, exclude, from snapshot models * name etag column correctly * remove count column * lint
Diffstat (limited to 'internal/cache/db.go')
-rw-r--r--internal/cache/db.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/internal/cache/db.go b/internal/cache/db.go
index 7a47b811f..1052446c4 100644
--- a/internal/cache/db.go
+++ b/internal/cache/db.go
@@ -70,6 +70,9 @@ type DBCaches struct {
// DomainPermissionDraft provides access to the domain permission draft database cache.
DomainPermissionDraft StructCache[*gtsmodel.DomainPermissionDraft]
+ // DomainPermissionSubscription provides access to the domain permission subscription database cache.
+ DomainPermissionSubscription StructCache[*gtsmodel.DomainPermissionSubscription]
+
// DomainPermissionExclude provides access to the domain permission exclude database cache.
DomainPermissionExclude *domain.Cache
@@ -589,6 +592,37 @@ func (c *Caches) initDomainPermissionDraft() {
})
}
+func (c *Caches) initDomainPermissionSubscription() {
+ // Calculate maximum cache size.
+ cap := calculateResultCacheMax(
+ sizeofDomainPermissionSubscription(), // model in-mem size.
+ config.GetCacheDomainPermissionSubscriptionMemRation(),
+ )
+
+ log.Infof(nil, "cache size = %d", cap)
+
+ copyF := func(d1 *gtsmodel.DomainPermissionSubscription) *gtsmodel.DomainPermissionSubscription {
+ d2 := new(gtsmodel.DomainPermissionSubscription)
+ *d2 = *d1
+
+ // Don't include ptr fields that
+ // will be populated separately.
+ d2.CreatedByAccount = nil
+
+ return d2
+ }
+
+ c.DB.DomainPermissionSubscription.Init(structr.CacheConfig[*gtsmodel.DomainPermissionSubscription]{
+ Indices: []structr.IndexConfig{
+ {Fields: "ID"},
+ {Fields: "URI"},
+ },
+ MaxSize: cap,
+ IgnoreErr: ignoreErrors,
+ Copy: copyF,
+ })
+}
+
func (c *Caches) initDomainPermissionExclude() {
c.DB.DomainPermissionExclude = new(domain.Cache)
}