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() {
|
||||||
|
@ -71,11 +74,15 @@ func init() {
|
||||||
replyStmts = ReplyStmts{
|
replyStmts = ReplyStmts{
|
||||||
isLiked: acc.Select("likes").Columns("targetItem").Where("sentBy=? and targetItem=? and targetType='replies'").Prepare(),
|
isLiked: acc.Select("likes").Columns("targetItem").Where("sentBy=? and targetItem=? and targetType='replies'").Prepare(),
|
||||||
createLike: acc.Insert("likes").Columns("weight, targetItem, targetType, sentBy").Fields("?,?,?,?").Prepare(),
|
createLike: acc.Insert("likes").Columns("weight, targetItem, targetType, sentBy").Fields("?,?,?,?").Prepare(),
|
||||||
edit: acc.Update(re).Set("content = ?, parsed_content = ?").Where("rid = ? AND poll = 0").Prepare(),
|
edit: acc.Update(re).Set("content=?,parsed_content=?").Where("rid=? AND poll=0").Prepare(),
|
||||||
setPoll: acc.Update(re).Set("poll = ?").Where("rid = ? AND poll = 0").Prepare(),
|
setPoll: acc.Update(re).Set("poll=?").Where("rid=? AND poll=0").Prepare(),
|
||||||
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)
|
||||||
|
|
|
@ -216,19 +216,19 @@ func init() {
|
||||||
getRids: acc.Select("replies").Columns("rid").Where("tid = ?").Orderby("rid ASC").Limit("?,?").Prepare(),
|
getRids: acc.Select("replies").Columns("rid").Where("tid = ?").Orderby("rid ASC").Limit("?,?").Prepare(),
|
||||||
getReplies: acc.SimpleLeftJoin("replies AS r", "users AS u", "r.rid, r.content, r.createdBy, r.createdAt, r.lastEdit, r.lastEditBy, u.avatar, u.name, u.group, u.level, r.ipaddress, r.likeCount, r.attachCount, r.actionType", "r.createdBy = u.uid", "r.tid = ?", "r.rid ASC", "?,?"),
|
getReplies: acc.SimpleLeftJoin("replies AS r", "users AS u", "r.rid, r.content, r.createdBy, r.createdAt, r.lastEdit, r.lastEditBy, u.avatar, u.name, u.group, u.level, r.ipaddress, r.likeCount, r.attachCount, r.actionType", "r.createdBy = u.uid", "r.tid = ?", "r.rid ASC", "?,?"),
|
||||||
addReplies: acc.Update(t).Set("postCount = postCount + ?, lastReplyBy = ?, lastReplyAt = UTC_TIMESTAMP()").Where("tid = ?").Prepare(),
|
addReplies: acc.Update(t).Set("postCount = postCount + ?, lastReplyBy = ?, lastReplyAt = UTC_TIMESTAMP()").Where("tid = ?").Prepare(),
|
||||||
updateLastReply: acc.Update(t).Set("lastReplyID = ?").Where("lastReplyID > ? AND tid = ?").Prepare(),
|
updateLastReply: acc.Update(t).Set("lastReplyID=?").Where("lastReplyID > ? AND tid = ?").Prepare(),
|
||||||
lock: acc.Update(t).Set("is_closed = 1").Where("tid = ?").Prepare(),
|
lock: acc.Update(t).Set("is_closed=1").Where("tid=?").Prepare(),
|
||||||
unlock: acc.Update(t).Set("is_closed = 0").Where("tid = ?").Prepare(),
|
unlock: acc.Update(t).Set("is_closed=0").Where("tid=?").Prepare(),
|
||||||
moveTo: acc.Update(t).Set("parentID = ?").Where("tid = ?").Prepare(),
|
moveTo: acc.Update(t).Set("parentID=?").Where("tid=?").Prepare(),
|
||||||
stick: acc.Update(t).Set("sticky = 1").Where("tid = ?").Prepare(),
|
stick: acc.Update(t).Set("sticky=1").Where("tid=?").Prepare(),
|
||||||
unstick: acc.Update(t).Set("sticky = 0").Where("tid = ?").Prepare(),
|
unstick: acc.Update(t).Set("sticky=0").Where("tid=?").Prepare(),
|
||||||
hasLikedTopic: acc.Select("likes").Columns("targetItem").Where("sentBy = ? and targetItem = ? and targetType = 'topics'").Prepare(),
|
hasLikedTopic: acc.Select("likes").Columns("targetItem").Where("sentBy=? and targetItem=? and targetType='topics'").Prepare(),
|
||||||
createLike: acc.Insert("likes").Columns("weight, targetItem, targetType, sentBy, createdAt").Fields("?,?,?,?,UTC_TIMESTAMP()").Prepare(),
|
createLike: acc.Insert("likes").Columns("weight, targetItem, targetType, sentBy, createdAt").Fields("?,?,?,?,UTC_TIMESTAMP()").Prepare(),
|
||||||
addLikesToTopic: acc.Update(t).Set("likeCount = likeCount + ?").Where("tid = ?").Prepare(),
|
addLikesToTopic: acc.Update(t).Set("likeCount=likeCount+?").Where("tid = ?").Prepare(),
|
||||||
delete: acc.Delete(t).Where("tid = ?").Prepare(),
|
delete: acc.Delete(t).Where("tid = ?").Prepare(),
|
||||||
deleteActivity: acc.Delete("activity_stream").Where("elementID = ? AND elementType = 'topic'").Prepare(),
|
deleteActivity: acc.Delete("activity_stream").Where("elementID=? AND elementType='topic'").Prepare(),
|
||||||
deleteActivitySubs: acc.Delete("activity_subscriptions").Where("targetID = ? AND targetType = 'topic'").Prepare(),
|
deleteActivitySubs: acc.Delete("activity_subscriptions").Where("targetID=? AND targetType='topic'").Prepare(),
|
||||||
edit: acc.Update(t).Set("title = ?, content = ?, parsed_content = ?").Where("tid = ?").Prepare(), // TODO: Only run the content update bits on non-polls, does this matter?
|
edit: acc.Update(t).Set("title=?,content=?,parsed_content=?").Where("tid=?").Prepare(), // TODO: Only run the content update bits on non-polls, does this matter?
|
||||||
setPoll: acc.Update(t).Set("poll = ?").Where("tid = ? AND poll = 0").Prepare(),
|
setPoll: acc.Update(t).Set("poll = ?").Where("tid = ? AND poll = 0").Prepare(),
|
||||||
createAction: acc.Insert("replies").Columns("tid, actionType, ipaddress, createdBy, createdAt, lastUpdated, content, parsed_content").Fields("?,?,?,?,UTC_TIMESTAMP(),UTC_TIMESTAMP(),'',''").Prepare(),
|
createAction: acc.Insert("replies").Columns("tid, actionType, ipaddress, createdBy, createdAt, lastUpdated, content, parsed_content").Fields("?,?,?,?,UTC_TIMESTAMP(),UTC_TIMESTAMP(),'',''").Prepare(),
|
||||||
|
|
||||||
|
|
|
@ -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