mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-02 13:02:26 -06:00
[bugfix] Don't copy ptr fields in caches (#2386)
This commit is contained in:
parent
0bb9b72334
commit
33ee61575f
12 changed files with 469 additions and 109 deletions
|
|
@ -19,10 +19,10 @@ package bundb
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtscontext"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
"github.com/uptrace/bun"
|
||||
)
|
||||
|
|
@ -64,27 +64,45 @@ func (r *relationshipDB) getNote(ctx context.Context, lookup string, dbQuery fun
|
|||
return note, nil
|
||||
}
|
||||
|
||||
// Set the note source account
|
||||
note.Account, err = r.state.DB.GetAccountByID(
|
||||
gtscontext.SetBarebones(ctx),
|
||||
note.AccountID,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error getting note source account: %w", err)
|
||||
}
|
||||
|
||||
// Set the note target account
|
||||
note.TargetAccount, err = r.state.DB.GetAccountByID(
|
||||
gtscontext.SetBarebones(ctx),
|
||||
note.TargetAccountID,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error getting note target account: %w", err)
|
||||
// Further populate the account fields where applicable.
|
||||
if err := r.PopulateNote(ctx, note); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return note, nil
|
||||
}
|
||||
|
||||
func (r *relationshipDB) PopulateNote(ctx context.Context, note *gtsmodel.AccountNote) error {
|
||||
var (
|
||||
errs = gtserror.NewMultiError(2)
|
||||
err error
|
||||
)
|
||||
|
||||
// Ensure note source account set.
|
||||
if note.Account == nil {
|
||||
note.Account, err = r.state.DB.GetAccountByID(
|
||||
gtscontext.SetBarebones(ctx),
|
||||
note.AccountID,
|
||||
)
|
||||
if err != nil {
|
||||
errs.Appendf("error populating note source account: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure note target account set.
|
||||
if note.TargetAccount == nil {
|
||||
note.TargetAccount, err = r.state.DB.GetAccountByID(
|
||||
gtscontext.SetBarebones(ctx),
|
||||
note.TargetAccountID,
|
||||
)
|
||||
if err != nil {
|
||||
errs.Appendf("error populating note target account: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
return errs.Combine()
|
||||
}
|
||||
|
||||
func (r *relationshipDB) PutNote(ctx context.Context, note *gtsmodel.AccountNote) error {
|
||||
note.UpdatedAt = time.Now()
|
||||
return r.state.Caches.GTS.AccountNote().Store(note, func() error {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue