Update last reply on topics properly upon reply delete.
This commit is contained in:
parent
69a2430e5a
commit
e4cfe610f6
@ -63,6 +63,9 @@ type ReplyStmts struct {
|
|||||||
delete *sql.Stmt
|
delete *sql.Stmt
|
||||||
addLikesToReply *sql.Stmt
|
addLikesToReply *sql.Stmt
|
||||||
removeRepliesFromTopic *sql.Stmt
|
removeRepliesFromTopic *sql.Stmt
|
||||||
|
|
||||||
|
updateTopicReplies *sql.Stmt
|
||||||
|
updateTopicReplies2 *sql.Stmt
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -76,6 +79,10 @@ func init() {
|
|||||||
delete: acc.Delete(re).Where("rid=?").Prepare(),
|
delete: acc.Delete(re).Where("rid=?").Prepare(),
|
||||||
addLikesToReply: acc.Update(re).Set("likeCount=likeCount+?").Where("rid=?").Prepare(),
|
addLikesToReply: acc.Update(re).Set("likeCount=likeCount+?").Where("rid=?").Prepare(),
|
||||||
removeRepliesFromTopic: acc.Update("topics").Set("postCount=postCount-?").Where("tid=?").Prepare(),
|
removeRepliesFromTopic: acc.Update("topics").Set("postCount=postCount-?").Where("tid=?").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 = ?"),
|
||||||
|
updateTopicReplies2: acc.Update("topics").Set("lastReplyAt=createdAt,lastReplyBy=createdBy,lastReplyID=0").Where("postCount=1 AND tid=?").Prepare(),
|
||||||
}
|
}
|
||||||
return acc.FirstError()
|
return acc.FirstError()
|
||||||
})
|
})
|
||||||
@ -115,6 +122,14 @@ func (r *Reply) Delete() error {
|
|||||||
}
|
}
|
||||||
// TODO: Move this bit to *Topic
|
// TODO: Move this bit to *Topic
|
||||||
_, err = replyStmts.removeRepliesFromTopic.Exec(1, r.ParentID)
|
_, err = replyStmts.removeRepliesFromTopic.Exec(1, r.ParentID)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = replyStmts.updateTopicReplies.Exec(r.ParentID)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = replyStmts.updateTopicReplies2.Exec(r.ParentID)
|
||||||
tc := Topics.GetCache()
|
tc := Topics.GetCache()
|
||||||
if tc != nil {
|
if tc != nil {
|
||||||
tc.Remove(r.ParentID)
|
tc.Remove(r.ParentID)
|
||||||
|
@ -52,7 +52,7 @@ func (a *MysqlAdapter) BuildConn(config map[string]string) (*sql.DB, error) {
|
|||||||
|
|
||||||
// First try opening a pipe as those are faster
|
// First try opening a pipe as those are faster
|
||||||
if runtime.GOOS == "linux" {
|
if runtime.GOOS == "linux" {
|
||||||
var dbsocket = "/tmp/mysql.sock"
|
dbsocket := "/tmp/mysql.sock"
|
||||||
if config["socket"] != "" {
|
if config["socket"] != "" {
|
||||||
dbsocket = config["socket"]
|
dbsocket = config["socket"]
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user