MM-40148: threadsOnly query param for user threads (#19833)
* MM-40148: threadsOnly query param for user threads Currently we always calculate counts when fetching user threads. Those counts include total, unread replies, and unread mentions, and are potentially expensive to calculate. This commit adds a new query param 'threadsOnly' which won't calculate any counts and just return threads. Co-authored-by: koox00 <3829551+koox00@users.noreply.github.com> Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
27bd16e5f5
Коммит
9521797b15
50
app/user.go
50
app/user.go
@@ -2296,35 +2296,37 @@ func (a *App) GetThreadsForUser(userID, teamID string, options model.GetUserThre
|
||||
var result model.Threads
|
||||
var eg errgroup.Group
|
||||
|
||||
eg.Go(func() error {
|
||||
totalUnreadThreads, err := a.Srv().Store.Thread().GetTotalUnreadThreads(userID, teamID, options)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to count unread threads for user id=%s", userID)
|
||||
}
|
||||
result.TotalUnreadThreads = totalUnreadThreads
|
||||
if !options.ThreadsOnly {
|
||||
eg.Go(func() error {
|
||||
totalUnreadThreads, err := a.Srv().Store.Thread().GetTotalUnreadThreads(userID, teamID, options)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to count unread threads for user id=%s", userID)
|
||||
}
|
||||
result.TotalUnreadThreads = totalUnreadThreads
|
||||
|
||||
return nil
|
||||
})
|
||||
return nil
|
||||
})
|
||||
|
||||
eg.Go(func() error {
|
||||
totalCount, err := a.Srv().Store.Thread().GetTotalThreads(userID, teamID, options)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to count threads for user id=%s", userID)
|
||||
}
|
||||
result.Total = totalCount
|
||||
eg.Go(func() error {
|
||||
totalCount, err := a.Srv().Store.Thread().GetTotalThreads(userID, teamID, options)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to count threads for user id=%s", userID)
|
||||
}
|
||||
result.Total = totalCount
|
||||
|
||||
return nil
|
||||
})
|
||||
return nil
|
||||
})
|
||||
|
||||
eg.Go(func() error {
|
||||
totalUnreadMentions, err := a.Srv().Store.Thread().GetTotalUnreadMentions(userID, teamID, options)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to count threads for user id=%s", userID)
|
||||
}
|
||||
result.TotalUnreadMentions = totalUnreadMentions
|
||||
eg.Go(func() error {
|
||||
totalUnreadMentions, err := a.Srv().Store.Thread().GetTotalUnreadMentions(userID, teamID, options)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to count threads for user id=%s", userID)
|
||||
}
|
||||
result.TotalUnreadMentions = totalUnreadMentions
|
||||
|
||||
return nil
|
||||
})
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
if !options.TotalsOnly {
|
||||
eg.Go(func() error {
|
||||
|
||||
Ссылка в новой задаче
Block a user