Set the metadata for the last reply rather than the first in a topic when a reply is deleted.

Add tests to check the LastReplyID for a topic before and after a reply is deleted.
This commit is contained in:
Azareal 2021-03-25 19:04:02 +10:00
parent 6446a1fa4c
commit f6a94d39d6
3 changed files with 8 additions and 1 deletions

View File

@ -91,7 +91,7 @@ func init() {
deleteActivitySubs: acc.Delete("activity_subscriptions").Where("targetID=? AND targetType='post'").Prepare(),
// TODO: Optimise this to avoid firing an update if it's not the last reply in a topic. We will need to set lastReplyID properly in other places and in the patcher first so we can use it here.
updateTopicReplies: acc.RawPrepare("UPDATE topics t INNER JOIN replies r ON t.tid=r.tid SET t.lastReplyBy=r.createdBy, t.lastReplyAt=r.createdAt, t.lastReplyID=r.rid WHERE t.tid=?"),
updateTopicReplies: acc.RawPrepare("UPDATE topics t INNER JOIN replies r ON t.tid=r.tid SET t.lastReplyBy=r.createdBy, t.lastReplyAt=r.createdAt, t.lastReplyID=r.rid WHERE t.tid=? ORDER BY r.rid DESC"),
updateTopicReplies2: acc.Update("topics").Set("lastReplyAt=createdAt,lastReplyBy=createdBy,lastReplyID=0").Where("postCount=1 AND tid=?").Prepare(),
getAidsOfReply: acc.Select("attachments").Columns("attachID").Where("originID=? AND originTable='replies'").Prepare(),

View File

@ -519,6 +519,7 @@ func (t *Topic) SetPoll(pollID int) error {
}
// TODO: Have this go through the ReplyStore?
// TODO: Return the rid?
func (t *Topic) CreateActionReply(action, ip string, uid int) (err error) {
if Config.DisablePostIP {
ip = ""

View File

@ -1195,6 +1195,8 @@ func testReplyStore(t *testing.T, newID int, ip string) {
topic, err = c.Topics.Get(tid)
expectNilErr(t, err)
exf(topic.PostCount == newPostCount+2, "topic.PostCount should be %d, not %d", newPostCount+2, topic.PostCount)
exf(topic.LastReplyID != rid, "topic.LastReplyID should not be %d", rid)
arid := topic.LastReplyID
// TODO: Expand upon this
rid, err = c.Rstore.Create(topic, "hiii", ip, 1)
@ -1218,6 +1220,10 @@ func testReplyStore(t *testing.T, newID int, ip string) {
_, err = c.Rstore.Get(rid)
recordMustNotExist(t, err, fmt.Sprintf("RID #%d shouldn't exist", rid))
topic, err = c.Topics.Get(tid)
expectNilErr(t, err)
exf(topic.LastReplyID == arid, "topic.LastReplyID should be %d not %d", arid, topic.LastReplyID)
// TODO: Write a test for this
//(topic *TopicUser) Replies(offset int, pFrag int, user *User) (rlist []*ReplyUser, ogdesc string, err error)