Refresh airing TV series when the calendar is opened
- POST /entries/sync-series starts a background refresh of airing TV series (not Ended/Canceled, auto sync on) not refreshed in the last 24h; manual refreshes reset that clock. GET kept as an alias, plus GET /entries/sync-series/status for progress - Reuses the rate-limited stale refresh job with a series-only scope; only one refresh job runs at a time - Calendar starts the sync on visit, shows progress, and reloads episodes and the library when it finishes - Remove the old SyncSeriesData, whose date check no longer worked
This commit is contained in:
1 parent
a88423163e
commit
ac0030d611
8 files changed
+119
-214
No files matched your search
@@ -575,14 +575,20 @@ class MaintenanceService {
|
||||
* Entries due for a TMDB refresh: never fetched, or last fetched more than
|
||||
* `hours` ago. Entries with auto sync turned off are skipped.
|
||||
* @param {number} [hours=24]
|
||||
* @param {{ seriesOnly?: boolean }} [options] - seriesOnly: only TV series
|
||||
* that are still airing (not Ended/Canceled), for the calendar sync
|
||||
*/
|
||||
async getStaleEntries(hours = 24) {
|
||||
async getStaleEntries(hours = 24, { seriesOnly = false } = {}) {
|
||||
const cutoff = new Date(Date.now() - hours * 60 * 60 * 1000);
|
||||
return Entry.findAll({
|
||||
attributes: ["id", "title", "last_fetch"],
|
||||
where: {
|
||||
autoSync: { [Op.not]: false },
|
||||
[Op.or]: [{ last_fetch: null }, { last_fetch: { [Op.lt]: cutoff } }],
|
||||
...(seriesOnly && {
|
||||
is_tvseries: true,
|
||||
status: { [Op.or]: [null, { [Op.notIn]: ["Ended", "Canceled"] }] },
|
||||
}),
|
||||
},
|
||||
order: [["last_fetch", "ASC"]],
|
||||
});
|
||||
@@ -600,18 +606,20 @@ class MaintenanceService {
|
||||
* TMDB requests go through tmdbService's rate limiter, so a large library
|
||||
* is spread out instead of hammering the API.
|
||||
* @param {number} [hours=24]
|
||||
* @param {{ seriesOnly?: boolean }} [options] - see getStaleEntries
|
||||
* @returns {Object} the job status, or `{ alreadyRunning: true, ... }`
|
||||
*/
|
||||
async startStaleRefresh(hours = 24) {
|
||||
async startStaleRefresh(hours = 24, options = {}) {
|
||||
if (this.staleRefreshJob?.running) {
|
||||
return { alreadyRunning: true, ...this.getStaleRefreshStatus() };
|
||||
}
|
||||
|
||||
const entries = await this.getStaleEntries(hours);
|
||||
const entries = await this.getStaleEntries(hours, options);
|
||||
const job = {
|
||||
running: true,
|
||||
cancelRequested: false,
|
||||
hours,
|
||||
scope: options.seriesOnly ? "series" : "all",
|
||||
total: entries.length,
|
||||
done: 0,
|
||||
succeeded: 0,
|
||||
|
||||
Reference in new issue
Block a user