summaryrefslogtreecommitdiffstats
path: root/store/sqlstore
diff options
context:
space:
mode:
authorMartin Kraft <martinkraft@gmail.com>2018-05-02 07:45:20 -0400
committerMartin Kraft <martinkraft@gmail.com>2018-05-02 07:45:20 -0400
commit7d5e85e4136b0e2e6cf902c48b186d99f0698d13 (patch)
tree84f7256de28eed0fd932f43532c218b385e09642 /store/sqlstore
parentf4dcb4edf2aafca85c9af631131a77888da24bc7 (diff)
parent529807c1ba0c6b5e697d95d35b46865e22b0e62a (diff)
downloadchat-7d5e85e4136b0e2e6cf902c48b186d99f0698d13.tar.gz
chat-7d5e85e4136b0e2e6cf902c48b186d99f0698d13.tar.bz2
chat-7d5e85e4136b0e2e6cf902c48b186d99f0698d13.zip
Merge remote-tracking branch 'origin/master' into advanced-permissions-phase-2
Diffstat (limited to 'store/sqlstore')
-rw-r--r--store/sqlstore/post_store.go85
1 files changed, 23 insertions, 62 deletions
diff --git a/store/sqlstore/post_store.go b/store/sqlstore/post_store.go
index 75154791c..e4872fe11 100644
--- a/store/sqlstore/post_store.go
+++ b/store/sqlstore/post_store.go
@@ -715,70 +715,31 @@ func (s *SqlPostStore) getRootPosts(channelId string, offset int, limit int) sto
func (s *SqlPostStore) getParentsPosts(channelId string, offset int, limit int) store.StoreChannel {
return store.Do(func(result *store.StoreResult) {
var posts []*model.Post
- _, err := s.GetReplica().Select(&posts, `
- SELECT
- *
+ _, err := s.GetReplica().Select(&posts,
+ `SELECT
+ q2.*
FROM
- Posts
+ Posts q2
+ INNER JOIN
+ (SELECT DISTINCT
+ q3.RootId
+ FROM
+ (SELECT
+ RootId
+ FROM
+ Posts
+ WHERE
+ ChannelId = :ChannelId1
+ AND DeleteAt = 0
+ ORDER BY CreateAt DESC
+ LIMIT :Limit OFFSET :Offset) q3
+ WHERE q3.RootId != '') q1
+ ON q1.RootId = q2.Id OR q1.RootId = q2.RootId
WHERE
- Id IN (SELECT * FROM (
- -- The root post of any replies in the window
- (SELECT * FROM (
- SELECT
- CASE RootId
- WHEN '' THEN NULL
- ELSE RootId
- END
- FROM
- Posts
- WHERE
- ChannelId = :ChannelId1
- AND DeleteAt = 0
- ORDER BY
- CreateAt DESC
- LIMIT :Limit1 OFFSET :Offset1
- ) x )
-
- UNION
-
- -- The reply posts to all threads intersecting with the window, including replies
- -- to root posts in the window itself.
- (
- SELECT
- Id
- FROM
- Posts
- WHERE RootId IN (SELECT * FROM (
- SELECT
- CASE RootId
- -- If there is no RootId, return the post id itself to be considered
- -- as a root post.
- WHEN '' THEN Id
- -- If there is a RootId, this post isn't a root post and return its
- -- root to be considered as a root post.
- ELSE RootId
- END
- FROM
- Posts
- WHERE
- ChannelId = :ChannelId2
- AND DeleteAt = 0
- ORDER BY
- CreateAt DESC
- LIMIT :Limit2 OFFSET :Offset2
- ) x )
- )
- ) x )
- AND
- DeleteAt = 0
- `, map[string]interface{}{
- "ChannelId1": channelId,
- "ChannelId2": channelId,
- "Offset1": offset,
- "Offset2": offset,
- "Limit1": limit,
- "Limit2": limit,
- })
+ ChannelId = :ChannelId2
+ AND DeleteAt = 0
+ ORDER BY CreateAt`,
+ map[string]interface{}{"ChannelId1": channelId, "Offset": offset, "Limit": limit, "ChannelId2": channelId})
if err != nil {
result.Err = model.NewAppError("SqlPostStore.GetLinearPosts", "store.sql_post.get_parents_posts.app_error", nil, "channelId="+channelId+" err="+err.Error(), http.StatusInternalServerError)
} else {