Added phased startup string function for bringing services back online gradually

This commit is contained in:
2025-09-01 02:38:29 +01:00
parent dfb075a4bf
commit a6a3fe8ec2
2 changed files with 17 additions and 0 deletions

View File

@@ -3,6 +3,7 @@ package global
import (
crand "crypto/rand" // Probably better than math/rand for this
"log"
"math/rand"
)
func GenerateRandomString(length int) string {
@@ -23,3 +24,15 @@ func GenerateRandomString(length int) string {
}
return string(charArray)
}
func PhasedStartupString() string {
// Redis is used for a lot of stuff, which means the Postgres DB gets HAMMERED on a fresh startup. Use
// this to generate a shuffled string that can be used to only allow e.g. UIDs starting with [x] to connect
// for the first however many seconds and incrementally expand access so that data doesn't need to be loaded all at
// once
chars := []rune("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
rand.Shuffle(len(chars), func(i, j int) {
chars[i], chars[j] = chars[j], chars[i]
})
return string(chars)
}