MM-41752: Batch update mention increment (#19596)
Previously, we were incrementing mentions one-by-one all concurrently in an unbounded fashion. This would cause a big spike in memory usage if there were an `@all` mention in a large channel. We fix this by changing the SQL query to take all userIDs at once. https://mattermost.atlassian.net/browse/MM-41752 ```release-note NONE ``` Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
dd100a3a69
Коммит
768fe43d3a
@@ -2549,24 +2549,32 @@ func (s SqlChannelStore) UpdateLastViewedAtPost(unreadPost *model.Post, userID s
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) IncrementMentionCount(channelId string, userId string, isRoot bool) error {
|
||||
func (s SqlChannelStore) IncrementMentionCount(channelId string, userIDs []string, isRoot bool) error {
|
||||
now := model.GetMillis()
|
||||
|
||||
rootInc := 0
|
||||
if isRoot {
|
||||
rootInc = 1
|
||||
}
|
||||
_, err := s.GetMasterX().Exec(
|
||||
`UPDATE
|
||||
ChannelMembers
|
||||
SET
|
||||
MentionCount = MentionCount + 1,
|
||||
MentionCountRoot = MentionCountRoot + ?,
|
||||
LastUpdateAt = ?
|
||||
WHERE
|
||||
UserId = ?
|
||||
AND ChannelId = ?`, rootInc, now, userId, channelId)
|
||||
|
||||
sql, args, err := s.getQueryBuilder().
|
||||
Update("ChannelMembers").
|
||||
Set("MentionCount", sq.Expr("MentionCount + 1")).
|
||||
Set("MentionCountRoot", sq.Expr("MentionCountRoot + ?", rootInc)).
|
||||
Set("LastUpdateAt", now).
|
||||
Where(sq.Eq{
|
||||
"UserId": userIDs,
|
||||
"ChannelId": channelId,
|
||||
}).
|
||||
ToSql()
|
||||
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to Update ChannelMembers with channelId=%s and userId=%s", channelId, userId)
|
||||
return errors.Wrap(err, "IncrementMentionCount_Tosql")
|
||||
}
|
||||
|
||||
_, err = s.GetMasterX().Exec(sql, args...)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to Update ChannelMembers with channelId=%s and userId=%v", channelId, userIDs)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user