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
|
||||
addLikesToReply *sql.Stmt
|
||||
removeRepliesFromTopic *sql.Stmt
|
||||
|
||||
updateTopicReplies *sql.Stmt
|
||||
updateTopicReplies2 *sql.Stmt
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
@ -76,6 +79,10 @@ func init() {
|
|||
delete: acc.Delete(re).Where("rid=?").Prepare(),
|
||||
addLikesToReply: acc.Update(re).Set("likeCount=likeCount+?").Where("rid=?").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()
|
||||
})
|
||||
|
@ -115,6 +122,14 @@ func (r *Reply) Delete() error {
|
|||
}
|
||||
// TODO: Move this bit to *Topic
|
||||
_, 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()
|
||||
if tc != nil {
|
||||
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
|
||||
if runtime.GOOS == "linux" {
|
||||
var dbsocket = "/tmp/mysql.sock"
|
||||
dbsocket := "/tmp/mysql.sock"
|
||||
if config["socket"] != "" {
|
||||
dbsocket = config["socket"]
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue