From 041d89b85a22b0a498a4176d0d26fd5dc84c33f9 Mon Sep 17 00:00:00 2001 From: JoramWilander Date: Wed, 26 Aug 2015 12:09:01 -0400 Subject: Refactored post handling/updating on both the client and server. --- store/sql_post_store.go | 79 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 56 insertions(+), 23 deletions(-) (limited to 'store/sql_post_store.go') diff --git a/store/sql_post_store.go b/store/sql_post_store.go index 479caf838..4ea28507b 100644 --- a/store/sql_post_store.go +++ b/store/sql_post_store.go @@ -7,7 +7,6 @@ import ( "fmt" "github.com/mattermost/platform/model" "github.com/mattermost/platform/utils" - "strconv" "strings" ) @@ -158,14 +157,6 @@ func (s SqlPostStore) Get(id string) StoreChannel { result.Err = model.NewAppError("SqlPostStore.GetPost", "We couldn't get the post", "id="+id+err.Error()) } - if post.ImgCount > 0 { - post.Filenames = []string{} - for i := 0; int64(i) < post.ImgCount; i++ { - fileUrl := "/api/v1/files/get_image/" + post.ChannelId + "/" + post.Id + "/" + strconv.Itoa(i+1) + ".png" - post.Filenames = append(post.Filenames, fileUrl) - } - } - pl.AddPost(&post) pl.AddOrder(id) @@ -265,25 +256,11 @@ func (s SqlPostStore) GetPosts(channelId string, offset int, limit int) StoreCha list := &model.PostList{Order: make([]string, 0, len(posts))} for _, p := range posts { - if p.ImgCount > 0 { - p.Filenames = []string{} - for i := 0; int64(i) < p.ImgCount; i++ { - fileUrl := "/api/v1/files/get_image/" + p.ChannelId + "/" + p.Id + "/" + strconv.Itoa(i+1) + ".png" - p.Filenames = append(p.Filenames, fileUrl) - } - } list.AddPost(p) list.AddOrder(p.Id) } for _, p := range parents { - if p.ImgCount > 0 { - p.Filenames = []string{} - for i := 0; int64(i) < p.ImgCount; i++ { - fileUrl := "/api/v1/files/get_image/" + p.ChannelId + "/" + p.Id + "/" + strconv.Itoa(i+1) + ".png" - p.Filenames = append(p.Filenames, fileUrl) - } - } list.AddPost(p) } @@ -299,6 +276,62 @@ func (s SqlPostStore) GetPosts(channelId string, offset int, limit int) StoreCha return storeChannel } +func (s SqlPostStore) GetPostsSince(channelId string, time int64) StoreChannel { + storeChannel := make(StoreChannel) + + go func() { + result := StoreResult{} + + var posts []*model.Post + _, err := s.GetReplica().Select(&posts, + `(SELECT + * + FROM + Posts + WHERE + (UpdateAt > :Time + AND ChannelId = :ChannelId) + LIMIT 100) + UNION + (SELECT + * + FROM + Posts + WHERE + Id + IN + (SELECT * FROM (SELECT + RootId + FROM + Posts + WHERE + UpdateAt > :Time + AND ChannelId = :ChannelId + LIMIT 100) temp_tab)) + ORDER BY CreateAt DESC`, + map[string]interface{}{"ChannelId": channelId, "Time": time}) + + if err != nil { + result.Err = model.NewAppError("SqlPostStore.GetPostsSince", "We couldn't get the posts for the channel", "channelId="+channelId+err.Error()) + } else { + + list := &model.PostList{Order: make([]string, 0, len(posts))} + + for _, p := range posts { + list.AddPost(p) + list.AddOrder(p.Id) + } + + result.Data = list + } + + storeChannel <- result + close(storeChannel) + }() + + return storeChannel +} + func (s SqlPostStore) getRootPosts(channelId string, offset int, limit int) StoreChannel { storeChannel := make(StoreChannel) -- cgit v1.2.3-1-g7c22