summaryrefslogtreecommitdiffstats
path: root/store
diff options
context:
space:
mode:
authorGeorge Goldberg <george@gberg.me>2017-05-18 16:26:52 +0100
committerHarrison Healey <harrisonmhealey@gmail.com>2017-05-18 11:26:52 -0400
commit0db5e3922fd5045b3f7f518ad65e42138f0325c4 (patch)
treee225a7191de7915a3da3716601ddb415c4f26979 /store
parent2bbedd9def2a782f370fb5280994ea0ecbf8a7c7 (diff)
downloadchat-0db5e3922fd5045b3f7f518ad65e42138f0325c4.tar.gz
chat-0db5e3922fd5045b3f7f518ad65e42138f0325c4.tar.bz2
chat-0db5e3922fd5045b3f7f518ad65e42138f0325c4.zip
PLT-6472: Basic Elastic Search implementation. (#6382)
* PLT-6472: Basic Elastic Search implementation. This currently supports indexing of posts at create/update/delete time. It does not support batch indexing or reindexing, and does not support any entities other than posts yet. The purpose is to more-or-less replicate the existing full-text search feature but with some of the immediate benefits of using elastic search. * Alter settings for AWS compatability. * Remove unneeded i18n strings.
Diffstat (limited to 'store')
-rw-r--r--store/sql_post_store.go27
-rw-r--r--store/sql_post_store_test.go42
-rw-r--r--store/store.go1
3 files changed, 70 insertions, 0 deletions
diff --git a/store/sql_post_store.go b/store/sql_post_store.go
index b2211a180..834e488a8 100644
--- a/store/sql_post_store.go
+++ b/store/sql_post_store.go
@@ -1287,3 +1287,30 @@ func (s SqlPostStore) GetPostsCreatedAt(channelId string, time int64) StoreChann
return storeChannel
}
+
+func (s SqlPostStore) GetPostsByIds(postIds []string) StoreChannel {
+ storeChannel := make(StoreChannel, 1)
+
+ go func() {
+ result := StoreResult{}
+
+ inClause := `'` + strings.Join(postIds, `', '`) + `'`
+
+ query := `SELECT * FROM Posts WHERE Id in (` + inClause + `) and DeleteAt = 0 ORDER BY CreateAt DESC`
+
+ var posts []*model.Post
+ _, err := s.GetReplica().Select(&posts, query, map[string]interface{}{})
+
+ if err != nil {
+ l4g.Error(err)
+ result.Err = model.NewAppError("SqlPostStore.GetPostsCreatedAt", "store.sql_post.get_posts_by_ids.app_error", nil, "", http.StatusInternalServerError)
+ } else {
+ result.Data = posts
+ }
+
+ storeChannel <- result
+ close(storeChannel)
+ }()
+
+ return storeChannel
+}
diff --git a/store/sql_post_store_test.go b/store/sql_post_store_test.go
index b69f0f636..f8fd653af 100644
--- a/store/sql_post_store_test.go
+++ b/store/sql_post_store_test.go
@@ -1550,3 +1550,45 @@ func TestPostStoreOverwrite(t *testing.T) {
t.Fatal("Failed to set FileIds")
}
}
+
+func TestPostStoreGetPostsByIds(t *testing.T) {
+ Setup()
+
+ o1 := &model.Post{}
+ o1.ChannelId = model.NewId()
+ o1.UserId = model.NewId()
+ o1.Message = "a" + model.NewId() + "AAAAAAAAAAA"
+ o1 = (<-store.Post().Save(o1)).Data.(*model.Post)
+
+ o2 := &model.Post{}
+ o2.ChannelId = o1.ChannelId
+ o2.UserId = model.NewId()
+ o2.Message = "a" + model.NewId() + "CCCCCCCCC"
+ o2 = (<-store.Post().Save(o2)).Data.(*model.Post)
+
+ o3 := &model.Post{}
+ o3.ChannelId = o1.ChannelId
+ o3.UserId = model.NewId()
+ o3.Message = "a" + model.NewId() + "QQQQQQQQQQ"
+ o3 = (<-store.Post().Save(o3)).Data.(*model.Post)
+
+ ro1 := (<-store.Post().Get(o1.Id)).Data.(*model.PostList).Posts[o1.Id]
+ ro2 := (<-store.Post().Get(o2.Id)).Data.(*model.PostList).Posts[o2.Id]
+ ro3 := (<-store.Post().Get(o3.Id)).Data.(*model.PostList).Posts[o3.Id]
+
+ postIds := []string{
+ ro1.Id,
+ ro2.Id,
+ ro3.Id,
+ }
+
+ if ro4 := Must(store.Post().GetPostsByIds(postIds)).([]*model.Post); len(ro4) != 3 {
+ t.Fatalf("Expected 3 posts in results. Got %v", len(ro4))
+ }
+
+ Must(store.Post().Delete(ro1.Id, model.GetMillis()))
+
+ if ro5 := Must(store.Post().GetPostsByIds(postIds)).([]*model.Post); len(ro5) != 2 {
+ t.Fatalf("Expected 2 posts in results. Got %v", len(ro5))
+ }
+}
diff --git a/store/store.go b/store/store.go
index 9916bfcd7..acbeafdd6 100644
--- a/store/store.go
+++ b/store/store.go
@@ -165,6 +165,7 @@ type PostStore interface {
InvalidateLastPostTimeCache(channelId string)
GetPostsCreatedAt(channelId string, time int64) StoreChannel
Overwrite(post *model.Post) StoreChannel
+ GetPostsByIds(postIds []string) StoreChannel
}
type UserStore interface {