summaryrefslogtreecommitdiff
path: root/internal/processing
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2022-09-02 11:17:46 +0100
committerLibravatar GitHub <noreply@github.com>2022-09-02 12:17:46 +0200
commitd68c04a6c0964d795a8d475c2f73d201bc72e68b (patch)
tree415746fa7279c4776ee822f1513f45c28a22e547 /internal/processing
parent[feature] Federate custom emoji (outbound) (#791) (diff)
downloadgotosocial-d68c04a6c0964d795a8d475c2f73d201bc72e68b.tar.xz
[performance] cache recently allowed/denied domains to cut down on db calls (#794)
* fetch creation and fetching domain blocks from db Signed-off-by: kim <grufwub@gmail.com> * add separate domainblock cache type, handle removing block from cache on delete Signed-off-by: kim <grufwub@gmail.com> * fix sentinel nil values being passed into cache Signed-off-by: kim <grufwub@gmail.com> Signed-off-by: kim <grufwub@gmail.com>
Diffstat (limited to 'internal/processing')
-rw-r--r--internal/processing/admin/createdomainblock.go35
-rw-r--r--internal/processing/admin/deletedomainblock.go4
2 files changed, 20 insertions, 19 deletions
diff --git a/internal/processing/admin/createdomainblock.go b/internal/processing/admin/createdomainblock.go
index 969cb52de..fcc0cb480 100644
--- a/internal/processing/admin/createdomainblock.go
+++ b/internal/processing/admin/createdomainblock.go
@@ -20,6 +20,7 @@ package admin
import (
"context"
+ "errors"
"fmt"
"strings"
"time"
@@ -41,22 +42,21 @@ func (p *processor) DomainBlockCreate(ctx context.Context, account *gtsmodel.Acc
domain = strings.ToLower(domain)
// first check if we already have a block -- if err == nil we already had a block so we can skip a whole lot of work
- domainBlock := &gtsmodel.DomainBlock{}
- err := p.db.GetWhere(ctx, []db.Where{{Key: "domain", Value: domain}}, domainBlock)
+ block, err := p.db.GetDomainBlock(ctx, domain)
if err != nil {
- if err != db.ErrNoEntries {
+ if !errors.Is(err, db.ErrNoEntries) {
// something went wrong in the DB
- return nil, gtserror.NewErrorInternalError(fmt.Errorf("DomainBlockCreate: db error checking for existence of domain block %s: %s", domain, err))
+ return nil, gtserror.NewErrorInternalError(fmt.Errorf("db error checking for existence of domain block %s: %s", domain, err))
}
// there's no block for this domain yet so create one
// note: we take a new ulid from timestamp here in case we need to sort blocks
blockID, err := id.NewULID()
if err != nil {
- return nil, gtserror.NewErrorInternalError(fmt.Errorf("DomainBlockCreate: error creating id for new domain block %s: %s", domain, err))
+ return nil, gtserror.NewErrorInternalError(fmt.Errorf("error creating id for new domain block %s: %s", domain, err))
}
- domainBlock = &gtsmodel.DomainBlock{
+ newBlock := gtsmodel.DomainBlock{
ID: blockID,
Domain: domain,
CreatedByAccountID: account.ID,
@@ -66,20 +66,22 @@ func (p *processor) DomainBlockCreate(ctx context.Context, account *gtsmodel.Acc
SubscriptionID: subscriptionID,
}
- // put the new block in the database
- if err := p.db.Put(ctx, domainBlock); err != nil {
- if err != db.ErrNoEntries {
- // there's a real error creating the block
- return nil, gtserror.NewErrorInternalError(fmt.Errorf("DomainBlockCreate: db error putting new domain block %s: %s", domain, err))
- }
+ // Insert the new block into the database
+ if err := p.db.CreateDomainBlock(ctx, newBlock); err != nil {
+ return nil, gtserror.NewErrorInternalError(fmt.Errorf("db error putting new domain block %s: %s", domain, err))
}
- // process the side effects of the domain block asynchronously since it might take a while
- go p.initiateDomainBlockSideEffects(context.Background(), account, domainBlock) // TODO: add this to a queuing system so it can retry/resume
+
+ // Set the newly created block
+ block = &newBlock
+
+ // Process the side effects of the domain block asynchronously since it might take a while
+ go p.initiateDomainBlockSideEffects(ctx, account, block)
}
- apiDomainBlock, err := p.tc.DomainBlockToAPIDomainBlock(ctx, domainBlock, false)
+ // Convert our gts model domain block into an API model
+ apiDomainBlock, err := p.tc.DomainBlockToAPIDomainBlock(ctx, block, false)
if err != nil {
- return nil, gtserror.NewErrorInternalError(fmt.Errorf("DomainBlockCreate: error converting domain block to frontend/api representation %s: %s", domain, err))
+ return nil, gtserror.NewErrorInternalError(fmt.Errorf("error converting domain block to frontend/api representation %s: %s", domain, err))
}
return apiDomainBlock, nil
@@ -92,7 +94,6 @@ func (p *processor) DomainBlockCreate(ctx context.Context, account *gtsmodel.Acc
// 3. Select all accounts from this instance and pass them through the delete functionality of the processor.
func (p *processor) initiateDomainBlockSideEffects(ctx context.Context, account *gtsmodel.Account, block *gtsmodel.DomainBlock) {
l := log.WithFields(kv.Fields{
-
{"domain", block.Domain},
}...)
diff --git a/internal/processing/admin/deletedomainblock.go b/internal/processing/admin/deletedomainblock.go
index 29e911888..b65954fe5 100644
--- a/internal/processing/admin/deletedomainblock.go
+++ b/internal/processing/admin/deletedomainblock.go
@@ -47,8 +47,8 @@ func (p *processor) DomainBlockDelete(ctx context.Context, account *gtsmodel.Acc
return nil, gtserror.NewErrorInternalError(err)
}
- // delete the domain block
- if err := p.db.DeleteByID(ctx, id, domainBlock); err != nil {
+ // Delete the domain block
+ if err := p.db.DeleteDomainBlock(ctx, domainBlock.Domain); err != nil {
return nil, gtserror.NewErrorInternalError(err)
}