Skip to content
This repository has been archived by the owner on Aug 9, 2021. It is now read-only.

Commit

Permalink
Merge pull request #303 from mjs/remove-dups-fix
Browse files Browse the repository at this point in the history
remove-dups: ignore recordings with a NULL "recordingDateTime"
  • Loading branch information
mjs authored Jan 28, 2020
2 parents a64d6ad + 32c3203 commit 1feb768
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions remove-dups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ async function main() {
// recordingDateTime). The recording with the lowest id will be
// kept. Recordings with an updatedAt timestamp within the last 30
// mins are ignored.
//
// Recordings with a NULL recordingDateTime are also ignored as
// these are typically recent uploads that are awaiting processing.
await client.query("BEGIN");
const res = await client.query(
`DELETE FROM "Recordings"
Expand All @@ -33,16 +36,15 @@ async function main() {
ROW_NUMBER() OVER (PARTITION BY "DeviceId", "recordingDateTime" ORDER BY id) as rownum
FROM "Recordings"
WHERE "updatedAt" < now() - INTERVAL '30 minutes'
AND "recordingDateTime" IS NOT NULL
) d
WHERE d.rownum > 1
) RETURNING id, "DeviceId", "recordingDateTime"
) RETURNING id, "DeviceId", "type", "recordingDateTime"
`
);
for (const row of res.rows) {
const ts = row.recordingDateTime
? row.recordingDateTime.toISOString()
: "null";
console.log(`deleted ${row.id}: device=${row.DeviceId} ts=${ts}`);
const ts = row.recordingDateTime!.toISOString()
console.log(`deleted ${row.id}: device=${row.DeviceId} type=${row.type} ts=${ts}`);
}
if (args.delete) {
await client.query("COMMIT");
Expand Down

0 comments on commit 1feb768

Please sign in to comment.