summaryrefslogtreecommitdiff
path: root/internal/db
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2023-06-11 11:18:44 +0200
committerLibravatar GitHub <noreply@github.com>2023-06-11 10:18:44 +0100
commit5e2897e35cd2bea889fa37a2a857f4dcc076dafc (patch)
treeb1ac6203ffa20f5fff1c460fed942854a6e5c6bd /internal/db
parent[docs] Revamp the installation guide (#1877) (diff)
downloadgotosocial-5e2897e35cd2bea889fa37a2a857f4dcc076dafc.tar.xz
[bugfix] Invalidate timeline entries for status when stats change (#1879)
Diffstat (limited to 'internal/db')
-rw-r--r--internal/db/bundb/statusfave.go43
-rw-r--r--internal/db/statusfave.go3
2 files changed, 46 insertions, 0 deletions
diff --git a/internal/db/bundb/statusfave.go b/internal/db/bundb/statusfave.go
index 497262530..1c96a1dd0 100644
--- a/internal/db/bundb/statusfave.go
+++ b/internal/db/bundb/statusfave.go
@@ -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.
diff --git a/internal/db/statusfave.go b/internal/db/statusfave.go
index b435da514..98ff1d69d 100644
--- a/internal/db/statusfave.go
+++ b/internal/db/statusfave.go
@@ -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