break up getThreadsForUser, leverage errgroup (#19709)
* MM-42282: handle teamId parameter correctly As per https://community-daily.mattermost.com/core/pl/ugs7ue6e4j8a7cgegk1bxje8to, `ThreadStore.GetThreadsForUser` accepts a `teamId` parameter, but incorrectly handles an empty value of `""` as looking only for channels with an empty `teamId` (aka DMs and GMs) instead of finding all channels and effectively ignoring the team property. Fixes: https://mattermost.atlassian.net/browse/MM-42282 * break up getThreadsForUser, leverage errgroup This change breaks up `GetThreadsForUser` in the `ThreadStore` into its constituent `GetTotalUnreadThreads`, `GetTotalThreads`, `GetTotalUnreadMentions`, and the original `GetThreadsForUser` but now solely returning the thread structures. Instead of a monolithic method at the store level, the application layer now handles calling bulk requests, leveraging `errgroup` for simpler parallelization. This change brings with it a few benefits: * Simpler code, including more idiomatic usage of squirrel * Simpler SQL, joining tables only when configured conditions require same. (No performance benefit here, since an unused LEFT JOIN generally has no overhead.) * Discrete Grafana metrics for each store method, giving us better insight into the performance characteristics in play. * **Performance boost**: reduced overhead when clearing push notifications. This last point is what prompted the re-re-reactoring in this PR. As I broke things up, I realized that `clearPushNotificationSync` only used the `TotalUnreadMentions`, but asked for the count of total threads and total unread threads. By exposing the discrete methods, this code path avoids two aggregate queries. We clear notifications when marking a thread as read, and when marking a channel with unread mentions as viewed, so I expect we'll see at least a modest boost to performance from simply not wasting these cycles anymore. No performance improvements are expected from this PR for the general case of using `GetThreadsForUser` to populate the threads view. * never discard errors from building queries * no MustSql Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
4bf3d6a7f5
Коммит
47c44a9b7d
@@ -236,11 +236,11 @@ func (a *App) clearPushNotificationSync(currentSessionId, userID, channelID, roo
|
||||
msg.Badge = int(unreadCount)
|
||||
|
||||
if msg.IsCRTEnabled {
|
||||
data, err := a.Srv().Store.Thread().GetThreadsForUser(userID, "", model.GetUserThreadsOpts{TotalsOnly: true})
|
||||
totalUnreadMentions, err := a.Srv().Store.Thread().GetTotalUnreadMentions(userID, "", model.GetUserThreadsOpts{})
|
||||
if err != nil {
|
||||
return model.NewAppError("clearPushNotificationSync", "app.user.get_thread_count_for_user.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
msg.Badge += int(data.TotalUnreadMentions)
|
||||
msg.Badge += int(totalUnreadMentions)
|
||||
}
|
||||
return a.sendPushNotificationToAllSessions(msg, userID, currentSessionId)
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user