Release v2.10.3
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
// Refresh data sources and notify only the screens whose rendered data changed.
|
||||
|
||||
async function getAffectedScreenSlugs(connection, common, slideMatchKey, sourceId) {
|
||||
const [slideRows] = await connection.query('SELECT id, content_json FROM c_slides WHERE content_json IS NOT NULL');
|
||||
const slideIds = [];
|
||||
@@ -106,6 +108,24 @@ function hasApiSourceChanged(apiSource, responseDetails) {
|
||||
return normalizeSnapshotValue(apiSource && apiSource.last_response_json) !== normalizeSnapshotValue(responseDetails && responseDetails.responseJson);
|
||||
}
|
||||
|
||||
function isDifferentHour(previousPulledAt, currentPulledAt) {
|
||||
const previous = new Date(previousPulledAt);
|
||||
const current = new Date(currentPulledAt);
|
||||
if (!Number.isFinite(previous.getTime())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return previous.getFullYear() !== current.getFullYear()
|
||||
|| previous.getMonth() !== current.getMonth()
|
||||
|| previous.getDate() !== current.getDate()
|
||||
|| previous.getHours() !== current.getHours();
|
||||
}
|
||||
|
||||
function hasWeatherLocationChanged(location, responseDetails, refreshedAt) {
|
||||
return normalizeSnapshotValue(location && location.last_response_json) !== normalizeSnapshotValue(responseDetails && responseDetails.responseJson)
|
||||
|| isDifferentHour(location && location.last_pulled_at, refreshedAt);
|
||||
}
|
||||
|
||||
async function refreshApiSource(pool, common, apiSourceOrId, actorId, notifyPlayerScreens) {
|
||||
const connection = await pool.getConnection();
|
||||
try {
|
||||
@@ -169,16 +189,17 @@ async function refreshWeatherLocation(pool, common, weatherLocationOrId, actorId
|
||||
pullError = String(error && error.message ? error.message : 'Unable to load weather forecast.');
|
||||
}
|
||||
|
||||
const refreshedAt = new Date();
|
||||
await connection.beginTransaction();
|
||||
await connection.query(
|
||||
'UPDATE i_weather_locations SET last_pulled_at = ?, last_pull_error = ?, last_response_json = COALESCE(?, last_response_json), modified_by = ? WHERE id = ?',
|
||||
[new Date(), pullError || null, result ? result.responseJson : null, actorId, location.id]
|
||||
[refreshedAt, pullError || null, result ? result.responseJson : null, actorId, location.id]
|
||||
);
|
||||
await connection.commit();
|
||||
|
||||
if (pullError) {
|
||||
console.error('[data-source-refresh] Weather location refresh completed with an error for location ' + location.id + ': ' + pullError);
|
||||
} else if (typeof notifyAffectedScreens === 'function') {
|
||||
} else if (hasWeatherLocationChanged(location, result, refreshedAt) && typeof notifyPlayerScreens === 'function') {
|
||||
try {
|
||||
await notifyAffectedScreens(connection, common, notifyPlayerScreens, 'weather_location_id', location.id);
|
||||
} catch (notifyError) {
|
||||
|
||||
Reference in New Issue
Block a user