Added phased startup string function for bringing services back online gradually
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
Reference in New Issue
Block a user