accounts: reduce initial load time even further

took the referralCache idea further and did it for all db queries. Now
take ~40ms for ~5000 users on arm64 through QEMU, and ~60ms on a
rockpro64.
This commit is contained in:
Harvey Tindall
2025-12-10 17:39:54 +00:00
parent a08a0fd3e6
commit 2e97142d9e
4 changed files with 153 additions and 50 deletions
+58
View File
@@ -1716,3 +1716,61 @@ func storeJSON(path string, obj interface{}) error {
}
return err
}
// ActiveReferralsByID returns a map of jellyfin user IDs to their active referral "invite" code, if they have one.
// It does not check if the user still exists, simply finding invites with the ReferrerJellyfinID field set.
func (st *Storage) ActiveReferralsByID() map[string]Invite {
out := map[string]Invite{}
for _, inv := range st.GetInvites() {
if inv.ReferrerJellyfinID == "" {
continue
}
out[inv.ReferrerJellyfinID] = inv
}
return out
}
// EmailsByID returns a map of jellyfin user IDs to EmailAddress entries, if they have one.
func (st *Storage) EmailsByID() map[string]EmailAddress {
out := map[string]EmailAddress{}
for _, email := range st.GetEmails() {
out[email.JellyfinID] = email
}
return out
}
// ExpiriesByID returns a map of jellyfin user IDs to User expiries, if they have one.
func (st *Storage) ExpiriesByID() map[string]UserExpiry {
out := map[string]UserExpiry{}
for _, expiry := range st.GetUserExpiries() {
out[expiry.JellyfinID] = expiry
}
return out
}
// DiscordUsersByID returns a map of jellyfin user IDs to Discord user entries, if they have one.
func (st *Storage) DiscordUsersByID() map[string]DiscordUser {
out := map[string]DiscordUser{}
for _, expiry := range st.GetDiscord() {
out[expiry.JellyfinID] = expiry
}
return out
}
// TelegramUsersByID returns a map of jellyfin user IDs to Telegram user entries, if they have one.
func (st *Storage) TelegramUsersByID() map[string]TelegramUser {
out := map[string]TelegramUser{}
for _, expiry := range st.GetTelegram() {
out[expiry.JellyfinID] = expiry
}
return out
}
// MatrixUsersByID returns a map of jellyfin user IDs to Matrix user entries, if they have one.
func (st *Storage) MatrixUsersByID() map[string]MatrixUser {
out := map[string]MatrixUser{}
for _, expiry := range st.GetMatrix() {
out[expiry.JellyfinID] = expiry
}
return out
}