mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-10-29 07:22:24 -05:00
[chore] replace statuses.updated_at column with statuses.edited_at (#3636)
* update statuses table to replace updated_at column with edited_at * code comment * better code comments, fix setting of status + edit + mention + poll database times * fix log to logf call * fix status.EditIDs not being carried over in dereferencer.encrichStatus() * move status.EditID setting into handleStatusEdit()
This commit is contained in:
parent
e9bb7ddd3a
commit
c013892ca2
23 changed files with 417 additions and 118 deletions
|
|
@ -656,6 +656,10 @@ func (d *Dereferencer) fetchStatusMentions(
|
|||
err error,
|
||||
) {
|
||||
|
||||
// Get most-recent modified time
|
||||
// for use in new mention ULIDs.
|
||||
updatedAt := status.UpdatedAt()
|
||||
|
||||
// Allocate new slice to take the yet-to-be created mention IDs.
|
||||
status.MentionIDs = make([]string, len(status.Mentions))
|
||||
|
||||
|
|
@ -691,10 +695,10 @@ func (d *Dereferencer) fetchStatusMentions(
|
|||
|
||||
// This mention didn't exist yet.
|
||||
// Generate new ID according to latest update.
|
||||
mention.ID = id.NewULIDFromTime(status.UpdatedAt)
|
||||
mention.ID = id.NewULIDFromTime(updatedAt)
|
||||
|
||||
// Set known further mention details.
|
||||
mention.CreatedAt = status.UpdatedAt
|
||||
// Set further mention details.
|
||||
mention.CreatedAt = updatedAt
|
||||
mention.OriginAccount = status.Account
|
||||
mention.OriginAccountID = status.AccountID
|
||||
mention.OriginAccountURI = status.AccountURI
|
||||
|
|
@ -1096,8 +1100,12 @@ func (d *Dereferencer) handleStatusPoll(
|
|||
func (d *Dereferencer) insertStatusPoll(ctx context.Context, status *gtsmodel.Status) error {
|
||||
var err error
|
||||
|
||||
// Generate new ID for poll from latest updated time.
|
||||
status.Poll.ID = id.NewULIDFromTime(status.UpdatedAt)
|
||||
// Get most-recent modified time
|
||||
// which will be poll creation time.
|
||||
createdAt := status.UpdatedAt()
|
||||
|
||||
// Generate new ID for poll from createdAt.
|
||||
status.Poll.ID = id.NewULIDFromTime(createdAt)
|
||||
|
||||
// Update the status<->poll links.
|
||||
status.PollID = status.Poll.ID
|
||||
|
|
@ -1133,6 +1141,10 @@ func (d *Dereferencer) handleStatusEdit(
|
|||
) {
|
||||
var edited bool
|
||||
|
||||
// Copy previous status edit columns.
|
||||
status.EditIDs = existing.EditIDs
|
||||
status.Edits = existing.Edits
|
||||
|
||||
// Preallocate max slice length.
|
||||
cols = make([]string, 1, 13)
|
||||
|
||||
|
|
@ -1216,25 +1228,21 @@ func (d *Dereferencer) handleStatusEdit(
|
|||
}
|
||||
|
||||
if edited {
|
||||
// ensure that updated_at hasn't remained the same
|
||||
// but an edit was received. manually intervene here.
|
||||
if status.UpdatedAt.Equal(existing.UpdatedAt) ||
|
||||
status.CreatedAt.Equal(status.UpdatedAt) {
|
||||
|
||||
// Simply use current fetching time.
|
||||
status.UpdatedAt = status.FetchedAt
|
||||
}
|
||||
// Get previous-most-recent modified time,
|
||||
// which will be this edit's creation time.
|
||||
createdAt := existing.UpdatedAt()
|
||||
|
||||
// Status has been editted since last
|
||||
// we saw it, take snapshot of existing.
|
||||
var edit gtsmodel.StatusEdit
|
||||
edit.ID = id.NewULIDFromTime(status.UpdatedAt)
|
||||
edit.ID = id.NewULIDFromTime(createdAt)
|
||||
edit.Content = existing.Content
|
||||
edit.ContentWarning = existing.ContentWarning
|
||||
edit.Text = existing.Text
|
||||
edit.Language = existing.Language
|
||||
edit.Sensitive = existing.Sensitive
|
||||
edit.StatusID = status.ID
|
||||
edit.CreatedAt = createdAt
|
||||
|
||||
// Copy existing attachments and descriptions.
|
||||
edit.AttachmentIDs = existing.AttachmentIDs
|
||||
|
|
@ -1246,9 +1254,6 @@ func (d *Dereferencer) handleStatusEdit(
|
|||
}
|
||||
}
|
||||
|
||||
// Edit creation is last update time.
|
||||
edit.CreatedAt = existing.UpdatedAt
|
||||
|
||||
if existing.Poll != nil {
|
||||
// Poll only set if existing contained them.
|
||||
edit.PollOptions = existing.Poll.Options
|
||||
|
|
@ -1275,10 +1280,10 @@ func (d *Dereferencer) handleStatusEdit(
|
|||
cols = append(cols, "edits")
|
||||
}
|
||||
|
||||
if !existing.UpdatedAt.Equal(status.UpdatedAt) {
|
||||
if !existing.EditedAt.Equal(status.EditedAt) {
|
||||
// Whether status edited or not,
|
||||
// updated_at column has changed.
|
||||
cols = append(cols, "updated_at")
|
||||
// edited_at column has changed.
|
||||
cols = append(cols, "edited_at")
|
||||
}
|
||||
|
||||
return cols, nil
|
||||
|
|
|
|||
|
|
@ -337,7 +337,7 @@ func (suite *StatusTestSuite) TestDereferencerRefreshStatusUpdated() {
|
|||
AttachmentIDs: testStatus.AttachmentIDs,
|
||||
PollOptions: getPollOptions(testStatus),
|
||||
PollVotes: getPollVotes(testStatus),
|
||||
CreatedAt: testStatus.UpdatedAt,
|
||||
CreatedAt: testStatus.UpdatedAt(),
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue