accounts: reduce initial load time further

When generating the cache and calling userSummary per user, previously
the DB was queried for an invite with the ReferrerJellyfinID set to the
user's ID. This was fast enough on my test system (~5000 users in
~1.5s), while testing cross-compilation, I found it ran extremely slow
on an arm64 build (running through QEMU admittedly), doing ~5000 in
~18s. Instead, a map of IDs to invites/referrals is generated once and
queried instead. Initial load now takes ~80ms on my system, and 0.95s
through QEMU, and 0.68s on a rockpro64 SBC.
This commit is contained in:
Harvey Tindall
2025-12-10 16:44:21 +00:00
parent 420a22970d
commit a08a0fd3e6
4 changed files with 36 additions and 5 deletions
+8 -1
View File
@@ -8,6 +8,8 @@ import (
"strings"
"sync"
"time"
lm "github.com/hrfee/jfa-go/logmessages"
)
const (
@@ -85,10 +87,12 @@ func (c *UserCache) MaybeSync(app *appContext) error {
status <- err
return
}
startTime := time.Now()
cache := make([]respUser, len(users))
labels := map[string]bool{}
referralCache := app.getActiveReferrals()
for i, jfUser := range users {
cache[i] = app.userSummary(jfUser)
cache[i] = app.userSummary(jfUser, &referralCache)
if cache[i].Label != "" {
labels[cache[i].Label] = true
}
@@ -101,6 +105,9 @@ func (c *UserCache) MaybeSync(app *appContext) error {
for label, _ := range labels {
labelSlice = append(labelSlice, label)
}
elapsed := time.Since(startTime).Seconds()
usersPerSec := float64(len(users)) / elapsed
app.debug.Printf(lm.CacheRefreshCompleted, len(users), elapsed, usersPerSec)
c.Cache = cache
c.Ref = ref
c.Sorted = false