summaryrefslogtreecommitdiffstats
path: root/store
diff options
context:
space:
mode:
authorJesús Espino <jespinog@gmail.com>2018-02-16 01:41:49 +0100
committerChristopher Speller <crspeller@gmail.com>2018-02-15 16:41:49 -0800
commit2930766c65fe5703e7bbec45c605cc7fc4188a66 (patch)
tree40c89789bc19bef7348de7fb4ac7e53764563f19 /store
parentc158e9a5a0f776dcf19ad8b9e38e83a1f51dd918 (diff)
downloadchat-2930766c65fe5703e7bbec45c605cc7fc4188a66.tar.gz
chat-2930766c65fe5703e7bbec45c605cc7fc4188a66.tar.bz2
chat-2930766c65fe5703e7bbec45c605cc7fc4188a66.zip
PLT-8723: Fix DeadLock on reactions insertions (#8225)
* PLT-8723: Fix DeadLock on reactions insertions * Improved the HasReactions update SQL
Diffstat (limited to 'store')
-rw-r--r--store/sqlstore/supplier_reactions.go26
1 files changed, 20 insertions, 6 deletions
diff --git a/store/sqlstore/supplier_reactions.go b/store/sqlstore/supplier_reactions.go
index 052472bf9..aa3b078ea 100644
--- a/store/sqlstore/supplier_reactions.go
+++ b/store/sqlstore/supplier_reactions.go
@@ -134,7 +134,7 @@ func (s *SqlSupplier) ReactionDeleteAllWithEmojiName(ctx context.Context, emojiN
}
for _, reaction := range reactions {
- if _, err := s.GetMaster().Exec(UPDATE_POST_HAS_REACTIONS_QUERY,
+ if _, err := s.GetMaster().Exec(UPDATE_POST_HAS_REACTIONS_ON_DELETE_QUERY,
map[string]interface{}{"PostId": reaction.PostId, "UpdateAt": model.GetMillis()}); err != nil {
l4g.Warn(utils.T("store.sql_reaction.delete_all_with_emoji_name.update_post.warn"), reaction.PostId, err.Error())
}
@@ -174,7 +174,7 @@ func saveReactionAndUpdatePost(transaction *gorp.Transaction, reaction *model.Re
return err
}
- return updatePostForReactions(transaction, reaction.PostId)
+ return updatePostForReactionsOnInsert(transaction, reaction.PostId)
}
func deleteReactionAndUpdatePost(transaction *gorp.Transaction, reaction *model.Reaction) error {
@@ -189,12 +189,12 @@ func deleteReactionAndUpdatePost(transaction *gorp.Transaction, reaction *model.
return err
}
- return updatePostForReactions(transaction, reaction.PostId)
+ return updatePostForReactionsOnDelete(transaction, reaction.PostId)
}
const (
// Set HasReactions = true if and only if the post has reactions, update UpdateAt only if HasReactions changes
- UPDATE_POST_HAS_REACTIONS_QUERY = `UPDATE
+ UPDATE_POST_HAS_REACTIONS_ON_DELETE_QUERY = `UPDATE
Posts
SET
UpdateAt = (CASE
@@ -206,8 +206,22 @@ const (
Id = :PostId`
)
-func updatePostForReactions(transaction *gorp.Transaction, postId string) error {
- _, err := transaction.Exec(UPDATE_POST_HAS_REACTIONS_QUERY, map[string]interface{}{"PostId": postId, "UpdateAt": model.GetMillis()})
+func updatePostForReactionsOnDelete(transaction *gorp.Transaction, postId string) error {
+ _, err := transaction.Exec(UPDATE_POST_HAS_REACTIONS_ON_DELETE_QUERY, map[string]interface{}{"PostId": postId, "UpdateAt": model.GetMillis()})
+
+ return err
+}
+
+func updatePostForReactionsOnInsert(transaction *gorp.Transaction, postId string) error {
+ _, err := transaction.Exec(
+ `UPDATE
+ Posts
+ SET
+ HasReactions = True,
+ UpdateAt = :UpdateAt
+ WHERE
+ Id = :PostId AND HasReactions = False`,
+ map[string]interface{}{"PostId": postId, "UpdateAt": model.GetMillis()})
return err
}