mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-26 02:33:31 -06: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
|
|
@ -361,14 +361,12 @@ func (c *Converter) ASStatusToStatus(ctx context.Context, statusable ap.Statusab
|
|||
status.CreatedAt = time.Now()
|
||||
}
|
||||
|
||||
// status.Updated
|
||||
// status.Edited
|
||||
//
|
||||
// Extract and validate update time for status. Defaults to published.
|
||||
// Extract and validate update time for status. Defaults to none.
|
||||
if upd := ap.GetUpdated(statusable); !upd.Before(status.CreatedAt) {
|
||||
status.UpdatedAt = upd
|
||||
} else if upd.IsZero() {
|
||||
status.UpdatedAt = status.CreatedAt
|
||||
} else {
|
||||
status.EditedAt = upd
|
||||
} else if !upd.IsZero() {
|
||||
|
||||
// This is a malformed status that will likely break our systems.
|
||||
err := gtserror.Newf("status %s 'updated' predates 'published'", uri)
|
||||
|
|
@ -649,9 +647,9 @@ func (c *Converter) ASAnnounceToStatus(
|
|||
// zero-time will fall back to db defaults.
|
||||
if pub := ap.GetPublished(announceable); !pub.IsZero() {
|
||||
boost.CreatedAt = pub
|
||||
boost.UpdatedAt = pub
|
||||
} else {
|
||||
log.Warnf(ctx, "unusable published property on %s", uri)
|
||||
boost.CreatedAt = time.Now()
|
||||
}
|
||||
|
||||
// Extract and load the boost actor account,
|
||||
|
|
|
|||
|
|
@ -486,7 +486,9 @@ func (c *Converter) StatusToAS(ctx context.Context, s *gtsmodel.Status) (ap.Stat
|
|||
|
||||
// Set created / updated at properties.
|
||||
ap.SetPublished(status, s.CreatedAt)
|
||||
ap.SetUpdated(status, s.UpdatedAt)
|
||||
if at := s.EditedAt; !at.IsZero() {
|
||||
ap.SetUpdated(status, at)
|
||||
}
|
||||
|
||||
// url
|
||||
if s.URL != "" {
|
||||
|
|
|
|||
|
|
@ -499,7 +499,6 @@ func (suite *InternalToASTestSuite) TestStatusToAS() {
|
|||
"tag": [],
|
||||
"to": "https://www.w3.org/ns/activitystreams#Public",
|
||||
"type": "Note",
|
||||
"updated": "2021-10-20T12:40:37+02:00",
|
||||
"url": "http://localhost:8080/@the_mighty_zork/statuses/01F8MHAMCHF6Y650WCRSCP4WMY"
|
||||
}`, string(bytes))
|
||||
}
|
||||
|
|
@ -599,7 +598,6 @@ func (suite *InternalToASTestSuite) TestStatusWithTagsToASWithIDs() {
|
|||
],
|
||||
"to": "https://www.w3.org/ns/activitystreams#Public",
|
||||
"type": "Note",
|
||||
"updated": "2021-10-20T11:36:45Z",
|
||||
"url": "http://localhost:8080/@admin/statuses/01F8MH75CBF9JFX4ZAD54N0W0R"
|
||||
}`, string(bytes))
|
||||
}
|
||||
|
|
@ -700,7 +698,6 @@ func (suite *InternalToASTestSuite) TestStatusWithTagsToASFromDB() {
|
|||
],
|
||||
"to": "https://www.w3.org/ns/activitystreams#Public",
|
||||
"type": "Note",
|
||||
"updated": "2021-10-20T11:36:45Z",
|
||||
"url": "http://localhost:8080/@admin/statuses/01F8MH75CBF9JFX4ZAD54N0W0R"
|
||||
}`, string(bytes))
|
||||
}
|
||||
|
|
@ -781,7 +778,6 @@ func (suite *InternalToASTestSuite) TestStatusToASWithMentions() {
|
|||
},
|
||||
"to": "https://www.w3.org/ns/activitystreams#Public",
|
||||
"type": "Note",
|
||||
"updated": "2021-11-20T13:32:16Z",
|
||||
"url": "http://localhost:8080/@admin/statuses/01FF25D5Q0DH7CHD57CTRS6WK0"
|
||||
}`, string(bytes))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -997,7 +997,7 @@ func (c *Converter) statusToAPIFilterResults(
|
|||
|
||||
// Key this status based on ID + last updated time,
|
||||
// to ensure we always filter on latest version.
|
||||
statusKey := s.ID + strconv.FormatInt(s.UpdatedAt.Unix(), 10)
|
||||
statusKey := s.ID + strconv.FormatInt(s.UpdatedAt().Unix(), 10)
|
||||
|
||||
// Check if we have filterable fields cached for this status.
|
||||
cache := c.state.Caches.StatusesFilterableFields
|
||||
|
|
@ -1384,10 +1384,8 @@ func (c *Converter) baseStatusToFrontend(
|
|||
InteractionPolicy: *apiInteractionPolicy,
|
||||
}
|
||||
|
||||
// Only set edited_at if this is a non-boost-wrapper
|
||||
// with an updated_at date different to creation date.
|
||||
if !s.UpdatedAt.Equal(s.CreatedAt) && s.BoostOfID == "" {
|
||||
timestamp := util.FormatISO8601(s.UpdatedAt)
|
||||
if at := s.EditedAt; !at.IsZero() {
|
||||
timestamp := util.FormatISO8601(at)
|
||||
apiStatus.EditedAt = util.Ptr(timestamp)
|
||||
}
|
||||
|
||||
|
|
@ -1522,8 +1520,8 @@ func (c *Converter) StatusToAPIEdits(ctx context.Context, status *gtsmodel.Statu
|
|||
PollOptions: options,
|
||||
PollVotes: votes,
|
||||
AttachmentIDs: status.AttachmentIDs,
|
||||
AttachmentDescriptions: nil, // no change from current
|
||||
CreatedAt: status.UpdatedAt,
|
||||
AttachmentDescriptions: nil, // no change from current
|
||||
CreatedAt: status.UpdatedAt(), // falls back to creation
|
||||
})
|
||||
|
||||
// Iterate through status edits, starting at newest.
|
||||
|
|
|
|||
|
|
@ -161,7 +161,7 @@ func (c *Converter) StatusToRSSItem(ctx context.Context, s *gtsmodel.Status) (*f
|
|||
Description: description,
|
||||
Id: id,
|
||||
IsPermaLink: "true",
|
||||
Updated: s.UpdatedAt,
|
||||
Updated: s.EditedAt,
|
||||
Created: s.CreatedAt,
|
||||
Enclosure: enclosure,
|
||||
Content: content,
|
||||
|
|
|
|||
|
|
@ -50,7 +50,6 @@ func (suite *InternalToRSSTestSuite) TestStatusToRSSItem1() {
|
|||
suite.Equal("@the_mighty_zork@localhost:8080", item.Author.Name)
|
||||
suite.Equal("@the_mighty_zork@localhost:8080 made a new post: \"hello everyone!\"", item.Description)
|
||||
suite.Equal("http://localhost:8080/@the_mighty_zork/statuses/01F8MHAMCHF6Y650WCRSCP4WMY", item.Id)
|
||||
suite.EqualValues(1634726437, item.Updated.Unix())
|
||||
suite.EqualValues(1634726437, item.Created.Unix())
|
||||
suite.Equal("", item.Enclosure.Length)
|
||||
suite.Equal("", item.Enclosure.Type)
|
||||
|
|
@ -76,7 +75,6 @@ func (suite *InternalToRSSTestSuite) TestStatusToRSSItem2() {
|
|||
suite.Equal("@admin@localhost:8080", item.Author.Name)
|
||||
suite.Equal("@admin@localhost:8080 posted 1 attachment: \"hello world! #welcome ! first post on the instance :rainbow: !\"", item.Description)
|
||||
suite.Equal("http://localhost:8080/@admin/statuses/01F8MH75CBF9JFX4ZAD54N0W0R", item.Id)
|
||||
suite.EqualValues(1634729805, item.Updated.Unix())
|
||||
suite.EqualValues(1634729805, item.Created.Unix())
|
||||
suite.Equal("62529", item.Enclosure.Length)
|
||||
suite.Equal("image/jpeg", item.Enclosure.Type)
|
||||
|
|
|
|||
|
|
@ -131,7 +131,6 @@ func (suite *WrapTestSuite) TestWrapNoteInCreate() {
|
|||
"tag": [],
|
||||
"to": "https://www.w3.org/ns/activitystreams#Public",
|
||||
"type": "Note",
|
||||
"updated": "2021-10-20T12:40:37+02:00",
|
||||
"url": "http://localhost:8080/@the_mighty_zork/statuses/01F8MHAMCHF6Y650WCRSCP4WMY"
|
||||
},
|
||||
"published": "2021-10-20T12:40:37+02:00",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue