Migrate Reactions store to Sync by default (#10737)
* Migrate Reactions store to Sync by default * Fixing tests * Fixing tests * Fixing govet * fixing tests * Addressing PR review comments
Этот коммит содержится в:
коммит произвёл
Christopher Speller
родитель
584ec68755
Коммит
9a9d5d4081
@@ -292,8 +292,8 @@ func (a *App) deleteEmojiImage(id string) {
|
||||
}
|
||||
|
||||
func (a *App) deleteReactionsForEmoji(emojiName string) {
|
||||
if result := <-a.Srv.Store.Reaction().DeleteAllWithEmojiName(emojiName); result.Err != nil {
|
||||
if err := a.Srv.Store.Reaction().DeleteAllWithEmojiName(emojiName); err != nil {
|
||||
mlog.Warn(fmt.Sprintf("Unable to delete reactions when deleting emoji with emoji name %v", emojiName))
|
||||
mlog.Warn(fmt.Sprint(result.Err))
|
||||
mlog.Warn(fmt.Sprint(err))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -407,15 +407,14 @@ func (a *App) buildPostReplies(postId string) (*[]ReplyImportData, *model.AppErr
|
||||
func (a *App) BuildPostReactions(postId string) (*[]ReactionImportData, *model.AppError) {
|
||||
var reactionsOfPost []ReactionImportData
|
||||
|
||||
result := <-a.Srv.Store.Reaction().GetForPost(postId, true)
|
||||
if result.Err != nil {
|
||||
return nil, result.Err
|
||||
reactions, err := a.Srv.Store.Reaction().GetForPost(postId, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
reactions := result.Data.([]*model.Reaction)
|
||||
|
||||
for _, reaction := range reactions {
|
||||
user, err := a.Srv.Store.User().Get(reaction.UserId)
|
||||
var user *model.User
|
||||
user, err = a.Srv.Store.User().Get(reaction.UserId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -843,8 +843,8 @@ func (a *App) ImportReaction(data *ReactionImportData, post *model.Post, dryRun
|
||||
EmojiName: *data.EmojiName,
|
||||
CreateAt: *data.CreateAt,
|
||||
}
|
||||
if result := <-a.Srv.Store.Reaction().Save(reaction); result.Err != nil {
|
||||
return result.Err
|
||||
if _, err := a.Srv.Store.Reaction().Save(reaction); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -2089,9 +2089,9 @@ func TestImportImportPost(t *testing.T) {
|
||||
t.Fatal("Post properties not as expected")
|
||||
}
|
||||
|
||||
if result := <-th.App.Srv.Store.Reaction().GetForPost(post.Id, false); result.Err != nil {
|
||||
if reactions, err := th.App.Srv.Store.Reaction().GetForPost(post.Id, false); err != nil {
|
||||
t.Fatal("Can't get reaction")
|
||||
} else if len(result.Data.([]*model.Reaction)) != 1 {
|
||||
} else if len(reactions) != 1 {
|
||||
t.Fatal("Invalid number of reactions")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,8 @@ func (a *App) SaveReactionForPost(reaction *model.Reaction) (*model.Reaction, *m
|
||||
}
|
||||
|
||||
if a.License() != nil && *a.Config().TeamSettings.ExperimentalTownSquareIsReadOnly && channel.Name == model.DEFAULT_CHANNEL {
|
||||
user, err := a.GetUser(reaction.UserId)
|
||||
var user *model.User
|
||||
user, err = a.GetUser(reaction.UserId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -35,13 +36,11 @@ func (a *App) SaveReactionForPost(reaction *model.Reaction) (*model.Reaction, *m
|
||||
}
|
||||
}
|
||||
|
||||
result := <-a.Srv.Store.Reaction().Save(reaction)
|
||||
if result.Err != nil {
|
||||
return nil, result.Err
|
||||
reaction, err = a.Srv.Store.Reaction().Save(reaction)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
reaction = result.Data.(*model.Reaction)
|
||||
|
||||
// The post is always modified since the UpdateAt always changes
|
||||
a.InvalidateCacheForChannelPosts(post.ChannelId)
|
||||
|
||||
@@ -53,22 +52,17 @@ func (a *App) SaveReactionForPost(reaction *model.Reaction) (*model.Reaction, *m
|
||||
}
|
||||
|
||||
func (a *App) GetReactionsForPost(postId string) ([]*model.Reaction, *model.AppError) {
|
||||
result := <-a.Srv.Store.Reaction().GetForPost(postId, true)
|
||||
if result.Err != nil {
|
||||
return nil, result.Err
|
||||
}
|
||||
return result.Data.([]*model.Reaction), nil
|
||||
return a.Srv.Store.Reaction().GetForPost(postId, true)
|
||||
}
|
||||
|
||||
func (a *App) GetBulkReactionsForPosts(postIds []string) (map[string][]*model.Reaction, *model.AppError) {
|
||||
reactions := make(map[string][]*model.Reaction)
|
||||
|
||||
result := <-a.Srv.Store.Reaction().BulkGetForPosts(postIds)
|
||||
if result.Err != nil {
|
||||
return nil, result.Err
|
||||
allReactions, err := a.Srv.Store.Reaction().BulkGetForPosts(postIds)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
allReactions := result.Data.([]*model.Reaction)
|
||||
for _, reaction := range allReactions {
|
||||
reactionsForPost := reactions[reaction.PostId]
|
||||
reactionsForPost = append(reactionsForPost, reaction)
|
||||
@@ -120,8 +114,8 @@ func (a *App) DeleteReactionForPost(reaction *model.Reaction) *model.AppError {
|
||||
hasReactions = false
|
||||
}
|
||||
|
||||
if result := <-a.Srv.Store.Reaction().Delete(reaction); result.Err != nil {
|
||||
return result.Err
|
||||
if _, err := a.Srv.Store.Reaction().Delete(reaction); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// The post is always modified since the UpdateAt always changes
|
||||
|
||||
Ссылка в новой задаче
Block a user