summaryrefslogtreecommitdiff
path: root/internal/processing/status/boost.go
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2023-08-04 12:28:33 +0100
committerLibravatar GitHub <noreply@github.com>2023-08-04 12:28:33 +0100
commit9a291dea843448f78b4b98ea6813739aebe708c6 (patch)
treef1ce643a3c9fe1b13e4c107f15b1ac4b20fe5b86 /internal/processing/status/boost.go
parent[feature] simpler cache size configuration (#2051) (diff)
downloadgotosocial-9a291dea843448f78b4b98ea6813739aebe708c6.tar.xz
[performance] add caching of status fave, boost of, in reply to ID lists (#2060)
Diffstat (limited to 'internal/processing/status/boost.go')
-rw-r--r--internal/processing/status/boost.go47
1 files changed, 12 insertions, 35 deletions
diff --git a/internal/processing/status/boost.go b/internal/processing/status/boost.go
index e5d38d9d2..eccd81886 100644
--- a/internal/processing/status/boost.go
+++ b/internal/processing/status/boost.go
@@ -106,47 +106,24 @@ func (p *Processor) BoostRemove(ctx context.Context, requestingAccount *gtsmodel
return nil, gtserror.NewErrorNotFound(errors.New("status is not visible"))
}
- // check if we actually have a boost for this status
- var toUnboost bool
-
- gtsBoost := &gtsmodel.Status{}
- where := []db.Where{
- {
- Key: "boost_of_id",
- Value: targetStatusID,
- },
- {
- Key: "account_id",
- Value: requestingAccount.ID,
- },
- }
- err = p.state.DB.GetWhere(ctx, where, gtsBoost)
- if err == nil {
- // we have a boost
- toUnboost = true
- }
-
+ // Check whether the requesting account has boosted the given status ID.
+ boost, err := p.state.DB.GetStatusBoost(ctx, targetStatusID, requestingAccount.ID)
if err != nil {
- // something went wrong in the db finding the boost
- if err != db.ErrNoEntries {
- return nil, gtserror.NewErrorInternalError(fmt.Errorf("error fetching existing boost from database: %s", err))
- }
- // we just don't have a boost
- toUnboost = false
+ return nil, gtserror.NewErrorNotFound(fmt.Errorf("error checking status boost %s: %w", targetStatusID, err))
}
- if toUnboost {
+ if boost != nil {
// pin some stuff onto the boost while we have it out of the db
- gtsBoost.Account = requestingAccount
- gtsBoost.BoostOf = targetStatus
- gtsBoost.BoostOfAccount = targetStatus.Account
- gtsBoost.BoostOf.Account = targetStatus.Account
+ boost.Account = requestingAccount
+ boost.BoostOf = targetStatus
+ boost.BoostOfAccount = targetStatus.Account
+ boost.BoostOf.Account = targetStatus.Account
// send it back to the processor for async processing
p.state.Workers.EnqueueClientAPI(ctx, messages.FromClientAPI{
APObjectType: ap.ActivityAnnounce,
APActivityType: ap.ActivityUndo,
- GTSModel: gtsBoost,
+ GTSModel: boost,
OriginAccount: requestingAccount,
TargetAccount: targetStatus.Account,
})
@@ -189,15 +166,15 @@ func (p *Processor) StatusBoostedBy(ctx context.Context, requestingAccount *gtsm
return nil, gtserror.NewErrorNotFound(err)
}
- statusReblogs, err := p.state.DB.GetStatusReblogs(ctx, targetStatus)
+ statusBoosts, err := p.state.DB.GetStatusBoosts(ctx, targetStatus.ID)
if err != nil {
err = fmt.Errorf("BoostedBy: error seeing who boosted status: %s", err)
return nil, gtserror.NewErrorNotFound(err)
}
// filter account IDs so the user doesn't see accounts they blocked or which blocked them
- accountIDs := make([]string, 0, len(statusReblogs))
- for _, s := range statusReblogs {
+ accountIDs := make([]string, 0, len(statusBoosts))
+ for _, s := range statusBoosts {
blocked, err := p.state.DB.IsEitherBlocked(ctx, requestingAccount.ID, s.AccountID)
if err != nil {
err = fmt.Errorf("BoostedBy: error checking blocks: %s", err)