MM-15198 Migrate Channel.Get/GetFromMaster to Sync by default (#10667)

* MM-15198 Migrate Channel.Get/GetFromMaster to Sync by default

* MM-15198 - Update store/storetest/post_store.go

fix error handling in post_store.go test case

Co-Authored-By: andresoro <ao15@my.fsu.edu>
Этот коммит содержится в:
Andres Orozco
2019-04-24 15:28:06 -04:00
коммит произвёл Miguel de la Cruz
родитель 370e9eedb1
Коммит 928ecba2d4
14 изменённых файлов: 141 добавлений и 128 удалений

Просмотреть файл

@@ -1109,16 +1109,16 @@ func (a *App) PostUpdateChannelDisplayNameMessage(userId string, channel *model.
} }
func (a *App) GetChannel(channelId string) (*model.Channel, *model.AppError) { func (a *App) GetChannel(channelId string) (*model.Channel, *model.AppError) {
result := <-a.Srv.Store.Channel().Get(channelId, true) channel, errCh := a.Srv.Store.Channel().Get(channelId, true)
if result.Err != nil { if errCh != nil {
if result.Err.Id == "store.sql_channel.get.existing.app_error" { if errCh.Id == "store.sql_channel.get.existing.app_error" {
result.Err.StatusCode = http.StatusNotFound errCh.StatusCode = http.StatusNotFound
return nil, result.Err return nil, errCh
} }
result.Err.StatusCode = http.StatusBadRequest errCh.StatusCode = http.StatusBadRequest
return nil, result.Err return nil, errCh
} }
return result.Data.(*model.Channel), nil return channel, nil
} }
func (a *App) GetChannelByName(channelName, teamId string, includeDeleted bool) (*model.Channel, *model.AppError) { func (a *App) GetChannelByName(channelName, teamId string, includeDeleted bool) (*model.Channel, *model.AppError) {
@@ -1424,7 +1424,13 @@ func (a *App) postJoinTeamMessage(user *model.User, channel *model.Channel) *mod
} }
func (a *App) LeaveChannel(channelId string, userId string) *model.AppError { func (a *App) LeaveChannel(channelId string, userId string) *model.AppError {
sc := a.Srv.Store.Channel().Get(channelId, true) sc := make(chan store.StoreResult, 1)
go func() {
channel, err := a.Srv.Store.Channel().Get(channelId, true)
sc <- store.StoreResult{Data: channel, Err: err}
close(sc)
}()
uc := make(chan store.StoreResult, 1) uc := make(chan store.StoreResult, 1)
go func() { go func() {
user, err := a.Srv.Store.User().Get(userId) user, err := a.Srv.Store.User().Get(userId)
@@ -1763,12 +1769,11 @@ func (a *App) MarkChannelsAsViewed(channelIds []string, userId string, currentSe
channelsToClearPushNotifications := []string{} channelsToClearPushNotifications := []string{}
if *a.Config().EmailSettings.SendPushNotifications { if *a.Config().EmailSettings.SendPushNotifications {
for _, channelId := range channelIds { for _, channelId := range channelIds {
chanResult := <-a.Srv.Store.Channel().Get(channelId, true) channel, errCh := a.Srv.Store.Channel().Get(channelId, true)
if chanResult.Err != nil { if errCh != nil {
mlog.Warn(fmt.Sprintf("Failed to get channel %v", chanResult.Err)) mlog.Warn(fmt.Sprintf("Failed to get channel %v", errCh))
continue continue
} }
channel := chanResult.Data.(*model.Channel)
member, err := a.Srv.Store.Channel().GetMember(channelId, userId) member, err := a.Srv.Store.Channel().GetMember(channelId, userId)
if err != nil { if err != nil {

Просмотреть файл

@@ -218,7 +218,12 @@ func (a *App) tryExecuteCustomCommand(args *model.CommandArgs, trigger string, m
return nil, nil, model.NewAppError("ExecuteCommand", "api.command.disabled.app_error", nil, "", http.StatusNotImplemented) return nil, nil, model.NewAppError("ExecuteCommand", "api.command.disabled.app_error", nil, "", http.StatusNotImplemented)
} }
chanChan := a.Srv.Store.Channel().Get(args.ChannelId, true) chanChan := make(chan store.StoreResult, 1)
go func() {
channel, err := a.Srv.Store.Channel().Get(args.ChannelId, true)
chanChan <- store.StoreResult{Data: channel, Err: err}
close(chanChan)
}()
teamChan := a.Srv.Store.Team().Get(args.TeamId) teamChan := a.Srv.Store.Team().Get(args.TeamId)
userChan := make(chan store.StoreResult, 1) userChan := make(chan store.StoreResult, 1)
go func() { go func() {

Просмотреть файл

@@ -216,12 +216,11 @@ func (s *Server) sendBatchedEmailNotification(userId string, notifications []*ba
continue continue
} }
result := <-s.Store.Channel().Get(notification.post.ChannelId, true) channel, errCh := s.Store.Channel().Get(notification.post.ChannelId, true)
if result.Err != nil { if errCh != nil {
mlog.Warn("Unable to find channel of post for batched email notification") mlog.Warn("Unable to find channel of post for batched email notification")
continue continue
} }
channel := result.Data.(*model.Channel)
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL
if license := s.License(); license != nil && *license.Features.EmailNotificationContents { if license := s.License(); license != nil && *license.Features.EmailNotificationContents {

Просмотреть файл

@@ -225,21 +225,17 @@ func (a *App) MigrateFilenamesToFileInfos(post *model.Post) []*model.FileInfo {
return []*model.FileInfo{} return []*model.FileInfo{}
} }
cchan := a.Srv.Store.Channel().Get(post.ChannelId, true) channel, errCh := a.Srv.Store.Channel().Get(post.ChannelId, true)
// There's a weird bug that rarely happens where a post ends up with duplicate Filenames so remove those // There's a weird bug that rarely happens where a post ends up with duplicate Filenames so remove those
filenames := utils.RemoveDuplicatesFromStringArray(post.Filenames) filenames := utils.RemoveDuplicatesFromStringArray(post.Filenames)
if errCh != nil {
result := <-cchan
if result.Err != nil {
mlog.Error( mlog.Error(
fmt.Sprintf("Unable to get channel when migrating post to use FileInfos, err=%v", result.Err), fmt.Sprintf("Unable to get channel when migrating post to use FileInfos, err=%v", errCh),
mlog.String("post_id", post.Id), mlog.String("post_id", post.Id),
mlog.String("channel_id", post.ChannelId), mlog.String("channel_id", post.ChannelId),
) )
return []*model.FileInfo{} return []*model.FileInfo{}
} }
channel := result.Data.(*model.Channel)
// Find the team that was used to make this post since its part of the file path that isn't saved in the Filename // Find the team that was used to make this post since its part of the file path that isn't saved in the Filename
var teamId string var teamId string
@@ -272,7 +268,7 @@ func (a *App) MigrateFilenamesToFileInfos(post *model.Post) []*model.FileInfo {
fileMigrationLock.Lock() fileMigrationLock.Lock()
defer fileMigrationLock.Unlock() defer fileMigrationLock.Unlock()
result = <-a.Srv.Store.Post().Get(post.Id) result := <-a.Srv.Store.Post().Get(post.Id)
if result.Err != nil { if result.Err != nil {
mlog.Error(fmt.Sprintf("Unable to get post when migrating post to use FileInfos, err=%v", result.Err), mlog.String("post_id", post.Id)) mlog.Error(fmt.Sprintf("Unable to get post when migrating post to use FileInfos, err=%v", result.Err), mlog.String("post_id", post.Id))
return []*model.FileInfo{} return []*model.FileInfo{}

Просмотреть файл

@@ -24,12 +24,11 @@ const (
func (a *App) CreatePostAsUser(post *model.Post, currentSessionId string) (*model.Post, *model.AppError) { func (a *App) CreatePostAsUser(post *model.Post, currentSessionId string) (*model.Post, *model.AppError) {
// Check that channel has not been deleted // Check that channel has not been deleted
result := <-a.Srv.Store.Channel().Get(post.ChannelId, true) channel, errCh := a.Srv.Store.Channel().Get(post.ChannelId, true)
if result.Err != nil { if errCh != nil {
err := model.NewAppError("CreatePostAsUser", "api.context.invalid_param.app_error", map[string]interface{}{"Name": "post.channel_id"}, result.Err.Error(), http.StatusBadRequest) err := model.NewAppError("CreatePostAsUser", "api.context.invalid_param.app_error", map[string]interface{}{"Name": "post.channel_id"}, errCh.Error(), http.StatusBadRequest)
return nil, err return nil, err
} }
channel := result.Data.(*model.Channel)
if strings.HasPrefix(post.Type, model.POST_SYSTEM_MESSAGE_PREFIX) { if strings.HasPrefix(post.Type, model.POST_SYSTEM_MESSAGE_PREFIX) {
err := model.NewAppError("CreatePostAsUser", "api.context.invalid_param.app_error", map[string]interface{}{"Name": "post.type"}, "", http.StatusBadRequest) err := model.NewAppError("CreatePostAsUser", "api.context.invalid_param.app_error", map[string]interface{}{"Name": "post.type"}, "", http.StatusBadRequest)
@@ -82,11 +81,10 @@ func (a *App) CreatePostAsUser(post *model.Post, currentSessionId string) (*mode
} }
func (a *App) CreatePostMissingChannel(post *model.Post, triggerWebhooks bool) (*model.Post, *model.AppError) { func (a *App) CreatePostMissingChannel(post *model.Post, triggerWebhooks bool) (*model.Post, *model.AppError) {
result := <-a.Srv.Store.Channel().Get(post.ChannelId, true) channel, err := a.Srv.Store.Channel().Get(post.ChannelId, true)
if result.Err != nil { if err != nil {
return nil, result.Err return nil, err
} }
channel := result.Data.(*model.Channel)
return a.CreatePost(post, channel, triggerWebhooks) return a.CreatePost(post, channel, triggerWebhooks)
} }

Просмотреть файл

@@ -401,13 +401,9 @@ func (a *App) CreateOutgoingWebhook(hook *model.OutgoingWebhook) (*model.Outgoin
} }
if len(hook.ChannelId) != 0 { if len(hook.ChannelId) != 0 {
cchan := a.Srv.Store.Channel().Get(hook.ChannelId, true) channel, errCh := a.Srv.Store.Channel().Get(hook.ChannelId, true)
if errCh != nil {
var channel *model.Channel return nil, errCh
if result := <-cchan; result.Err != nil {
return nil, result.Err
} else {
channel = result.Data.(*model.Channel)
} }
if channel.Type != model.CHANNEL_OPEN { if channel.Type != model.CHANNEL_OPEN {
@@ -641,7 +637,11 @@ func (a *App) HandleIncomingWebhook(hookId string, req *model.IncomingWebhookReq
cchan = a.Srv.Store.Channel().GetByName(hook.TeamId, channelName, true) cchan = a.Srv.Store.Channel().GetByName(hook.TeamId, channelName, true)
} }
} else { } else {
cchan = a.Srv.Store.Channel().Get(hook.ChannelId, true) var err *model.AppError
channel, err = a.Srv.Store.Channel().Get(hook.ChannelId, true)
if err != nil {
return model.NewAppError("HandleIncomingWebhook", "web.incoming_webhook.channel.app_error", nil, "err="+err.Message, err.StatusCode)
}
} }
if channel == nil { if channel == nil {

Просмотреть файл

@@ -51,8 +51,8 @@ func getChannelFromChannelArg(a *app.App, channelArg string) *model.Channel {
} }
if channel == nil { if channel == nil {
if result := <-a.Srv.Store.Channel().Get(channelPart, true); result.Err == nil { if ch, errCh := a.Srv.Store.Channel().Get(channelPart, true); errCh == nil {
channel = result.Data.(*model.Channel) channel = ch
} }
} }

Просмотреть файл

@@ -690,7 +690,7 @@ func (s SqlChannelStore) InvalidateChannelByName(teamId, name string) {
} }
} }
func (s SqlChannelStore) Get(id string, allowFromCache bool) store.StoreChannel { func (s SqlChannelStore) Get(id string, allowFromCache bool) (*model.Channel, *model.AppError) {
return s.get(id, false, allowFromCache) return s.get(id, false, allowFromCache)
} }
@@ -712,47 +712,45 @@ func (s SqlChannelStore) GetPinnedPosts(channelId string) store.StoreChannel {
}) })
} }
func (s SqlChannelStore) GetFromMaster(id string) store.StoreChannel { func (s SqlChannelStore) GetFromMaster(id string) (*model.Channel, *model.AppError) {
return s.get(id, true, false) return s.get(id, true, false)
} }
func (s SqlChannelStore) get(id string, master bool, allowFromCache bool) store.StoreChannel { func (s SqlChannelStore) get(id string, master bool, allowFromCache bool) (*model.Channel, *model.AppError) {
return store.Do(func(result *store.StoreResult) { var db *gorp.DbMap
var db *gorp.DbMap
if master {
db = s.GetMaster()
} else {
db = s.GetReplica()
}
if allowFromCache { if master {
if cacheItem, ok := channelCache.Get(id); ok { db = s.GetMaster()
if s.metrics != nil { } else {
s.metrics.IncrementMemCacheHitCounter("Channel") db = s.GetReplica()
} }
result.Data = (cacheItem.(*model.Channel)).DeepCopy()
return if allowFromCache {
if cacheItem, ok := channelCache.Get(id); ok {
if s.metrics != nil {
s.metrics.IncrementMemCacheHitCounter("Channel")
} }
ch := cacheItem.(*model.Channel).DeepCopy()
return ch, nil
} }
}
if s.metrics != nil { if s.metrics != nil {
s.metrics.IncrementMemCacheMissCounter("Channel") s.metrics.IncrementMemCacheMissCounter("Channel")
} }
obj, err := db.Get(model.Channel{}, id) obj, err := db.Get(model.Channel{}, id)
if err != nil { if err != nil {
result.Err = model.NewAppError("SqlChannelStore.Get", "store.sql_channel.get.find.app_error", nil, "id="+id+", "+err.Error(), http.StatusInternalServerError) return nil, model.NewAppError("SqlChannelStore.Get", "store.sql_channel.get.find.app_error", nil, "id="+id+", "+err.Error(), http.StatusInternalServerError)
return }
}
if obj == nil { if obj == nil {
result.Err = model.NewAppError("SqlChannelStore.Get", "store.sql_channel.get.existing.app_error", nil, "id="+id, http.StatusNotFound) return nil, model.NewAppError("SqlChannelStore.Get", "store.sql_channel.get.existing.app_error", nil, "id="+id, http.StatusNotFound)
return }
}
result.Data = obj.(*model.Channel) ch := obj.(*model.Channel)
channelCache.AddWithExpiresInSecs(id, obj.(*model.Channel), CHANNEL_CACHE_SEC) channelCache.AddWithExpiresInSecs(id, ch, CHANNEL_CACHE_SEC)
}) return ch, nil
} }
// Delete records the given deleted timestamp to the channel in question. // Delete records the given deleted timestamp to the channel in question.
@@ -1289,14 +1287,12 @@ func (s SqlChannelStore) SaveMember(member *model.ChannelMember) store.StoreChan
defer s.InvalidateAllChannelMembersForUser(member.UserId) defer s.InvalidateAllChannelMembersForUser(member.UserId)
// Grab the channel we are saving this member to // Grab the channel we are saving this member to
cr := <-s.GetFromMaster(member.ChannelId) channel, errCh := s.GetFromMaster(member.ChannelId)
if cr.Err != nil { if errCh != nil {
result.Err = cr.Err result.Err = errCh
return return
} }
channel := cr.Data.(*model.Channel)
transaction, err := s.GetMaster().Begin() transaction, err := s.GetMaster().Begin()
if err != nil { if err != nil {
result.Err = model.NewAppError("SqlChannelStore.SaveMember", "store.sql_channel.save_member.open_transaction.app_error", nil, err.Error(), http.StatusInternalServerError) result.Err = model.NewAppError("SqlChannelStore.SaveMember", "store.sql_channel.save_member.open_transaction.app_error", nil, err.Error(), http.StatusInternalServerError)

Просмотреть файл

@@ -406,9 +406,9 @@ func (s *SqlSupplier) GroupCreateGroupSyncable(ctx context.Context, groupSyncabl
err = s.GetMaster().Insert(groupSyncableToGroupTeam(groupSyncable)) err = s.GetMaster().Insert(groupSyncableToGroupTeam(groupSyncable))
case model.GroupSyncableTypeChannel: case model.GroupSyncableTypeChannel:
channelResult := <-s.Channel().Get(groupSyncable.SyncableId, false) _, errCh := s.Channel().Get(groupSyncable.SyncableId, false)
if channelResult.Err != nil { if errCh != nil {
result.Err = channelResult.Err result.Err = errCh
return result return result
} }

Просмотреть файл

@@ -129,10 +129,10 @@ type ChannelStore interface {
CreateDirectChannel(userId string, otherUserId string) StoreChannel CreateDirectChannel(userId string, otherUserId string) StoreChannel
SaveDirectChannel(channel *model.Channel, member1 *model.ChannelMember, member2 *model.ChannelMember) StoreChannel SaveDirectChannel(channel *model.Channel, member1 *model.ChannelMember, member2 *model.ChannelMember) StoreChannel
Update(channel *model.Channel) StoreChannel Update(channel *model.Channel) StoreChannel
Get(id string, allowFromCache bool) StoreChannel Get(id string, allowFromCache bool) (*model.Channel, *model.AppError)
InvalidateChannel(id string) InvalidateChannel(id string)
InvalidateChannelByName(teamId, name string) InvalidateChannelByName(teamId, name string)
GetFromMaster(id string) StoreChannel GetFromMaster(id string) (*model.Channel, *model.AppError)
Delete(channelId string, time int64) StoreChannel Delete(channelId string, time int64) StoreChannel
Restore(channelId string, time int64) StoreChannel Restore(channelId string, time int64) StoreChannel
SetDeleteAt(channelId string, deleteAt int64, updateAt int64) StoreChannel SetDeleteAt(channelId string, deleteAt int64, updateAt int64) StoreChannel

Просмотреть файл

@@ -356,15 +356,15 @@ func testChannelStoreGet(t *testing.T, ss store.Store, s SqlSupplier) {
o1.Type = model.CHANNEL_OPEN o1.Type = model.CHANNEL_OPEN
store.Must(ss.Channel().Save(&o1, -1)) store.Must(ss.Channel().Save(&o1, -1))
if r1 := <-ss.Channel().Get(o1.Id, false); r1.Err != nil { if c1, err := ss.Channel().Get(o1.Id, false); err != nil {
t.Fatal(r1.Err) t.Fatal(err)
} else { } else {
if r1.Data.(*model.Channel).ToJson() != o1.ToJson() { if c1.ToJson() != o1.ToJson() {
t.Fatal("invalid returned channel") t.Fatal("invalid returned channel")
} }
} }
if err := (<-ss.Channel().Get("", false)).Err; err == nil { if _, err := ss.Channel().Get("", false); err == nil {
t.Fatal("Missing id should have failed") t.Fatal("Missing id should have failed")
} }
@@ -398,18 +398,18 @@ func testChannelStoreGet(t *testing.T, ss store.Store, s SqlSupplier) {
store.Must(ss.Channel().SaveDirectChannel(&o2, &m1, &m2)) store.Must(ss.Channel().SaveDirectChannel(&o2, &m1, &m2))
if r2 := <-ss.Channel().Get(o2.Id, false); r2.Err != nil { if c2, err := ss.Channel().Get(o2.Id, false); err != nil {
t.Fatal(r2.Err) t.Fatal(err)
} else { } else {
if r2.Data.(*model.Channel).ToJson() != o2.ToJson() { if c2.ToJson() != o2.ToJson() {
t.Fatal("invalid returned channel") t.Fatal("invalid returned channel")
} }
} }
if r4 := <-ss.Channel().Get(o2.Id, true); r4.Err != nil { if c4, err := ss.Channel().Get(o2.Id, true); err != nil {
t.Fatal(r4.Err) t.Fatal(err)
} else { } else {
if r4.Data.(*model.Channel).ToJson() != o2.ToJson() { if c4.ToJson() != o2.ToJson() {
t.Fatal("invalid returned channel") t.Fatal("invalid returned channel")
} }
} }
@@ -535,7 +535,7 @@ func testChannelStoreRestore(t *testing.T, ss store.Store) {
t.Fatal(r.Err) t.Fatal(r.Err)
} }
if r := <-ss.Channel().Get(o1.Id, false); r.Data.(*model.Channel).DeleteAt == 0 { if c, _ := ss.Channel().Get(o1.Id, false); c.DeleteAt == 0 {
t.Fatal("should have been deleted") t.Fatal("should have been deleted")
} }
@@ -543,7 +543,7 @@ func testChannelStoreRestore(t *testing.T, ss store.Store) {
t.Fatal(r.Err) t.Fatal(r.Err)
} }
if r := <-ss.Channel().Get(o1.Id, false); r.Data.(*model.Channel).DeleteAt != 0 { if c, _ := ss.Channel().Get(o1.Id, false); c.DeleteAt != 0 {
t.Fatal("should have been restored") t.Fatal("should have been restored")
} }
@@ -594,7 +594,7 @@ func testChannelStoreDelete(t *testing.T, ss store.Store) {
t.Fatal(r.Err) t.Fatal(r.Err)
} }
if r := <-ss.Channel().Get(o1.Id, false); r.Data.(*model.Channel).DeleteAt == 0 { if c, _ := ss.Channel().Get(o1.Id, false); c.DeleteAt == 0 {
t.Fatal("should have been deleted") t.Fatal("should have been deleted")
} }
@@ -826,7 +826,7 @@ func testChannelMemberStore(t *testing.T, ss store.Store) {
c1.Type = model.CHANNEL_OPEN c1.Type = model.CHANNEL_OPEN
c1 = *store.Must(ss.Channel().Save(&c1, -1)).(*model.Channel) c1 = *store.Must(ss.Channel().Save(&c1, -1)).(*model.Channel)
c1t1 := (<-ss.Channel().Get(c1.Id, false)).Data.(*model.Channel) c1t1, _ := ss.Channel().Get(c1.Id, false)
assert.EqualValues(t, 0, c1t1.ExtraUpdateAt, "ExtraUpdateAt should be 0") assert.EqualValues(t, 0, c1t1.ExtraUpdateAt, "ExtraUpdateAt should be 0")
u1 := model.User{} u1 := model.User{}
@@ -853,7 +853,7 @@ func testChannelMemberStore(t *testing.T, ss store.Store) {
o2.NotifyProps = model.GetDefaultChannelNotifyProps() o2.NotifyProps = model.GetDefaultChannelNotifyProps()
store.Must(ss.Channel().SaveMember(&o2)) store.Must(ss.Channel().SaveMember(&o2))
c1t2 := (<-ss.Channel().Get(c1.Id, false)).Data.(*model.Channel) c1t2, _ := ss.Channel().Get(c1.Id, false)
assert.EqualValues(t, 0, c1t2.ExtraUpdateAt, "ExtraUpdateAt should be 0") assert.EqualValues(t, 0, c1t2.ExtraUpdateAt, "ExtraUpdateAt should be 0")
count := (<-ss.Channel().GetMemberCount(o1.ChannelId, true)).Data.(int64) count := (<-ss.Channel().GetMemberCount(o1.ChannelId, true)).Data.(int64)
@@ -886,7 +886,7 @@ func testChannelMemberStore(t *testing.T, ss store.Store) {
t.Fatal("should have removed 1 member") t.Fatal("should have removed 1 member")
} }
c1t3 := (<-ss.Channel().Get(c1.Id, false)).Data.(*model.Channel) c1t3, _ := ss.Channel().Get(c1.Id, false)
assert.EqualValues(t, 0, c1t3.ExtraUpdateAt, "ExtraUpdateAt should be 0") assert.EqualValues(t, 0, c1t3.ExtraUpdateAt, "ExtraUpdateAt should be 0")
member, _ := ss.Channel().GetMember(o1.ChannelId, o1.UserId) member, _ := ss.Channel().GetMember(o1.ChannelId, o1.UserId)
@@ -898,7 +898,7 @@ func testChannelMemberStore(t *testing.T, ss store.Store) {
t.Fatal("Should have been a duplicate") t.Fatal("Should have been a duplicate")
} }
c1t4 := (<-ss.Channel().Get(c1.Id, false)).Data.(*model.Channel) c1t4, _ := ss.Channel().Get(c1.Id, false)
assert.EqualValues(t, 0, c1t4.ExtraUpdateAt, "ExtraUpdateAt should be 0") assert.EqualValues(t, 0, c1t4.ExtraUpdateAt, "ExtraUpdateAt should be 0")
} }
@@ -910,7 +910,7 @@ func testChannelDeleteMemberStore(t *testing.T, ss store.Store) {
c1.Type = model.CHANNEL_OPEN c1.Type = model.CHANNEL_OPEN
c1 = *store.Must(ss.Channel().Save(&c1, -1)).(*model.Channel) c1 = *store.Must(ss.Channel().Save(&c1, -1)).(*model.Channel)
c1t1 := (<-ss.Channel().Get(c1.Id, false)).Data.(*model.Channel) c1t1, _ := ss.Channel().Get(c1.Id, false)
assert.EqualValues(t, 0, c1t1.ExtraUpdateAt, "ExtraUpdateAt should be 0") assert.EqualValues(t, 0, c1t1.ExtraUpdateAt, "ExtraUpdateAt should be 0")
u1 := model.User{} u1 := model.User{}
@@ -937,7 +937,7 @@ func testChannelDeleteMemberStore(t *testing.T, ss store.Store) {
o2.NotifyProps = model.GetDefaultChannelNotifyProps() o2.NotifyProps = model.GetDefaultChannelNotifyProps()
store.Must(ss.Channel().SaveMember(&o2)) store.Must(ss.Channel().SaveMember(&o2))
c1t2 := (<-ss.Channel().Get(c1.Id, false)).Data.(*model.Channel) c1t2, _ := ss.Channel().Get(c1.Id, false)
assert.EqualValues(t, 0, c1t2.ExtraUpdateAt, "ExtraUpdateAt should be 0") assert.EqualValues(t, 0, c1t2.ExtraUpdateAt, "ExtraUpdateAt should be 0")
count := (<-ss.Channel().GetMemberCount(o1.ChannelId, false)).Data.(int64) count := (<-ss.Channel().GetMemberCount(o1.ChannelId, false)).Data.(int64)
@@ -2870,8 +2870,8 @@ func testResetAllChannelSchemes(t *testing.T, ss store.Store) {
res := <-ss.Channel().ResetAllChannelSchemes() res := <-ss.Channel().ResetAllChannelSchemes()
assert.Nil(t, res.Err) assert.Nil(t, res.Err)
c1 = (<-ss.Channel().Get(c1.Id, true)).Data.(*model.Channel) c1, _ = ss.Channel().Get(c1.Id, true)
c2 = (<-ss.Channel().Get(c2.Id, true)).Data.(*model.Channel) c2, _ = ss.Channel().Get(c2.Id, true)
assert.Equal(t, "", *c1.SchemeId) assert.Equal(t, "", *c1.SchemeId)
assert.Equal(t, "", *c2.SchemeId) assert.Equal(t, "", *c2.SchemeId)

Просмотреть файл

@@ -131,19 +131,28 @@ func (_m *ChannelStore) Delete(channelId string, time int64) store.StoreChannel
} }
// Get provides a mock function with given fields: id, allowFromCache // Get provides a mock function with given fields: id, allowFromCache
func (_m *ChannelStore) Get(id string, allowFromCache bool) store.StoreChannel { func (_m *ChannelStore) Get(id string, allowFromCache bool) (*model.Channel, *model.AppError) {
ret := _m.Called(id, allowFromCache) ret := _m.Called(id, allowFromCache)
var r0 store.StoreChannel var r0 *model.Channel
if rf, ok := ret.Get(0).(func(string, bool) store.StoreChannel); ok { if rf, ok := ret.Get(0).(func(string, bool) *model.Channel); ok {
r0 = rf(id, allowFromCache) r0 = rf(id, allowFromCache)
} else { } else {
if ret.Get(0) != nil { if ret.Get(0) != nil {
r0 = ret.Get(0).(store.StoreChannel) r0 = ret.Get(0).(*model.Channel)
} }
} }
return r0 var r1 *model.AppError
if rf, ok := ret.Get(1).(func(string, bool) *model.AppError); ok {
r1 = rf(id, allowFromCache)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)
}
}
return r0, r1
} }
// GetAll provides a mock function with given fields: teamId // GetAll provides a mock function with given fields: teamId
@@ -467,19 +476,28 @@ func (_m *ChannelStore) GetForPost(postId string) store.StoreChannel {
} }
// GetFromMaster provides a mock function with given fields: id // GetFromMaster provides a mock function with given fields: id
func (_m *ChannelStore) GetFromMaster(id string) store.StoreChannel { func (_m *ChannelStore) GetFromMaster(id string) (*model.Channel, *model.AppError) {
ret := _m.Called(id) ret := _m.Called(id)
var r0 store.StoreChannel var r0 *model.Channel
if rf, ok := ret.Get(0).(func(string) store.StoreChannel); ok { if rf, ok := ret.Get(0).(func(string) *model.Channel); ok {
r0 = rf(id) r0 = rf(id)
} else { } else {
if ret.Get(0) != nil { if ret.Get(0) != nil {
r0 = ret.Get(0).(store.StoreChannel) r0 = ret.Get(0).(*model.Channel)
} }
} }
return r0 var r1 *model.AppError
if rf, ok := ret.Get(1).(func(string) *model.AppError); ok {
r1 = rf(id)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)
}
}
return r0, r1
} }
// GetMember provides a mock function with given fields: channelId, userId // GetMember provides a mock function with given fields: channelId, userId

Просмотреть файл

@@ -80,9 +80,8 @@ func testPostStoreSaveChannelMsgCounts(t *testing.T, ss store.Store) {
require.Nil(t, (<-ss.Post().Save(&o1)).Err) require.Nil(t, (<-ss.Post().Save(&o1)).Err)
res = <-ss.Channel().Get(c1.Id, false) c1, err := ss.Channel().Get(c1.Id, false)
require.Nil(t, res.Err) require.Nil(t, err)
c1 = res.Data.(*model.Channel)
assert.Equal(t, int64(1), c1.TotalMsgCount, "Message count should update by 1") assert.Equal(t, int64(1), c1.TotalMsgCount, "Message count should update by 1")
o1.Id = "" o1.Id = ""
@@ -93,9 +92,8 @@ func testPostStoreSaveChannelMsgCounts(t *testing.T, ss store.Store) {
o1.Type = model.POST_REMOVE_FROM_TEAM o1.Type = model.POST_REMOVE_FROM_TEAM
require.Nil(t, (<-ss.Post().Save(&o1)).Err) require.Nil(t, (<-ss.Post().Save(&o1)).Err)
res = <-ss.Channel().Get(c1.Id, false) c1, err = ss.Channel().Get(c1.Id, false)
require.Nil(t, res.Err) require.Nil(t, err)
c1 = res.Data.(*model.Channel)
assert.Equal(t, int64(1), c1.TotalMsgCount, "Message count should not update for team add/removed message") assert.Equal(t, int64(1), c1.TotalMsgCount, "Message count should not update for team add/removed message")
oldLastPostAt := c1.LastPostAt oldLastPostAt := c1.LastPostAt
@@ -107,9 +105,8 @@ func testPostStoreSaveChannelMsgCounts(t *testing.T, ss store.Store) {
o2.CreateAt = int64(7) o2.CreateAt = int64(7)
require.Nil(t, (<-ss.Post().Save(&o2)).Err) require.Nil(t, (<-ss.Post().Save(&o2)).Err)
res = <-ss.Channel().Get(c1.Id, false) c1, err = ss.Channel().Get(c1.Id, false)
require.Nil(t, res.Err) require.Nil(t, err)
c1 = res.Data.(*model.Channel)
assert.Equal(t, oldLastPostAt, c1.LastPostAt, "LastPostAt should not update for old message save") assert.Equal(t, oldLastPostAt, c1.LastPostAt, "LastPostAt should not update for old message save")
} }

Просмотреть файл

@@ -422,9 +422,8 @@ func testSchemeStoreDelete(t *testing.T, ss store.Store) {
sres5 := <-ss.Scheme().Delete(d5.Id) sres5 := <-ss.Scheme().Delete(d5.Id)
assert.Nil(t, sres5.Err) assert.Nil(t, sres5.Err)
cres6 := <-ss.Channel().Get(c5.Id, true) c6, err := ss.Channel().Get(c5.Id, true)
assert.Nil(t, cres6.Err) assert.Nil(t, err)
c6 := cres6.Data.(*model.Channel)
assert.Equal(t, "", *c6.SchemeId) assert.Equal(t, "", *c6.SchemeId)
} }