Этот коммит содержится в:
Gabin Aureche
2017-03-13 13:25:08 +01:00
коммит произвёл George Goldberg
родитель 482a0fb5fc
Коммит fe38d6d5bb
38 изменённых файлов: 885 добавлений и 52 удалений

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

@@ -321,6 +321,32 @@ func (s SqlChannelStore) Get(id string, allowFromCache bool) StoreChannel {
return s.get(id, false, allowFromCache)
}
func (s SqlChannelStore) GetPinnedPosts(channelId string) StoreChannel {
storeChannel := make(StoreChannel, 1)
go func() {
result := StoreResult{}
pl := &model.PostList{}
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 {
result.Err = model.NewLocAppError("SqlPostStore.GetPinnedPosts", "store.sql_channel.pinned_posts.app_error", nil, err.Error())
} else {
for _, post := range posts {
pl.AddPost(post)
pl.AddOrder(post.Id)
}
}
result.Data = pl
storeChannel <- result
close(storeChannel)
}()
return storeChannel
}
func (s SqlChannelStore) GetFromMaster(id string) StoreChannel {
return s.get(id, true, false)
}

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

@@ -1493,3 +1493,46 @@ func TestChannelStoreAnalyticsDeletedTypeCount(t *testing.T) {
}
}
}
func TestChannelStoreGetPinnedPosts(t *testing.T) {
Setup()
o1 := Must(store.Channel().Save(&model.Channel{
TeamId: model.NewId(),
DisplayName: "Name",
Name: "a" + model.NewId() + "b",
Type: model.CHANNEL_OPEN,
})).(*model.Channel)
p1 := Must(store.Post().Save(&model.Post{
UserId: model.NewId(),
ChannelId: o1.Id,
Message: "test",
IsPinned: true,
})).(*model.Post)
if r1 := <-store.Channel().GetPinnedPosts(o1.Id); r1.Err != nil {
t.Fatal(r1.Err)
} else if r1.Data.(*model.PostList).Posts[p1.Id] == nil {
t.Fatal("didn't return relevant pinned posts")
}
o2 := Must(store.Channel().Save(&model.Channel{
TeamId: model.NewId(),
DisplayName: "Name",
Name: "a" + model.NewId() + "b",
Type: model.CHANNEL_OPEN,
})).(*model.Channel)
Must(store.Post().Save(&model.Post{
UserId: model.NewId(),
ChannelId: o2.Id,
Message: "test",
}))
if r2 := <-store.Channel().GetPinnedPosts(o2.Id); r2.Err != nil {
t.Fatal(r2.Err)
} else if len(r2.Data.(*model.PostList).Posts) != 0 {
t.Fatal("wasn't supposed to return posts")
}
}

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

@@ -64,6 +64,7 @@ func (s SqlPostStore) CreateIndexesIfNotExists() {
s.CreateIndexIfNotExists("idx_posts_channel_id", "Posts", "ChannelId")
s.CreateIndexIfNotExists("idx_posts_root_id", "Posts", "RootId")
s.CreateIndexIfNotExists("idx_posts_user_id", "Posts", "UserId")
s.CreateIndexIfNotExists("idx_posts_is_pinned", "Posts", "IsPinned")
s.CreateFullTextIndexIfNotExists("idx_posts_message_txt", "Posts", "Message")
s.CreateFullTextIndexIfNotExists("idx_posts_hashtags_txt", "Posts", "Hashtags")

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

@@ -118,6 +118,7 @@ type ChannelStore interface {
InvalidateMemberCount(channelId string)
GetMemberCountFromCache(channelId string) int64
GetMemberCount(channelId string, allowFromCache bool) StoreChannel
GetPinnedPosts(channelId string) StoreChannel
RemoveMember(channelId string, userId string) StoreChannel
PermanentDeleteMembersByUser(userId string) StoreChannel
PermanentDeleteMembersByChannel(channelId string) StoreChannel