MM-31710 Server/API: change total_unread_replies to total_unread_threads (#16663)

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Eli Yukelzon
2021-01-19 13:33:57 +02:00
коммит произвёл GitHub
родитель 90952a1bd5
Коммит 911d1f070e
3 изменённых файлов: 103 добавлений и 54 удалений

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

@@ -120,19 +120,22 @@ func (s *SqlThreadStore) GetThreadsForUser(userId, teamId string, opts model.Get
model.Post
}
unreadRepliesQuery := "SELECT COUNT(Posts.Id) From Posts Where Posts.RootId=ThreadMemberships.PostId AND Posts.UpdateAt >= ThreadMemberships.LastViewed AND Posts.DeleteAt=0"
unreadRepliesQuery := "SELECT COUNT(Posts.Id) From Posts Where Posts.RootId=ThreadMemberships.PostId AND Posts.UpdateAt >= ThreadMemberships.LastViewed"
fetchConditions := sq.And{
sq.Or{sq.Eq{"Channels.TeamId": teamId}, sq.Eq{"Channels.TeamId": ""}},
sq.Eq{"ThreadMemberships.UserId": userId},
sq.Eq{"ThreadMemberships.Following": true},
}
if !opts.Deleted {
fetchConditions = sq.And{fetchConditions, sq.Eq{"Posts.DeleteAt": 0}}
}
pageSize := uint64(30)
if opts.PageSize == 0 {
if opts.PageSize != 0 {
pageSize = opts.PageSize
}
totalUnreadRepliesChan := make(chan store.StoreResult, 1)
totalUnreadThreadsChan := make(chan store.StoreResult, 1)
totalCountChan := make(chan store.StoreResult, 1)
totalUnreadMentionsChan := make(chan store.StoreResult, 1)
threadsChan := make(chan store.StoreResult, 1)
@@ -140,20 +143,21 @@ func (s *SqlThreadStore) GetThreadsForUser(userId, teamId string, opts model.Get
repliesQuery, repliesQueryArgs, _ := s.getQueryBuilder().
Select("COUNT(Posts.Id)").
From("Posts").
LeftJoin("ThreadMemberships ON Posts.RootId = ThreadMemberships.PostId").
LeftJoin("ThreadMemberships ON Posts.Id = ThreadMemberships.PostId").
LeftJoin("Channels ON Posts.ChannelId = Channels.Id").
Where(fetchConditions).
Where("Posts.UpdateAt >= ThreadMemberships.LastViewed").ToSql()
totalUnreadReplies, err := s.GetMaster().SelectInt(repliesQuery, repliesQueryArgs...)
totalUnreadRepliesChan <- store.StoreResult{Data: totalUnreadReplies, NErr: errors.Wrapf(err, "failed to get count replies on threads for user id=%s", userId)}
close(totalUnreadRepliesChan)
totalUnreadThreads, err := s.GetMaster().SelectInt(repliesQuery, repliesQueryArgs...)
totalUnreadThreadsChan <- store.StoreResult{Data: totalUnreadThreads, NErr: errors.Wrapf(err, "failed to get count unread on threads for user id=%s", userId)}
close(totalUnreadThreadsChan)
}()
go func() {
threadsQuery, threadsQueryArgs, _ := s.getQueryBuilder().
Select("COUNT(ThreadMemberships.PostId)").
LeftJoin("Threads ON Threads.PostId = ThreadMemberships.PostId").
LeftJoin("Channels ON Threads.ChannelId = Channels.Id").
LeftJoin("Posts ON Posts.Id = ThreadMemberships.PostId").
From("ThreadMemberships").
Where(fetchConditions).ToSql()
@@ -166,6 +170,7 @@ func (s *SqlThreadStore) GetThreadsForUser(userId, teamId string, opts model.Get
Select("COALESCE(SUM(ThreadMemberships.UnreadMentions),0)").
From("ThreadMemberships").
LeftJoin("Threads ON Threads.PostId = ThreadMemberships.PostId").
LeftJoin("Posts ON Posts.Id = ThreadMemberships.PostId").
LeftJoin("Channels ON Threads.ChannelId = Channels.Id").
Where(fetchConditions).ToSql()
totalUnreadMentions, err := s.GetMaster().SelectInt(mentionsQuery, mentionsQueryArgs...)
@@ -174,9 +179,6 @@ func (s *SqlThreadStore) GetThreadsForUser(userId, teamId string, opts model.Get
}()
go func() {
newFetchConditions := fetchConditions
if !opts.Deleted {
newFetchConditions = sq.And{fetchConditions, sq.Eq{"Posts.DeleteAt": 0}}
}
if opts.Since > 0 {
newFetchConditions = sq.And{newFetchConditions, sq.GtOrEq{"Threads.LastReplyAt": opts.Since}}
}
@@ -216,11 +218,11 @@ func (s *SqlThreadStore) GetThreadsForUser(userId, teamId string, opts model.Get
}
totalCount := totalCountResult.Data.(int64)
totalUnreadRepliesResult := <-totalUnreadRepliesChan
if totalUnreadRepliesResult.NErr != nil {
return nil, totalUnreadRepliesResult.NErr
totalUnreadThreadsResult := <-totalUnreadThreadsChan
if totalUnreadThreadsResult.NErr != nil {
return nil, totalUnreadThreadsResult.NErr
}
totalUnreadReplies := totalUnreadRepliesResult.Data.(int64)
totalUnreadThreads := totalUnreadThreadsResult.Data.(int64)
var userIds []string
userIdMap := map[string]bool{}
@@ -249,7 +251,7 @@ func (s *SqlThreadStore) GetThreadsForUser(userId, teamId string, opts model.Get
Total: totalCount,
Threads: nil,
TotalUnreadMentions: totalUnreadMentions,
TotalUnreadReplies: totalUnreadReplies,
TotalUnreadThreads: totalUnreadThreads,
}
for _, thread := range threads {