diff --git a/common/reply.go b/common/reply.go index fbaf6cf5..6ae1c6eb 100644 --- a/common/reply.go +++ b/common/reply.go @@ -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(), diff --git a/common/topic.go b/common/topic.go index 2b677e0d..2f368acc 100644 --- a/common/topic.go +++ b/common/topic.go @@ -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 = "" diff --git a/misc_test.go b/misc_test.go index b022b557..9998527b 100644 --- a/misc_test.go +++ b/misc_test.go @@ -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)