Refactored post handling/updating on both the client and server.

Этот коммит содержится в:
JoramWilander
2015-08-26 12:09:01 -04:00
родитель 8356e25f80
Коммит 041d89b85a
28 изменённых файлов: 1643 добавлений и 902 удалений

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

@@ -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)

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

@@ -383,6 +383,91 @@ func TestPostStoreGetPostsWtihDetails(t *testing.T) {
}
}
func TestPostStoreGetPostsSince(t *testing.T) {
Setup()
o0 := &model.Post{}
o0.ChannelId = model.NewId()
o0.UserId = model.NewId()
o0.Message = "a" + model.NewId() + "b"
o0 = (<-store.Post().Save(o0)).Data.(*model.Post)
time.Sleep(2 * time.Millisecond)
o1 := &model.Post{}
o1.ChannelId = model.NewId()
o1.UserId = model.NewId()
o1.Message = "a" + model.NewId() + "b"
o1 = (<-store.Post().Save(o1)).Data.(*model.Post)
time.Sleep(2 * time.Millisecond)
o2 := &model.Post{}
o2.ChannelId = o1.ChannelId
o2.UserId = model.NewId()
o2.Message = "a" + model.NewId() + "b"
o2.ParentId = o1.Id
o2.RootId = o1.Id
o2 = (<-store.Post().Save(o2)).Data.(*model.Post)
time.Sleep(2 * time.Millisecond)
o2a := &model.Post{}
o2a.ChannelId = o1.ChannelId
o2a.UserId = model.NewId()
o2a.Message = "a" + model.NewId() + "b"
o2a.ParentId = o1.Id
o2a.RootId = o1.Id
o2a = (<-store.Post().Save(o2a)).Data.(*model.Post)
time.Sleep(2 * time.Millisecond)
o3 := &model.Post{}
o3.ChannelId = o1.ChannelId
o3.UserId = model.NewId()
o3.Message = "a" + model.NewId() + "b"
o3.ParentId = o1.Id
o3.RootId = o1.Id
o3 = (<-store.Post().Save(o3)).Data.(*model.Post)
time.Sleep(2 * time.Millisecond)
o4 := &model.Post{}
o4.ChannelId = o1.ChannelId
o4.UserId = model.NewId()
o4.Message = "a" + model.NewId() + "b"
o4 = (<-store.Post().Save(o4)).Data.(*model.Post)
time.Sleep(2 * time.Millisecond)
o5 := &model.Post{}
o5.ChannelId = o1.ChannelId
o5.UserId = model.NewId()
o5.Message = "a" + model.NewId() + "b"
o5.ParentId = o4.Id
o5.RootId = o4.Id
o5 = (<-store.Post().Save(o5)).Data.(*model.Post)
r1 := (<-store.Post().GetPostsSince(o1.ChannelId, o1.CreateAt)).Data.(*model.PostList)
if r1.Order[0] != o5.Id {
t.Fatal("invalid order")
}
if r1.Order[1] != o4.Id {
t.Fatal("invalid order")
}
if r1.Order[2] != o3.Id {
t.Fatal("invalid order")
}
if r1.Order[3] != o2a.Id {
t.Fatal("invalid order")
}
if len(r1.Posts) != 6 {
t.Fatal("wrong size")
}
if r1.Posts[o1.Id].Message != o1.Message {
t.Fatal("Missing parent")
}
}
func TestPostStoreSearch(t *testing.T) {
Setup()

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

@@ -75,6 +75,7 @@ type PostStore interface {
Get(id string) StoreChannel
Delete(postId string, time int64) StoreChannel
GetPosts(channelId string, offset int, limit int) StoreChannel
GetPostsSince(channelId string, time int64) StoreChannel
GetEtag(channelId string) StoreChannel
Search(teamId string, userId string, terms string, isHashtagSearch bool) StoreChannel
}