mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
Fix issue with Aurora read replica (#5448)
This commit is contained in:
committed by
Joram Wilander
parent
48b785aded
commit
da448cedc8
@@ -7,6 +7,7 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
l4g "github.com/alecthomas/log4go"
|
||||
"github.com/mattermost/platform/model"
|
||||
@@ -153,6 +154,8 @@ func CreateDirectChannel(userId string, otherUserId string) (*model.Channel, *mo
|
||||
} else {
|
||||
channel := result.Data.(*model.Channel)
|
||||
|
||||
WaitForChannelMembership(channel.Id, userId)
|
||||
|
||||
InvalidateCacheForUser(userId)
|
||||
InvalidateCacheForUser(otherUserId)
|
||||
|
||||
@@ -164,6 +167,31 @@ func CreateDirectChannel(userId string, otherUserId string) (*model.Channel, *mo
|
||||
}
|
||||
}
|
||||
|
||||
func WaitForChannelMembership(channelId string, userId string) {
|
||||
if len(utils.Cfg.SqlSettings.DataSourceReplicas) > 0 {
|
||||
now := model.GetMillis()
|
||||
|
||||
for model.GetMillis()-now < 12000 {
|
||||
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
|
||||
result := <-Srv.Store.Channel().GetMember(channelId, userId)
|
||||
|
||||
// If the membership was found then return
|
||||
if result.Err == nil {
|
||||
return
|
||||
}
|
||||
|
||||
// If we recieved a error but it wasn't a missing channel member then return
|
||||
if result.Err.Id != store.MISSING_CHANNEL_MEMBER_ERROR {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
l4g.Error("WaitForChannelMembership giving up channelId=%v userId=%v", channelId, userId)
|
||||
}
|
||||
}
|
||||
|
||||
func UpdateChannel(channel *model.Channel) (*model.Channel, *model.AppError) {
|
||||
if result := <-Srv.Store.Channel().Update(channel); result.Err != nil {
|
||||
return nil, result.Err
|
||||
@@ -327,6 +355,8 @@ func addUserToChannel(user *model.User, channel *model.Channel) (*model.ChannelM
|
||||
return nil, model.NewLocAppError("AddUserToChannel", "api.channel.add_user.to.channel.failed.app_error", nil, "")
|
||||
}
|
||||
|
||||
WaitForChannelMembership(channel.Id, user.Id)
|
||||
|
||||
InvalidateCacheForUser(user.Id)
|
||||
InvalidateCacheForChannelMembers(channel.Id)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user