The GetTeamsUnreadForUser call would be called for every team switch.
In CRT mode, it would make a separate store call for every team, which
would run the 3 aggregate SQL queries in GetThreadsForUser.

This is suboptimal because the complexity is linearly proportional
to the number of teams.

We make the following optimizations:
1. Change the query to a single one which aggregates all teams.
2. The query originally used just 2 out of the 3 queries, so one
query was fully redundant. We remove that query in the new one.
3. Further analysis was done whether it makes sense to run the 2
queries synchronously or not. The load-tests didn't show any degradation
in running them concurrently, so we keep the same behavior.

```release-note
NONE
```
Этот коммит содержится в:
Agniva De Sarker
2022-02-17 09:24:39 +05:30
коммит произвёл GitHub
родитель 9640962428
Коммит 6898b3d70f
8 изменённых файлов: 303 добавлений и 25 удалений

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

@@ -10519,6 +10519,27 @@ func (s *RetryLayerThreadStore) GetPosts(threadID string, since int64) ([]*model
}
func (s *RetryLayerThreadStore) GetTeamsUnreadForUser(userID string, teamIDs []string) (map[string]*model.TeamUnread, error) {
tries := 0
for {
result, err := s.ThreadStore.GetTeamsUnreadForUser(userID, teamIDs)
if err == nil {
return result, nil
}
if !isRepeatableError(err) {
return result, err
}
tries++
if tries >= 3 {
err = errors.Wrap(err, "giving up after 3 consecutive repeatable transaction failures")
return result, err
}
timepkg.Sleep(100 * timepkg.Millisecond)
}
}
func (s *RetryLayerThreadStore) GetThreadFollowers(threadID string, fetchOnlyActive bool) ([]string, error) {
tries := 0