mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-02 04:12: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
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue