mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-12-29 17:46:15 -06:00
only populate the status edits when specifically requested
This commit is contained in:
parent
a2d2443103
commit
7f866b36b8
4 changed files with 34 additions and 13 deletions
|
|
@ -297,17 +297,6 @@ func (s *statusDB) PopulateStatus(ctx context.Context, status *gtsmodel.Status)
|
|||
}
|
||||
}
|
||||
|
||||
if !status.EditsPopulated() {
|
||||
// Status edits are out-of-date with IDs, repopulate.
|
||||
status.Edits, err = s.state.DB.GetStatusEditsByIDs(
|
||||
gtscontext.SetBarebones(ctx),
|
||||
status.EditIDs,
|
||||
)
|
||||
if err != nil {
|
||||
errs.Appendf("error populating status edits: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
if status.CreatedWithApplicationID != "" && status.CreatedWithApplication == nil {
|
||||
// Populate the status' expected CreatedWithApplication (not always set).
|
||||
status.CreatedWithApplication, err = s.state.DB.GetApplicationByID(
|
||||
|
|
@ -322,6 +311,23 @@ func (s *statusDB) PopulateStatus(ctx context.Context, status *gtsmodel.Status)
|
|||
return errs.Combine()
|
||||
}
|
||||
|
||||
func (s *statusDB) PopulateStatusEdits(ctx context.Context, status *gtsmodel.Status) error {
|
||||
var err error
|
||||
|
||||
if !status.EditsPopulated() {
|
||||
// Status edits are out-of-date with IDs, repopulate.
|
||||
status.Edits, err = s.state.DB.GetStatusEditsByIDs(
|
||||
gtscontext.SetBarebones(ctx),
|
||||
status.EditIDs,
|
||||
)
|
||||
if err != nil {
|
||||
return gtserror.Newf("error populating status edits: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *statusDB) PutStatus(ctx context.Context, status *gtsmodel.Status) error {
|
||||
return s.state.Caches.DB.Status.Store(status, func() error {
|
||||
// It is safe to run this database transaction within cache.Store
|
||||
|
|
|
|||
|
|
@ -41,8 +41,12 @@ type Status interface {
|
|||
GetStatusBoost(ctx context.Context, boostOfID string, byAccountID string) (*gtsmodel.Status, error)
|
||||
|
||||
// PopulateStatus ensures that all sub-models of a status are populated (e.g. mentions, attachments, etc).
|
||||
// Except for edits, to fetch these please call PopulateStatusEdits() .
|
||||
PopulateStatus(ctx context.Context, status *gtsmodel.Status) error
|
||||
|
||||
// PopulateStatusEdits ensures that status' edits are fully popualted.
|
||||
PopulateStatusEdits(ctx context.Context, status *gtsmodel.Status) error
|
||||
|
||||
// PutStatus stores one status in the database.
|
||||
PutStatus(ctx context.Context, status *gtsmodel.Status) error
|
||||
|
||||
|
|
|
|||
|
|
@ -60,6 +60,12 @@ func (p *Processor) Edit(
|
|||
)
|
||||
}
|
||||
|
||||
// We need the status populated including all historical edits.
|
||||
if err := p.state.DB.PopulateStatusEdits(ctx, status); err != nil {
|
||||
err := gtserror.Newf("error getting status edits from db: %w", err)
|
||||
return nil, gtserror.NewErrorInternalError(err)
|
||||
}
|
||||
|
||||
// Time of edit.
|
||||
now := time.Now()
|
||||
|
||||
|
|
@ -337,9 +343,14 @@ func (p *Processor) HistoryGet(ctx context.Context, requester *gtsmodel.Account,
|
|||
return nil, errWithCode
|
||||
}
|
||||
|
||||
if err := p.state.DB.PopulateStatusEdits(ctx, target); err != nil {
|
||||
err := gtserror.Newf("error getting status edits from db: %w", err)
|
||||
return nil, gtserror.NewErrorInternalError(err)
|
||||
}
|
||||
|
||||
edits, err := p.converter.StatusToAPIEdits(ctx, target)
|
||||
if err != nil {
|
||||
err := gtserror.Newf("error converting status: %w", err)
|
||||
err := gtserror.Newf("error converting status edits: %w", err)
|
||||
return nil, gtserror.NewErrorInternalError(err)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1591,7 +1591,7 @@ func (c *Converter) StatusToAPIEdits(ctx context.Context, status *gtsmodel.Statu
|
|||
Account: apiAccount,
|
||||
Poll: apiPoll,
|
||||
MediaAttachments: apiAttachments,
|
||||
Emojis: apiEmojis, // todo
|
||||
Emojis: apiEmojis, // same models used for whole status + all edits
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue