Fix getKnownMessageAttachments query
This commit is contained in:
parent
cf43726664
commit
efa29dc800
2 changed files with 27 additions and 3 deletions
|
@ -74,15 +74,27 @@ async function cleanupOrphanedAttachments({
|
||||||
// Delete orphaned attachments from conversations and messages.
|
// Delete orphaned attachments from conversations and messages.
|
||||||
|
|
||||||
const orphanedAttachments = new Set(await getAllAttachments(userDataPath));
|
const orphanedAttachments = new Set(await getAllAttachments(userDataPath));
|
||||||
|
console.log(
|
||||||
|
'cleanupOrphanedAttachments: found ' +
|
||||||
|
`${orphanedAttachments.size} attachments on disk`
|
||||||
|
);
|
||||||
|
|
||||||
{
|
{
|
||||||
const attachments: ReadonlyArray<string> = await sql.sqlCall(
|
const attachments: ReadonlyArray<string> = await sql.sqlCall(
|
||||||
'getKnownConversationAttachments'
|
'getKnownConversationAttachments'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let missing = 0;
|
||||||
for (const known of attachments) {
|
for (const known of attachments) {
|
||||||
orphanedAttachments.delete(known);
|
if (!orphanedAttachments.delete(known)) {
|
||||||
|
missing += 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
`cleanupOrphanedAttachments: found ${attachments.length} conversation ` +
|
||||||
|
`attachments (${missing} missing), ${orphanedAttachments.size} remain`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// This call is intentionally not awaited. We block the app while running
|
// This call is intentionally not awaited. We block the app while running
|
||||||
|
@ -103,6 +115,8 @@ function deleteOrphanedAttachments({
|
||||||
// This function *can* throw.
|
// This function *can* throw.
|
||||||
async function runWithPossibleException(): Promise<void> {
|
async function runWithPossibleException(): Promise<void> {
|
||||||
let cursor: MessageAttachmentsCursorType | undefined;
|
let cursor: MessageAttachmentsCursorType | undefined;
|
||||||
|
let totalFound = 0;
|
||||||
|
let totalMissing = 0;
|
||||||
try {
|
try {
|
||||||
do {
|
do {
|
||||||
let attachments: ReadonlyArray<string>;
|
let attachments: ReadonlyArray<string>;
|
||||||
|
@ -113,8 +127,12 @@ function deleteOrphanedAttachments({
|
||||||
cursor
|
cursor
|
||||||
));
|
));
|
||||||
|
|
||||||
|
totalFound += attachments.length;
|
||||||
|
|
||||||
for (const known of attachments) {
|
for (const known of attachments) {
|
||||||
orphanedAttachments.delete(known);
|
if (!orphanedAttachments.delete(known)) {
|
||||||
|
totalMissing += 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cursor === undefined) {
|
if (cursor === undefined) {
|
||||||
|
@ -132,6 +150,12 @@ function deleteOrphanedAttachments({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
`cleanupOrphanedAttachments: found ${totalFound} message ` +
|
||||||
|
`attachments, (${totalMissing} missing) ` +
|
||||||
|
`${orphanedAttachments.size} remain`
|
||||||
|
);
|
||||||
|
|
||||||
await deleteAllAttachments({
|
await deleteAllAttachments({
|
||||||
userDataPath,
|
userDataPath,
|
||||||
attachments: Array.from(orphanedAttachments),
|
attachments: Array.from(orphanedAttachments),
|
||||||
|
|
|
@ -5182,7 +5182,7 @@ async function getKnownMessageAttachments(
|
||||||
count += 1;
|
count += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
const done = messages.length < chunkSize;
|
const done = rowids.length < chunkSize;
|
||||||
return {
|
return {
|
||||||
attachments: Array.from(result),
|
attachments: Array.from(result),
|
||||||
cursor: { runId, count, done },
|
cursor: { runId, count, done },
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue