mirror of
https://github.com/hrfee/jfa-go.git
synced 2026-01-18 16:47:42 +01:00
jellyseerr: fix extremely long import, run only once
cache was being invalidated for every user, and on my 5000 user test instance, this sweated jellyseerr and my computer (audibly). Also, since this only needs to realistically run once, a flag is set in the database to indicate it's been done, and unset once the feature is disabled. It'll only run on boot if the flag is unset, or if triggered by the /tasks route. Will likely add manual trigger buttons on the web as well.
This commit is contained in:
@@ -9,8 +9,13 @@ import (
|
||||
lm "github.com/hrfee/jfa-go/logmessages"
|
||||
)
|
||||
|
||||
type JellyseerrInitialSyncStatus struct {
|
||||
Done bool
|
||||
}
|
||||
|
||||
// Ensure the Jellyseerr cache is up to date before calling.
|
||||
func (app *appContext) SynchronizeJellyseerrUser(jfID string) {
|
||||
user, imported, err := app.js.GetOrImportUser(jfID)
|
||||
user, imported, err := app.js.GetOrImportUser(jfID, true)
|
||||
if err != nil {
|
||||
app.debug.Printf(lm.FailedImportUser, lm.Jellyseerr, jfID, err)
|
||||
return
|
||||
@@ -63,19 +68,30 @@ func (app *appContext) SynchronizeJellyseerrUser(jfID string) {
|
||||
}
|
||||
|
||||
func (app *appContext) SynchronizeJellyseerrUsers() {
|
||||
jsSync := JellyseerrInitialSyncStatus{}
|
||||
app.storage.db.Get("jellyseerr_inital_sync_status", &jsSync)
|
||||
if jsSync.Done {
|
||||
return
|
||||
}
|
||||
|
||||
users, err := app.jf.GetUsers(false)
|
||||
if err != nil {
|
||||
app.err.Printf(lm.FailedGetUsers, lm.Jellyfin, err)
|
||||
return
|
||||
}
|
||||
app.js.ReloadCache()
|
||||
// I'm sure Jellyseerr can handle it,
|
||||
// but past issues with the Jellyfin db scare me from
|
||||
// running these concurrently. W/e, its a bg task anyway.
|
||||
for _, user := range users {
|
||||
app.SynchronizeJellyseerrUser(user.ID)
|
||||
}
|
||||
// Don't run again until this flag is unset
|
||||
// Stored in the DB as it's not something the user needs to see.
|
||||
app.storage.db.Upsert("jellyseerr_inital_sync_status", JellyseerrInitialSyncStatus{true})
|
||||
}
|
||||
|
||||
// Not really a normal daemon, since it'll only fire once when the feature is enabled.
|
||||
func newJellyseerrDaemon(interval time.Duration, app *appContext) *GenericDaemon {
|
||||
d := NewGenericDaemon(interval, app,
|
||||
func(app *appContext) {
|
||||
@@ -83,5 +99,12 @@ func newJellyseerrDaemon(interval time.Duration, app *appContext) *GenericDaemon
|
||||
},
|
||||
)
|
||||
d.Name("Jellyseerr import")
|
||||
|
||||
jsSync := JellyseerrInitialSyncStatus{}
|
||||
app.storage.db.Get("jellyseerr_inital_sync_status", &jsSync)
|
||||
if jsSync.Done {
|
||||
return nil
|
||||
}
|
||||
|
||||
return d
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user