summaryrefslogtreecommitdiffstats
path: root/store
diff options
context:
space:
mode:
authorGeorge Goldberg <george@gberg.me>2017-07-11 09:09:15 +0100
committerGitHub <noreply@github.com>2017-07-11 09:09:15 +0100
commit83d53ea98cf5486f89bd4280b6b5ef835da4fd22 (patch)
tree1977949d599b3ce3b023f8699854d974be4d92a8 /store
parent0cc60abf6a33dca0d8317481f83d0eb2771f43a1 (diff)
downloadchat-83d53ea98cf5486f89bd4280b6b5ef835da4fd22.tar.gz
chat-83d53ea98cf5486f89bd4280b6b5ef835da4fd22.tar.bz2
chat-83d53ea98cf5486f89bd4280b6b5ef835da4fd22.zip
PLT-6475: Elasticsearch Indexing Worker. (#6879)
Diffstat (limited to 'store')
-rw-r--r--store/sql_post_store.go41
-rw-r--r--store/sql_post_store_test.go69
-rw-r--r--store/store.go1
3 files changed, 111 insertions, 0 deletions
diff --git a/store/sql_post_store.go b/store/sql_post_store.go
index 6db2d5992..16142681c 100644
--- a/store/sql_post_store.go
+++ b/store/sql_post_store.go
@@ -1315,3 +1315,44 @@ func (s SqlPostStore) GetPostsByIds(postIds []string) StoreChannel {
return storeChannel
}
+
+func (s SqlPostStore) GetPostsBatchForIndexing(startTime int64, limit int) StoreChannel {
+ storeChannel := make(StoreChannel, 1)
+
+ go func() {
+ result := StoreResult{}
+
+ var posts []*model.PostForIndexing
+ _, err1 := s.GetSearchReplica().Select(&posts,
+ `(SELECT
+ Posts.*,
+ Channels.TeamId,
+ ParentPosts.CreateAt ParentCreateAt
+ FROM
+ Posts
+ LEFT JOIN
+ Channels
+ ON
+ Posts.ChannelId = Channels.Id
+ LEFT JOIN
+ Posts ParentPosts
+ ON
+ Posts.RootId = ParentPosts.Id
+ WHERE
+ Posts.CreateAt >= :StartTime
+ ORDER BY CreateAt ASC
+ LIMIT :NumPosts)`,
+ map[string]interface{}{"StartTime": startTime, "NumPosts": limit})
+
+ if err1 != nil {
+ result.Err = model.NewLocAppError("SqlPostStore.GetPostContext", "store.sql_post.get_posts_batch_for_indexing.get.app_error", nil, err1.Error())
+ } 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 00d4185b4..27e816996 100644
--- a/store/sql_post_store_test.go
+++ b/store/sql_post_store_test.go
@@ -1592,3 +1592,72 @@ func TestPostStoreGetPostsByIds(t *testing.T) {
t.Fatalf("Expected 2 posts in results. Got %v", len(ro5))
}
}
+
+func TestPostStoreGetPostsBatchForIndexing(t *testing.T) {
+ Setup()
+
+ c1 := &model.Channel{}
+ c1.TeamId = model.NewId()
+ c1.DisplayName = "Channel1"
+ c1.Name = "zz" + model.NewId() + "b"
+ c1.Type = model.CHANNEL_OPEN
+ c1 = (<-store.Channel().Save(c1)).Data.(*model.Channel)
+
+ c2 := &model.Channel{}
+ c2.TeamId = model.NewId()
+ c2.DisplayName = "Channel2"
+ c2.Name = "zz" + model.NewId() + "b"
+ c2.Type = model.CHANNEL_OPEN
+ c2 = (<-store.Channel().Save(c2)).Data.(*model.Channel)
+
+ o1 := &model.Post{}
+ o1.ChannelId = c1.Id
+ o1.UserId = model.NewId()
+ o1.Message = "zz" + model.NewId() + "AAAAAAAAAAA"
+ o1 = (<-store.Post().Save(o1)).Data.(*model.Post)
+
+ o2 := &model.Post{}
+ o2.ChannelId = c2.Id
+ o2.UserId = model.NewId()
+ o2.Message = "zz" + model.NewId() + "CCCCCCCCC"
+ o2 = (<-store.Post().Save(o2)).Data.(*model.Post)
+
+ o3 := &model.Post{}
+ o3.ChannelId = c1.Id
+ o3.UserId = model.NewId()
+ o3.ParentId = o1.Id
+ o3.RootId = o1.Id
+ o3.Message = "zz" + model.NewId() + "QQQQQQQQQQ"
+ o3 = (<-store.Post().Save(o3)).Data.(*model.Post)
+
+ if r := Must(store.Post().GetPostsBatchForIndexing(o1.CreateAt, 100)).([]*model.PostForIndexing); len(r) != 3 {
+ t.Fatalf("Expected 3 posts in results. Got %v", len(r))
+ } else {
+ for _, p := range r {
+ if p.Id == o1.Id {
+ if p.TeamId != c1.TeamId {
+ t.Fatalf("Unexpected team ID")
+ }
+ if p.ParentCreateAt != nil {
+ t.Fatalf("Unexpected parent create at")
+ }
+ } else if p.Id == o2.Id {
+ if p.TeamId != c2.TeamId {
+ t.Fatalf("Unexpected team ID")
+ }
+ if p.ParentCreateAt != nil {
+ t.Fatalf("Unexpected parent create at")
+ }
+ } else if p.Id == o3.Id {
+ if p.TeamId != c1.TeamId {
+ t.Fatalf("Unexpected team ID")
+ }
+ if *p.ParentCreateAt != o1.CreateAt {
+ t.Fatalf("Unexpected parent create at")
+ }
+ } else {
+ t.Fatalf("unexpected post returned")
+ }
+ }
+ }
+}
diff --git a/store/store.go b/store/store.go
index 95496b609..062ed0fbd 100644
--- a/store/store.go
+++ b/store/store.go
@@ -168,6 +168,7 @@ type PostStore interface {
GetPostsCreatedAt(channelId string, time int64) StoreChannel
Overwrite(post *model.Post) StoreChannel
GetPostsByIds(postIds []string) StoreChannel
+ GetPostsBatchForIndexing(startTime int64, limit int) StoreChannel
}
type UserStore interface {