Order unprocessed envelopes by receivedAtCounter
This commit is contained in:
parent
924c271b13
commit
6aeddb9301
6 changed files with 50 additions and 14 deletions
|
@ -3254,7 +3254,7 @@ async function getAllUnprocessedAndIncrementAttempts(): Promise<
|
||||||
`
|
`
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM unprocessed
|
FROM unprocessed
|
||||||
ORDER BY timestamp ASC;
|
ORDER BY receivedAtCounter ASC;
|
||||||
`
|
`
|
||||||
)
|
)
|
||||||
.all();
|
.all();
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
// Copyright 2022 Signal Messenger, LLC
|
||||||
|
// SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
|
import type { Database } from 'better-sqlite3';
|
||||||
|
|
||||||
|
import type { LoggerType } from '../../types/Logging';
|
||||||
|
|
||||||
|
export default function updateToSchemaVersion59(
|
||||||
|
currentVersion: number,
|
||||||
|
db: Database,
|
||||||
|
logger: LoggerType
|
||||||
|
): void {
|
||||||
|
if (currentVersion >= 59) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
db.transaction(() => {
|
||||||
|
db.exec(
|
||||||
|
`
|
||||||
|
CREATE INDEX unprocessed_byReceivedAtCounter ON unprocessed
|
||||||
|
(receivedAtCounter)
|
||||||
|
`
|
||||||
|
);
|
||||||
|
|
||||||
|
db.pragma('user_version = 59');
|
||||||
|
})();
|
||||||
|
logger.info('updateToSchemaVersion59: success!');
|
||||||
|
}
|
|
@ -5,12 +5,13 @@ import type { Database } from 'better-sqlite3';
|
||||||
|
|
||||||
import type { LoggerType } from '../../types/Logging';
|
import type { LoggerType } from '../../types/Logging';
|
||||||
|
|
||||||
export default function updateToSchemaVersion59(
|
// TODO: DESKTOP-3694
|
||||||
|
export default function updateToSchemaVersion60(
|
||||||
currentVersion: number,
|
currentVersion: number,
|
||||||
db: Database,
|
db: Database,
|
||||||
logger: LoggerType
|
logger: LoggerType
|
||||||
): void {
|
): void {
|
||||||
if (currentVersion >= 59) {
|
if (currentVersion >= 60) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,17 +24,17 @@ export default function updateToSchemaVersion59(
|
||||||
ON messages
|
ON messages
|
||||||
(
|
(
|
||||||
conversationId,
|
conversationId,
|
||||||
storyId
|
storyId,
|
||||||
expirationStartTimestamp,
|
expirationStartTimestamp,
|
||||||
expireTimer,
|
expireTimer,
|
||||||
received_at,
|
received_at
|
||||||
)
|
)
|
||||||
WHERE isStory IS 0 AND type IS 'incoming';
|
WHERE isStory IS 0 AND type IS 'incoming';
|
||||||
`
|
`
|
||||||
);
|
);
|
||||||
|
|
||||||
db.pragma('user_version = 59');
|
db.pragma('user_version = 60');
|
||||||
})();
|
})();
|
||||||
|
|
||||||
logger.info('updateToSchemaVersion59: success!');
|
logger.info('updateToSchemaVersion60: success!');
|
||||||
}
|
}
|
|
@ -34,6 +34,8 @@ import updateToSchemaVersion55 from './55-report-message-aci';
|
||||||
import updateToSchemaVersion56 from './56-add-unseen-to-message';
|
import updateToSchemaVersion56 from './56-add-unseen-to-message';
|
||||||
import updateToSchemaVersion57 from './57-rm-message-history-unsynced';
|
import updateToSchemaVersion57 from './57-rm-message-history-unsynced';
|
||||||
import updateToSchemaVersion58 from './58-update-unread';
|
import updateToSchemaVersion58 from './58-update-unread';
|
||||||
|
import updateToSchemaVersion59 from './59-unprocessed-received-at-counter-index';
|
||||||
|
import updateToSchemaVersion60 from './60-update-expiring-index';
|
||||||
|
|
||||||
function updateToSchemaVersion1(
|
function updateToSchemaVersion1(
|
||||||
currentVersion: number,
|
currentVersion: number,
|
||||||
|
@ -1931,6 +1933,8 @@ export const SCHEMA_VERSIONS = [
|
||||||
updateToSchemaVersion56,
|
updateToSchemaVersion56,
|
||||||
updateToSchemaVersion57,
|
updateToSchemaVersion57,
|
||||||
updateToSchemaVersion58,
|
updateToSchemaVersion58,
|
||||||
|
updateToSchemaVersion59,
|
||||||
|
updateToSchemaVersion60,
|
||||||
];
|
];
|
||||||
|
|
||||||
export function updateSchema(db: Database, logger: LoggerType): void {
|
export function updateSchema(db: Database, logger: LoggerType): void {
|
||||||
|
|
|
@ -1658,7 +1658,7 @@ describe('SignalProtocolStore', () => {
|
||||||
id: '0-dropped',
|
id: '0-dropped',
|
||||||
envelope: 'old envelope',
|
envelope: 'old envelope',
|
||||||
timestamp: NOW - 2 * durations.MONTH,
|
timestamp: NOW - 2 * durations.MONTH,
|
||||||
receivedAtCounter: 0,
|
receivedAtCounter: -1,
|
||||||
version: 2,
|
version: 2,
|
||||||
attempts: 0,
|
attempts: 0,
|
||||||
}),
|
}),
|
||||||
|
@ -1666,7 +1666,7 @@ describe('SignalProtocolStore', () => {
|
||||||
id: '2-two',
|
id: '2-two',
|
||||||
envelope: 'second',
|
envelope: 'second',
|
||||||
timestamp: NOW + 2,
|
timestamp: NOW + 2,
|
||||||
receivedAtCounter: 0,
|
receivedAtCounter: 1,
|
||||||
version: 2,
|
version: 2,
|
||||||
attempts: 0,
|
attempts: 0,
|
||||||
}),
|
}),
|
||||||
|
@ -1674,7 +1674,7 @@ describe('SignalProtocolStore', () => {
|
||||||
id: '3-three',
|
id: '3-three',
|
||||||
envelope: 'third',
|
envelope: 'third',
|
||||||
timestamp: NOW + 3,
|
timestamp: NOW + 3,
|
||||||
receivedAtCounter: 0,
|
receivedAtCounter: 2,
|
||||||
version: 2,
|
version: 2,
|
||||||
attempts: 0,
|
attempts: 0,
|
||||||
}),
|
}),
|
||||||
|
@ -1691,7 +1691,8 @@ describe('SignalProtocolStore', () => {
|
||||||
const items = await store.getAllUnprocessedAndIncrementAttempts();
|
const items = await store.getAllUnprocessedAndIncrementAttempts();
|
||||||
assert.strictEqual(items.length, 3);
|
assert.strictEqual(items.length, 3);
|
||||||
|
|
||||||
// they are in the proper order because the collection comparator is 'timestamp'
|
// they are in the proper order because the collection comparator is
|
||||||
|
// 'receivedAtCounter'
|
||||||
assert.strictEqual(items[0].envelope, 'first');
|
assert.strictEqual(items[0].envelope, 'first');
|
||||||
assert.strictEqual(items[1].envelope, 'second');
|
assert.strictEqual(items[1].envelope, 'second');
|
||||||
assert.strictEqual(items[2].envelope, 'third');
|
assert.strictEqual(items[2].envelope, 'third');
|
||||||
|
|
|
@ -2287,9 +2287,9 @@ describe('SQL migrations test', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('updateToSchemaVersion59', () => {
|
describe('updateToSchemaVersion60', () => {
|
||||||
it('updates index to make query efficient', () => {
|
it('updates index to make query efficient', () => {
|
||||||
updateToVersion(47);
|
updateToVersion(60);
|
||||||
|
|
||||||
const items = db
|
const items = db
|
||||||
.prepare(
|
.prepare(
|
||||||
|
@ -2320,7 +2320,9 @@ describe('SQL migrations test', () => {
|
||||||
assert.notInclude(detail, 'SCAN');
|
assert.notInclude(detail, 'SCAN');
|
||||||
assert.include(
|
assert.include(
|
||||||
detail,
|
detail,
|
||||||
'SEARCH messages USING INDEX expiring_message_by_conversation_and_received_at (expirationStartTimestamp=? AND expireTimer>?)'
|
'SEARCH messages USING INDEX ' +
|
||||||
|
'expiring_message_by_conversation_and_received_at ' +
|
||||||
|
'(conversationId=? AND storyId=?)'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue