mirror of
https://github.com/BreizhHardware/Jellystat.git
synced 2026-01-18 16:27:20 +01:00
chore: Update bulk insert and update query for jf_activity_watchdog table
fix: timestamp update error in watchdog table chore: removed legacy update code and used db bulkInsert function which has update on conflict handlers
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
|
||||
|
||||
const update_query = [
|
||||
{table:'jf_activity_watchdog',query:' ON CONFLICT ("Id") DO UPDATE SET "TranscodingInfo" = EXCLUDED."TranscodingInfo", "MediaStreams" = EXCLUDED."MediaStreams", "PlayMethod" = EXCLUDED."PlayMethod"'},
|
||||
{table:'jf_activity_watchdog',query:' ON CONFLICT ("Id") DO UPDATE SET "TranscodingInfo" = EXCLUDED."TranscodingInfo", "MediaStreams" = EXCLUDED."MediaStreams", "PlayMethod" = EXCLUDED."PlayMethod","ActivityDateInserted" = EXCLUDED."ActivityDateInserted","PlaybackDuration" = EXCLUDED."PlaybackDuration","IsPaused"= EXCLUDED."IsPaused"'},
|
||||
{table:'jf_item_info',query:' ON CONFLICT ("Id") DO UPDATE SET "Path" = EXCLUDED."Path", "Name" = EXCLUDED."Name", "Size" = EXCLUDED."Size", "Bitrate" = EXCLUDED."Bitrate", "MediaStreams" = EXCLUDED."MediaStreams"'},
|
||||
{table:'jf_libraries',query:' ON CONFLICT ("Id") DO UPDATE SET "Name" = EXCLUDED."Name", "Type" = EXCLUDED."Type", "CollectionType" = EXCLUDED."CollectionType", "ImageTagsPrimary" = EXCLUDED."ImageTagsPrimary", archived=false'},
|
||||
{table:'jf_library_episodes',query:' ON CONFLICT ("Id") DO UPDATE SET "Name" = EXCLUDED."Name", "PremiereDate" = EXCLUDED."PremiereDate", "OfficialRating" = EXCLUDED."OfficialRating", "CommunityRating" = EXCLUDED."CommunityRating", "RunTimeTicks" = EXCLUDED."RunTimeTicks", "ProductionYear" = EXCLUDED."ProductionYear", "IndexNumber" = EXCLUDED."IndexNumber", "ParentIndexNumber" = EXCLUDED."ParentIndexNumber", "Type" = EXCLUDED."Type", "ParentLogoItemId" = EXCLUDED."ParentLogoItemId", "ParentBackdropItemId" = EXCLUDED."ParentBackdropItemId", "ParentBackdropImageTags" = EXCLUDED."ParentBackdropImageTags", "SeriesId" = EXCLUDED."SeriesId", "SeasonId" = EXCLUDED."SeasonId", "SeasonName" = EXCLUDED."SeasonName", "SeriesName" = EXCLUDED."SeriesName", "PrimaryImageHash" = EXCLUDED."PrimaryImageHash", "DateCreated" = EXCLUDED."DateCreated" , archived=false'},
|
||||
|
||||
@@ -79,7 +79,7 @@ async function ActivityMonitor(interval) {
|
||||
|
||||
wdData.PlaybackDuration = parseInt(wdData.PlaybackDuration) + diffInSeconds;
|
||||
|
||||
wdData.ActivityDateInserted = `'${lastPausedDate.format("YYYY-MM-DD HH:mm:ss.SSSZ")}'::timestamptz`;
|
||||
wdData.ActivityDateInserted = `${lastPausedDate.format("YYYY-MM-DD HH:mm:ss.SSSZ")}`;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -96,34 +96,7 @@ async function ActivityMonitor(interval) {
|
||||
|
||||
//update wd state
|
||||
if (WatchdogDataToUpdate.length > 0) {
|
||||
const WatchdogDataUpdated = WatchdogDataToUpdate;
|
||||
|
||||
await (async () => {
|
||||
try {
|
||||
await db.query("BEGIN");
|
||||
const cs = new pgp.helpers.ColumnSet([
|
||||
"?Id",
|
||||
"IsPaused",
|
||||
{ name: "PlaybackDuration", mod: ":raw" },
|
||||
{ name: "ActivityDateInserted", mod: ":raw" },
|
||||
]);
|
||||
|
||||
const updateQuery = pgp.helpers.update(WatchdogDataUpdated, cs, "jf_activity_watchdog") + ' WHERE v."Id" = t."Id"';
|
||||
await db
|
||||
.query(updateQuery)
|
||||
.then((result) => {
|
||||
// console.log('Update successful', result.rowCount, 'rows updated');
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Error updating rows", error);
|
||||
});
|
||||
|
||||
await db.query("COMMIT");
|
||||
} catch (error) {
|
||||
await db.query("ROLLBACK");
|
||||
console.log(error);
|
||||
}
|
||||
})();
|
||||
await db.insertBulk("jf_activity_watchdog", WatchdogDataToUpdate, jf_activity_watchdog_columns);
|
||||
}
|
||||
|
||||
//delete from db no longer in session data and insert into stats db
|
||||
|
||||
Reference in New Issue
Block a user