openvibers/openvibe.tours Commits

Clear stale Live recordings before repopulating (#18)

OP OpenVibers committed 12 days ago · 036210d37e · 2 files, +20 −11

Changes

ddiff --git a/server/jobs/live.js b/server/jobs/live.js
iindex f6c8a67..1a96b11 100644
---- a/server/jobs/live.js
++++ b/server/jobs/live.js
@@@ -37,17 +37,23 @@ function createLiveJob({ config, s, store, fetchImpl, log = console }) {
if (city) result.withCity += 1;
}
}
-- for (const item of recent) {
-- const city = match(`${item.title} ${item.tags.join(' ')}`);
-- await store.upsertLive({ ...item, cityId: city ? city.id : null, cityName: city ? city.name : null });
-- result.vods += 1;
-- if (city) result.withCity += 1;
++ const recordingsOk = !result.errors.some((e) => e.startsWith('recent:')) && !result.errors.some((e) => e.startsWith('clips:'));
++ if (recordingsOk) await store.clearLiveRecordings();
++ if (!result.errors.some((e) => e.startsWith('recent:'))) {
++ for (const item of recent) {
++ const city = match(`${item.title} ${item.tags.join(' ')}`);
++ await store.upsertLive({ ...item, cityId: city ? city.id : null, cityName: city ? city.name : null });
++ result.vods += 1;
++ if (city) result.withCity += 1;
++ }
}
-- for (const item of clips) {
-- const city = match(`${item.title} `);
-- await store.upsertLive({ ...item, cityId: city ? city.id : null, cityName: city ? city.name : null });
-- result.clips += 1;
-- if (city) result.withCity += 1;
++ if (!result.errors.some((e) => e.startsWith('clips:'))) {
++ for (const item of clips) {
++ const city = match(`${item.title} `);
++ await store.upsertLive({ ...item, cityId: city ? city.id : null, cityName: city ? city.name : null });
++ result.clips += 1;
++ if (city) result.withCity += 1;
++ }
}
await store.trimLiveVods(200);
return result;
ddiff --git a/server/store.js b/server/store.js
iindex 2144e00..cac98a2 100644
---- a/server/store.js
++++ b/server/store.js
@@@ -394,6 +394,9 @@ function createStore(s, { config = {} } = {}) {
async function clearLiveStreams() {
await db.exec("DELETE FROM tours_live WHERE kind = 'stream'");
}
++ async function clearLiveRecordings() {
++ await db.exec("DELETE FROM tours_live WHERE kind IN ('vod', 'clip')");
++ }
async function trimLiveVods(keep = 200) {
await db.exec(`DELETE FROM tours_live WHERE kind = 'vod' AND id NOT IN
(SELECT id FROM tours_live WHERE kind IN ('vod', 'clip') ORDER BY COALESCE(ended_at, fetched_at) DESC LIMIT $1)`, [keep]);
@@@ -595,7 +598,7 @@ function createStore(s, { config = {} } = {}) {
latestJobRuns, recordJobStart, recordJobFinish,
publicCitiesForSitemap, publicRoutesForSitemap, publicPlacesForSitemap, publicCitiesForLlms,
upsertCity, upsertCitySource, citySourcesMissing, citySource, upsertPlace, replaceRoutesForCity,
-- upsertLive, clearLiveStreams, trimLiveVods, upsertStay,
++ upsertLive, clearLiveStreams, clearLiveRecordings, trimLiveVods, upsertStay,
createTrip, tripsForSubject, tripBySlug, updateTrip, deleteTrip,
addTripPlace, removeTripPlace, setTripRoute, addTripStay, removeTripStay,
};