mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-10-29 14:22:26 -05:00
[bugfix] Invalidate timeline entries for status when stats change (#1879)
This commit is contained in:
parent
84e1c7a7c4
commit
5e2897e35c
12 changed files with 531 additions and 130 deletions
|
|
@ -24,6 +24,7 @@ import (
|
|||
|
||||
"github.com/superseriousbusiness/gotosocial/internal/db"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtscontext"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/log"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/state"
|
||||
|
|
@ -145,6 +146,48 @@ func (s *statusFaveDB) GetStatusFavesForStatus(ctx context.Context, statusID str
|
|||
return faves, nil
|
||||
}
|
||||
|
||||
func (s *statusFaveDB) PopulateStatusFave(ctx context.Context, statusFave *gtsmodel.StatusFave) error {
|
||||
var (
|
||||
err error
|
||||
errs = make(gtserror.MultiError, 0, 3)
|
||||
)
|
||||
|
||||
if statusFave.Account == nil {
|
||||
// StatusFave author is not set, fetch from database.
|
||||
statusFave.Account, err = s.state.DB.GetAccountByID(
|
||||
gtscontext.SetBarebones(ctx),
|
||||
statusFave.AccountID,
|
||||
)
|
||||
if err != nil {
|
||||
errs.Append(fmt.Errorf("error populating status fave author: %w", err))
|
||||
}
|
||||
}
|
||||
|
||||
if statusFave.TargetAccount == nil {
|
||||
// StatusFave target account is not set, fetch from database.
|
||||
statusFave.TargetAccount, err = s.state.DB.GetAccountByID(
|
||||
gtscontext.SetBarebones(ctx),
|
||||
statusFave.TargetAccountID,
|
||||
)
|
||||
if err != nil {
|
||||
errs.Append(fmt.Errorf("error populating status fave target account: %w", err))
|
||||
}
|
||||
}
|
||||
|
||||
if statusFave.Status == nil {
|
||||
// StatusFave status is not set, fetch from database.
|
||||
statusFave.Status, err = s.state.DB.GetStatusByID(
|
||||
gtscontext.SetBarebones(ctx),
|
||||
statusFave.StatusID,
|
||||
)
|
||||
if err != nil {
|
||||
errs.Append(fmt.Errorf("error populating status fave status: %w", err))
|
||||
}
|
||||
}
|
||||
|
||||
return errs.Combine()
|
||||
}
|
||||
|
||||
func (s *statusFaveDB) PutStatusFave(ctx context.Context, fave *gtsmodel.StatusFave) db.Error {
|
||||
return s.state.Caches.GTS.StatusFave().Store(fave, func() error {
|
||||
_, err := s.conn.
|
||||
|
|
|
|||
|
|
@ -35,6 +35,9 @@ type StatusFave interface {
|
|||
// This slice will be unfiltered, not taking account of blocks and whatnot, so filter it before serving it back to a user.
|
||||
GetStatusFavesForStatus(ctx context.Context, statusID string) ([]*gtsmodel.StatusFave, Error)
|
||||
|
||||
// PopulateStatusFave ensures that all sub-models of a fave are populated (account, status, etc).
|
||||
PopulateStatusFave(ctx context.Context, statusFave *gtsmodel.StatusFave) error
|
||||
|
||||
// PutStatusFave inserts the given statusFave into the database.
|
||||
PutStatusFave(ctx context.Context, statusFave *gtsmodel.StatusFave) Error
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue