Migrates Channel.IncrementMentionCount to sync by default (#11237)

* Migrates Channel.IncrementMentionCount to sync by default

* Calls to Channel.IncrementMentionCount are concurrent now
This commit is contained in:
Rodrigo Villablanca Vásquez
2019-06-25 06:13:39 -04:00
committed by Miguel de la Cruz
parent eb9415a668
commit 54d62dbadf
6 changed files with 42 additions and 34 deletions

View File

@@ -65,7 +65,7 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
hereNotification := false
channelNotification := false
allNotification := false
updateMentionChans := []store.StoreChannel{}
updateMentionChans := []chan *model.AppError{}
if channel.Type == model.CHANNEL_DIRECT {
var otherUserId string
@@ -136,8 +136,8 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
}
if len(m.OtherPotentialMentions) > 0 && !post.IsSystemMessage() {
if result := <-a.Srv.Store.User().GetProfilesByUsernames(m.OtherPotentialMentions, &model.ViewUsersRestrictions{Teams: []string{team.Id}}); result.Err == nil {
channelMentions := model.UserSlice(result.Data.([]*model.User)).FilterByActive(true)
if profilesResult := <-a.Srv.Store.User().GetProfilesByUsernames(m.OtherPotentialMentions, &model.ViewUsersRestrictions{Teams: []string{team.Id}}); profilesResult.Err == nil {
channelMentions := model.UserSlice(profilesResult.Data.([]*model.User)).FilterByActive(true)
var outOfChannelMentions model.UserSlice
var outOfGroupsMentions model.UserSlice
@@ -176,7 +176,12 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
mentionedUsersList := make([]string, 0, len(mentionedUserIds))
for id := range mentionedUserIds {
mentionedUsersList = append(mentionedUsersList, id)
updateMentionChans = append(updateMentionChans, a.Srv.Store.Channel().IncrementMentionCount(post.ChannelId, id))
umc := make(chan *model.AppError, 1)
go func() {
umc <- a.Srv.Store.Channel().IncrementMentionCount(post.ChannelId, id)
close(umc)
}()
updateMentionChans = append(updateMentionChans, umc)
}
notification := &postNotification{
@@ -275,8 +280,8 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
// Make sure all mention updates are complete to prevent race
// Probably better to batch these DB updates in the future
// MUST be completed before push notifications send
for _, uchan := range updateMentionChans {
if result := <-uchan; result.Err != nil {
for _, umc := range updateMentionChans {
if err := <-umc; err != nil {
mlog.Warn(fmt.Sprintf("Failed to update mention count, post_id=%v channel_id=%v err=%v", post.Id, post.ChannelId, result.Err), mlog.String("post_id", post.Id))
}
}