[MM-16339] Migrate "Channel.GetPinnedPosts" to Sync by default (#11280)
* Migrate "Channel.GetPinnedPosts" to Sync by default * remove unnecessary error checking * fixing shadowed err variable * fixing shadowed err variable * fixing gofmt
Этот коммит содержится в:
коммит произвёл
Jesús Espino
родитель
86e0c8567c
Коммит
73e47567bc
@@ -2008,11 +2008,7 @@ func (a *App) postChannelMoveMessage(user *model.User, channel *model.Channel, p
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetPinnedPosts(channelId string) (*model.PostList, *model.AppError) {
|
func (a *App) GetPinnedPosts(channelId string) (*model.PostList, *model.AppError) {
|
||||||
result := <-a.Srv.Store.Channel().GetPinnedPosts(channelId)
|
return a.Srv.Store.Channel().GetPinnedPosts(channelId)
|
||||||
if result.Err != nil {
|
|
||||||
return nil, result.Err
|
|
||||||
}
|
|
||||||
return result.Data.(*model.PostList), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) ToggleMuteChannel(channelId string, userId string) *model.ChannelMember {
|
func (a *App) ToggleMuteChannel(channelId string, userId string) *model.ChannelMember {
|
||||||
|
|||||||
@@ -710,22 +710,18 @@ func (s SqlChannelStore) Get(id string, allowFromCache bool) (*model.Channel, *m
|
|||||||
return s.get(id, false, allowFromCache)
|
return s.get(id, false, allowFromCache)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s SqlChannelStore) GetPinnedPosts(channelId string) store.StoreChannel {
|
func (s SqlChannelStore) GetPinnedPosts(channelId string) (*model.PostList, *model.AppError) {
|
||||||
return store.Do(func(result *store.StoreResult) {
|
pl := model.NewPostList()
|
||||||
pl := model.NewPostList()
|
|
||||||
|
|
||||||
var posts []*model.Post
|
var posts []*model.Post
|
||||||
if _, err := s.GetReplica().Select(&posts, "SELECT * FROM Posts WHERE IsPinned = true AND ChannelId = :ChannelId AND DeleteAt = 0 ORDER BY CreateAt ASC", map[string]interface{}{"ChannelId": channelId}); err != nil {
|
if _, err := s.GetReplica().Select(&posts, "SELECT * FROM Posts WHERE IsPinned = true AND ChannelId = :ChannelId AND DeleteAt = 0 ORDER BY CreateAt ASC", map[string]interface{}{"ChannelId": channelId}); err != nil {
|
||||||
result.Err = model.NewAppError("SqlPostStore.GetPinnedPosts", "store.sql_channel.pinned_posts.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return nil, model.NewAppError("SqlPostStore.GetPinnedPosts", "store.sql_channel.pinned_posts.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
} else {
|
}
|
||||||
for _, post := range posts {
|
for _, post := range posts {
|
||||||
pl.AddPost(post)
|
pl.AddPost(post)
|
||||||
pl.AddOrder(post.Id)
|
pl.AddOrder(post.Id)
|
||||||
}
|
}
|
||||||
}
|
return pl, nil
|
||||||
|
|
||||||
result.Data = pl
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s SqlChannelStore) GetFromMaster(id string) (*model.Channel, *model.AppError) {
|
func (s SqlChannelStore) GetFromMaster(id string) (*model.Channel, *model.AppError) {
|
||||||
|
|||||||
@@ -172,7 +172,7 @@ type ChannelStore interface {
|
|||||||
InvalidateMemberCount(channelId string)
|
InvalidateMemberCount(channelId string)
|
||||||
GetMemberCountFromCache(channelId string) int64
|
GetMemberCountFromCache(channelId string) int64
|
||||||
GetMemberCount(channelId string, allowFromCache bool) (int64, *model.AppError)
|
GetMemberCount(channelId string, allowFromCache bool) (int64, *model.AppError)
|
||||||
GetPinnedPosts(channelId string) StoreChannel
|
GetPinnedPosts(channelId string) (*model.PostList, *model.AppError)
|
||||||
RemoveMember(channelId string, userId string) *model.AppError
|
RemoveMember(channelId string, userId string) *model.AppError
|
||||||
PermanentDeleteMembersByUser(userId string) *model.AppError
|
PermanentDeleteMembersByUser(userId string) *model.AppError
|
||||||
PermanentDeleteMembersByChannel(channelId string) *model.AppError
|
PermanentDeleteMembersByChannel(channelId string) *model.AppError
|
||||||
|
|||||||
@@ -2974,9 +2974,9 @@ func testChannelStoreGetPinnedPosts(t *testing.T, ss store.Store) {
|
|||||||
IsPinned: true,
|
IsPinned: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
if r1 := <-ss.Channel().GetPinnedPosts(o1.Id); r1.Err != nil {
|
if pl, errGet := ss.Channel().GetPinnedPosts(o1.Id); errGet != nil {
|
||||||
t.Fatal(r1.Err)
|
t.Fatal(errGet)
|
||||||
} else if r1.Data.(*model.PostList).Posts[p1.Id] == nil {
|
} else if pl.Posts[p1.Id] == nil {
|
||||||
t.Fatal("didn't return relevant pinned posts")
|
t.Fatal("didn't return relevant pinned posts")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2997,9 +2997,9 @@ func testChannelStoreGetPinnedPosts(t *testing.T, ss store.Store) {
|
|||||||
})
|
})
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
if r2 := <-ss.Channel().GetPinnedPosts(o2.Id); r2.Err != nil {
|
if pl, errGet := ss.Channel().GetPinnedPosts(o2.Id); errGet != nil {
|
||||||
t.Fatal(r2.Err)
|
t.Fatal(errGet)
|
||||||
} else if len(r2.Data.(*model.PostList).Posts) != 0 {
|
} else if len(pl.Posts) != 0 {
|
||||||
t.Fatal("wasn't supposed to return posts")
|
t.Fatal("wasn't supposed to return posts")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -939,19 +939,28 @@ func (_m *ChannelStore) GetMoreChannels(teamId string, userId string, offset int
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetPinnedPosts provides a mock function with given fields: channelId
|
// GetPinnedPosts provides a mock function with given fields: channelId
|
||||||
func (_m *ChannelStore) GetPinnedPosts(channelId string) store.StoreChannel {
|
func (_m *ChannelStore) GetPinnedPosts(channelId string) (*model.PostList, *model.AppError) {
|
||||||
ret := _m.Called(channelId)
|
ret := _m.Called(channelId)
|
||||||
|
|
||||||
var r0 store.StoreChannel
|
var r0 *model.PostList
|
||||||
if rf, ok := ret.Get(0).(func(string) store.StoreChannel); ok {
|
if rf, ok := ret.Get(0).(func(string) *model.PostList); ok {
|
||||||
r0 = rf(channelId)
|
r0 = rf(channelId)
|
||||||
} else {
|
} else {
|
||||||
if ret.Get(0) != nil {
|
if ret.Get(0) != nil {
|
||||||
r0 = ret.Get(0).(store.StoreChannel)
|
r0 = ret.Get(0).(*model.PostList)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return r0
|
var r1 *model.AppError
|
||||||
|
if rf, ok := ret.Get(1).(func(string) *model.AppError); ok {
|
||||||
|
r1 = rf(channelId)
|
||||||
|
} else {
|
||||||
|
if ret.Get(1) != nil {
|
||||||
|
r1 = ret.Get(1).(*model.AppError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return r0, r1
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPublicChannelsByIdsForTeam provides a mock function with given fields: teamId, channelIds
|
// GetPublicChannelsByIdsForTeam provides a mock function with given fields: teamId, channelIds
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user