mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-12-04 23:18:09 -06:00
[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
This commit is contained in:
parent
c2029df9bc
commit
301543616b
69 changed files with 5664 additions and 264 deletions
2
internal/cache/cache.go
vendored
2
internal/cache/cache.go
vendored
|
|
@ -74,6 +74,8 @@ func (c *Caches) Init() {
|
|||
c.initConversationLastStatusIDs()
|
||||
c.initDomainAllow()
|
||||
c.initDomainBlock()
|
||||
c.initDomainPermissionDraft()
|
||||
c.initDomainPermissionExclude()
|
||||
c.initEmoji()
|
||||
c.initEmojiCategory()
|
||||
c.initFilter()
|
||||
|
|
|
|||
42
internal/cache/db.go
vendored
42
internal/cache/db.go
vendored
|
|
@ -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(
|
||||
|
|
|
|||
15
internal/cache/size.go
vendored
15
internal/cache/size.go
vendored
|
|
@ -342,6 +342,21 @@ func sizeofConversation() uintptr {
|
|||
}))
|
||||
}
|
||||
|
||||
func sizeofDomainPermissionDraft() uintptr {
|
||||
return uintptr(size.Of(>smodel.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(>smodel.Emoji{
|
||||
ID: exampleID,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue