mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2025-06-05 21:59:39 +02:00
[performance] add caching of status fave, boost of, in reply to ID lists (#2060)
This commit is contained in:
@ -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 := >smodel.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)
|
||||
|
Reference in New Issue
Block a user