summaryrefslogtreecommitdiff
path: root/internal/db/bundb/relationship_note.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2023-11-27 16:39:44 +0100
committerLibravatar GitHub <noreply@github.com>2023-11-27 15:39:44 +0000
commit33ee61575f2fc15c5a85c3fdbb3823a0cd22d25d (patch)
tree5e887d5ea5b828c84a1a9eb386bbaa07ad63a420 /internal/db/bundb/relationship_note.go
parent[docs] Add docs about memory requirements and swap (#2385) (diff)
downloadgotosocial-33ee61575f2fc15c5a85c3fdbb3823a0cd22d25d.tar.xz
[bugfix] Don't copy ptr fields in caches (#2386)
Diffstat (limited to 'internal/db/bundb/relationship_note.go')
-rw-r--r--internal/db/bundb/relationship_note.go48
1 files changed, 33 insertions, 15 deletions
diff --git a/internal/db/bundb/relationship_note.go b/internal/db/bundb/relationship_note.go
index 84f0ebeab..f7d15f8b7 100644
--- a/internal/db/bundb/relationship_note.go
+++ b/internal/db/bundb/relationship_note.go
@@ -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,25 +64,43 @@ 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)
+ // Further populate the account fields where applicable.
+ if err := r.PopulateNote(ctx, note); err != nil {
+ return nil, err
}
- // Set the note target account
- note.TargetAccount, err = r.state.DB.GetAccountByID(
- gtscontext.SetBarebones(ctx),
- note.TargetAccountID,
+ return note, nil
+}
+
+func (r *relationshipDB) PopulateNote(ctx context.Context, note *gtsmodel.AccountNote) error {
+ var (
+ errs = gtserror.NewMultiError(2)
+ err error
)
- if err != nil {
- return nil, fmt.Errorf("error getting note target account: %w", err)
+
+ // 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)
+ }
}
- return note, nil
+ // 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 {