mirror of
https://github.com/abhinavxd/libredesk.git
synced 2026-09-22 10:33:24 +00:00
fix: shuffle users in team balancer to prevent ordering bias on app restart
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"strconv"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -145,6 +146,12 @@ func (e *Engine) populateTeamBalancer() error {
|
||||
continue
|
||||
}
|
||||
|
||||
// Shuffle users to prevent ordering bias, as every app restart will pick the same first user.
|
||||
r := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
r.Shuffle(len(users), func(i, j int) {
|
||||
users[i], users[j] = users[j], users[i]
|
||||
})
|
||||
|
||||
for _, user := range users {
|
||||
// Team does not have a balancer pool, create one.
|
||||
if _, ok := e.roundRobinBalancer[team.ID]; !ok {
|
||||
|
||||
Reference in New Issue
Block a user