openvibers/openvibe.tours Commits
Clear stale Live recordings before repopulating (#18)
Changes
@@@ -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;@@@ -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,};
@@ -37,17 +37,23 @@ function createLiveJob({ config, s, store, fetchImpl, log = console }) {
@@ -37,17 +37,23 @@ function createLiveJob({ config, s, store, fetchImpl, log = console }) {
if (city) result.withCity += 1;
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);
await store.trimLiveVods(200);
return result;
return result;
@@ -394,6 +394,9 @@ function createStore(s, { config = {} } = {}) {
@@ -394,6 +394,9 @@ function createStore(s, { config = {} } = {}) {
async function clearLiveStreams() {
async function clearLiveStreams() {
await db.exec("DELETE FROM tours_live WHERE kind = 'stream'");
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) {
async function trimLiveVods(keep = 200) {
await db.exec(`DELETE FROM tours_live WHERE kind = 'vod' AND id NOT IN
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]);
(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 = {} } = {}) {
@@ -595,7 +598,7 @@ function createStore(s, { config = {} } = {}) {
latestJobRuns, recordJobStart, recordJobFinish,
latestJobRuns, recordJobStart, recordJobFinish,
publicCitiesForSitemap, publicRoutesForSitemap, publicPlacesForSitemap, publicCitiesForLlms,
publicCitiesForSitemap, publicRoutesForSitemap, publicPlacesForSitemap, publicCitiesForLlms,
upsertCity, upsertCitySource, citySourcesMissing, citySource, upsertPlace, replaceRoutesForCity,
upsertCity, upsertCitySource, citySourcesMissing, citySource, upsertPlace, replaceRoutesForCity,
- upsertLive, clearLiveStreams, trimLiveVods, upsertStay,
+ upsertLive, clearLiveStreams, clearLiveRecordings, trimLiveVods, upsertStay,
createTrip, tripsForSubject, tripBySlug, updateTrip, deleteTrip,
createTrip, tripsForSubject, tripBySlug, updateTrip, deleteTrip,
addTripPlace, removeTripPlace, setTripRoute, addTripStay, removeTripStay,
addTripPlace, removeTripPlace, setTripRoute, addTripStay, removeTripStay,
};
};