Update message attachment migration

This commit is contained in:
trevor-signal 2025-06-02 17:16:37 -04:00 committed by GitHub
commit 115b79e4ac
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 97 additions and 90 deletions

View file

@ -3,7 +3,7 @@
import { assert } from 'chai';
import { sql, sqlJoin } from '../../sql/util';
import { sql } from '../../sql/util';
import { createDB, explain, updateToVersion } from './helpers';
import type { WritableDB } from '../../sql/Interface';
import { DataWriter } from '../../sql/Server';
@ -29,61 +29,8 @@ describe('SQL/updateToSchemaVersion1360', () => {
);
assert.strictEqual(
details,
'SEARCH message_attachments USING COVERING INDEX message_attachments_messageId (messageId=?)'
'SEARCH message_attachments USING COVERING INDEX sqlite_autoindex_message_attachments_1 (messageId=?)'
);
});
it('uses index to select based on messageId', async () => {
const details = explain(
db,
sql`SELECT * from message_attachments WHERE messageId IN (${sqlJoin(['id1', 'id2'])});`
);
assert.strictEqual(
details,
'SEARCH message_attachments USING INDEX message_attachments_messageId (messageId=?)'
);
});
it('uses index find path with existing plaintextHash', async () => {
const details = explain(
db,
sql`
SELECT path, localKey
FROM message_attachments
WHERE plaintextHash = ${'plaintextHash'}
LIMIT 1;
`
);
assert.strictEqual(
details,
'SEARCH message_attachments USING INDEX message_attachments_plaintextHash (plaintextHash=?)'
);
});
it('uses all path indices to find if path is being referenced', async () => {
const path = 'path';
const details = explain(
db,
sql`
SELECT 1 FROM message_attachments
WHERE
path = ${path} OR
thumbnailPath = ${path} OR
screenshotPath = ${path} OR
backupThumbnailPath = ${path};
`
);
assert.deepStrictEqual(details.split('\n'), [
'MULTI-INDEX OR',
'INDEX 1',
'SEARCH message_attachments USING INDEX message_attachments_path (path=?)',
'INDEX 2',
'SEARCH message_attachments USING INDEX message_attachments_all_thumbnailPath (thumbnailPath=?)',
'INDEX 3',
'SEARCH message_attachments USING INDEX message_attachments_all_screenshotPath (screenshotPath=?)',
'INDEX 4',
'SEARCH message_attachments USING INDEX message_attachments_all_backupThumbnailPath (backupThumbnailPath=?)',
]);
});
});
});