diff options
author | 2023-11-27 16:39:44 +0100 | |
---|---|---|
committer | 2023-11-27 15:39:44 +0000 | |
commit | 33ee61575f2fc15c5a85c3fdbb3823a0cd22d25d (patch) | |
tree | 5e887d5ea5b828c84a1a9eb386bbaa07ad63a420 /internal/db/bundb/user.go | |
parent | [docs] Add docs about memory requirements and swap (#2385) (diff) | |
download | gotosocial-33ee61575f2fc15c5a85c3fdbb3823a0cd22d25d.tar.xz |
[bugfix] Don't copy ptr fields in caches (#2386)
Diffstat (limited to 'internal/db/bundb/user.go')
-rw-r--r-- | internal/db/bundb/user.go | 35 |
1 files changed, 28 insertions, 7 deletions
diff --git a/internal/db/bundb/user.go b/internal/db/bundb/user.go index eaa1d8e3d..46b3c568f 100644 --- a/internal/db/bundb/user.go +++ b/internal/db/bundb/user.go @@ -130,18 +130,39 @@ func (u *userDB) getUser(ctx context.Context, lookup string, dbQuery func(*gtsmo return nil, err } - // Fetch the related account model for this user. - user.Account, err = u.state.DB.GetAccountByID( - gtscontext.SetBarebones(ctx), - user.AccountID, - ) - if err != nil { - return nil, gtserror.Newf("error populating user account: %w", err) + if gtscontext.Barebones(ctx) { + // Return without populating. + return user, nil + } + + if err := u.PopulateUser(ctx, user); err != nil { + return nil, err } return user, nil } +// PopulateUser ensures that the user's struct fields are populated. +func (u *userDB) PopulateUser(ctx context.Context, user *gtsmodel.User) error { + var ( + errs = gtserror.NewMultiError(1) + err error + ) + + if user.Account == nil { + // Fetch the related account model for this user. + user.Account, err = u.state.DB.GetAccountByID( + gtscontext.SetBarebones(ctx), + user.AccountID, + ) + if err != nil { + errs.Appendf("error populating user account: %w", err) + } + } + + return errs.Combine() +} + func (u *userDB) GetAllUsers(ctx context.Context) ([]*gtsmodel.User, error) { var userIDs []string |