ensure that status.updated_at always fits chronologically

This commit is contained in:
kim 2024-12-03 23:57:36 +00:00
commit bcfa9af8a5
2 changed files with 13 additions and 5 deletions

View file

@ -926,6 +926,15 @@ func (d *Dereferencer) updateStatus(
// any other changes in status content itself.
if pollChanged || statusChanged(existing, status) {
// We prefer to use provided 'upated_at', but ensure
// it fits chronologically with creation / last update.
if !status.UpdatedAt.After(status.CreatedAt) ||
!status.UpdatedAt.After(existing.UpdatedAt) {
// Else fallback to now as update time.
status.UpdatedAt = status.FetchedAt
}
// Status has been editted since last
// we saw it, take snapshot of existing.
var edit gtsmodel.StatusEdit
@ -1009,7 +1018,7 @@ func (d *Dereferencer) updateStatusPoll(
// insert latest poll version into database.
return true, d.insertStatusPoll(ctx, status)
case pollUpdated(existing.Poll, status.Poll):
case pollStateUpdated(existing.Poll, status.Poll):
// Since we last saw it, the poll has updated!
// Whether that be stats, or close time.
poll := existing.Poll

View file

@ -58,9 +58,9 @@ func pollChanged(existing, latest *gtsmodel.Poll) bool {
!existing.ExpiresAt.Equal(latest.ExpiresAt)
}
// pollUpdated returns whether a poll has updated, i.e. if the
// pollStateUpdated returns whether a poll has updated, i.e. if
// vote counts have changed, or if it has expired / been closed.
func pollUpdated(existing, latest *gtsmodel.Poll) bool {
func pollStateUpdated(existing, latest *gtsmodel.Poll) bool {
return *existing.Voters != *latest.Voters ||
!slices.Equal(existing.Votes, latest.Votes) ||
!existing.ClosedAt.Equal(latest.ClosedAt)
@ -74,8 +74,7 @@ func pollJustClosed(existing, latest *gtsmodel.Poll) bool {
// statusChanged returns whether a status has changed in a way that
// indicates that existing should be snapshotted for version history.
func statusChanged(existing, latest *gtsmodel.Status) bool {
return !existing.UpdatedAt.Equal(latest.UpdatedAt) ||
existing.Content != latest.Content ||
return existing.Content != latest.Content ||
existing.ContentWarning != latest.ContentWarning ||
!slices.Equal(existing.AttachmentIDs, latest.AttachmentIDs)
}