MM-41085: Use a counting semaphore in sendNotifications (#19498)
We throttle the concurrency limit in maintaining thread membership for a given thread using a counting semaphore. The limit is currently 8 which is a decent number to start with. On some more thinking, it would be even better if the sql query could be modified to support batch updates. https://mattermost.atlassian.net/browse/MM-41085 ```release-note NONE ```
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
569ee94116
Коммит
6605300c66
@@ -219,11 +219,22 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
|
|||||||
for id := range mentions.Mentions {
|
for id := range mentions.Mentions {
|
||||||
threadParticipants[id] = true
|
threadParticipants[id] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// sema is a counting semaphore to throttle the number of concurrent DB requests.
|
||||||
|
// A concurrency of 8 should be sufficient.
|
||||||
|
// We don't want to set a higher limit which can bring down the DB.
|
||||||
|
sema := make(chan struct{}, 8)
|
||||||
// for each mention, make sure to update thread autofollow (if enabled) and update increment mention count
|
// for each mention, make sure to update thread autofollow (if enabled) and update increment mention count
|
||||||
for id := range threadParticipants {
|
for id := range threadParticipants {
|
||||||
mac := make(chan *model.AppError, 1)
|
mac := make(chan *model.AppError, 1)
|
||||||
|
// Get token.
|
||||||
|
sema <- struct{}{}
|
||||||
go func(userID string) {
|
go func(userID string) {
|
||||||
defer close(mac)
|
defer func() {
|
||||||
|
close(mac)
|
||||||
|
// Release token.
|
||||||
|
<-sema
|
||||||
|
}()
|
||||||
mentionType, incrementMentions := mentions.Mentions[userID]
|
mentionType, incrementMentions := mentions.Mentions[userID]
|
||||||
// if the user was not explicitly mentioned, check if they explicitly unfollowed the thread
|
// if the user was not explicitly mentioned, check if they explicitly unfollowed the thread
|
||||||
if !incrementMentions {
|
if !incrementMentions {
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user