Drop calls from migration with the same callId and peerId

This commit is contained in:
Jamie Kyle 2023-08-09 09:32:43 -07:00 committed by GitHub
parent 1eaabb6734
commit e20fa41fd5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 89 additions and 0 deletions

View file

@ -77,6 +77,8 @@ export default function updateToSchemaVersion87(
const rows = db.prepare(selectQuery).all();
const uniqueConstraint = new Set();
for (const row of rows) {
const json = JSON.parse(row.json);
const details = json.callHistoryDetails;
@ -153,6 +155,17 @@ export default function updateToSchemaVersion87(
continue;
}
// We need to ensure a call with the same callId and peerId doesn't get
// inserted twice because of the unique constraint on the table.
const uniqueKey = `${callId} -> ${peerId}`;
if (uniqueConstraint.has(uniqueKey)) {
logger.error(
`updateToSchemaVersion87: duplicate callId/peerId pair (${uniqueKey})`
);
continue;
}
uniqueConstraint.add(uniqueKey);
const [insertQuery, insertParams] = sql`
INSERT INTO callsHistory (
callId,