mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
PLT-7822: Fix search order for SQL search backend. (#7704)
This commit is contained in:
committed by
Harrison Healey
parent
2a2af0e390
commit
61b023f5df
@@ -645,6 +645,8 @@ func (a *App) SearchPostsInTeam(terms string, userId string, teamId string, isOr
|
||||
}
|
||||
}
|
||||
|
||||
posts.SortByCreateAt()
|
||||
|
||||
return posts, nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ package model
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"sort"
|
||||
)
|
||||
|
||||
type PostList struct {
|
||||
@@ -82,6 +83,12 @@ func (o *PostList) Extend(other *PostList) {
|
||||
}
|
||||
}
|
||||
|
||||
func (o *PostList) SortByCreateAt() {
|
||||
sort.Slice(o.Order, func(i, j int) bool {
|
||||
return o.Posts[o.Order[i]].CreateAt > o.Posts[o.Order[j]].CreateAt
|
||||
})
|
||||
}
|
||||
|
||||
func (o *PostList) Etag() string {
|
||||
|
||||
id := "0"
|
||||
|
||||
@@ -6,6 +6,8 @@ package model
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestPostListJson(t *testing.T) {
|
||||
@@ -68,3 +70,23 @@ func TestPostListExtend(t *testing.T) {
|
||||
t.Fatal("extending l2 again changed l2")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPostListSortByCreateAt(t *testing.T) {
|
||||
pl := PostList{}
|
||||
p1 := &Post{Id: NewId(), Message: NewId(), CreateAt: 2}
|
||||
pl.AddPost(p1)
|
||||
p2 := &Post{Id: NewId(), Message: NewId(), CreateAt: 1}
|
||||
pl.AddPost(p2)
|
||||
p3 := &Post{Id: NewId(), Message: NewId(), CreateAt: 3}
|
||||
pl.AddPost(p3)
|
||||
|
||||
pl.AddOrder(p1.Id)
|
||||
pl.AddOrder(p2.Id)
|
||||
pl.AddOrder(p3.Id)
|
||||
|
||||
pl.SortByCreateAt()
|
||||
|
||||
assert.EqualValues(t, pl.Order[0], p3.Id)
|
||||
assert.EqualValues(t, pl.Order[1], p1.Id)
|
||||
assert.EqualValues(t, pl.Order[2], p2.Id)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user