feat: add async SQLite on Node 24 and improve messaging diagnostics (#520)

Move database work off the main thread on Node.js 24 and improve message handling and runtime diagnostics.

Preserve migration, restart, and concurrency coverage with the async SQLite driver.
This commit is contained in:
MliKiowa authored and GitHub committed 2026-10-13 10:12:47 +08:00
1 parent 20f48d11ec
commit c7428363cb
170 files changed
+7748 -3913

No files matched your search

@@ -17,7 +17,7 @@ const SELF_ID = 3961840894;
const PEER_ID = 2705892349;
function productionResolver(store: MessageStore): ConverterContext['messageIdResolver'] {
return (isGroup, sessionId, sequence, eventName, timestamp, replyElements) => {
return async (isGroup, sessionId, sequence, eventName, timestamp, replyElements) => {
const resolvedEventName = eventName || (isGroup ? 'group_message' : PRIVATE_MESSAGE_EVENT);
if (
@@ -26,7 +26,7 @@ function productionResolver(store: MessageStore): ConverterContext['messageIdRes
(resolvedEventName === PRIVATE_MESSAGE_EVENT ||
resolvedEventName === PRIVATE_SENT_MESSAGE_EVENT)
) {
const storedId = store.resolvePrivateReplyMessageId(
const storedId = await store.resolvePrivateReplyMessageId(
sessionId,
sequence,
resolvedEventName === PRIVATE_SENT_MESSAGE_EVENT,
@@ -53,13 +53,14 @@ describe('private reply id matches send receipt (#417, #433)', () => {
let dir: string;
let store: MessageStore;
beforeEach(() => {
beforeEach(async () => {
dir = fs.mkdtempSync(path.join(os.tmpdir(), 'sl-reply-id-'));
store = new MessageStore(path.join(dir, 'messages.db'));
await store.initialization;
});
afterEach(() => {
store.close();
afterEach(async () => {
await store.close();
fs.rmSync(dir, { recursive: true, force: true });
});
@@ -70,7 +71,7 @@ describe('private reply id matches send receipt (#417, #433)', () => {
[101, [{ type: 'text', data: { text: 'the quoted text' } }]],
[102, [{ type: 'record', data: { file: 'voice.amr' } }]],
] as const) {
store.storeMeta(id, {
await store.storeMeta(id, {
isGroup: false,
targetId: PEER_ID,
sequence: id,
@@ -81,7 +82,7 @@ describe('private reply id matches send receipt (#417, #433)', () => {
random: id,
timestamp: sentAt,
});
store.storeEvent(id, false, PEER_ID, id, PRIVATE_NT_MESSAGE_EVENT, {
await store.storeEvent(id, false, PEER_ID, id, PRIVATE_NT_MESSAGE_EVENT, {
time: sentAt,
post_type: 'message_sent',
message_type: 'private',
@@ -90,14 +91,15 @@ describe('private reply id matches send receipt (#417, #433)', () => {
});
}
store.close();
await store.close();
store = new MessageStore(path.join(dir, 'messages.db'));
await store.initialization;
const ctx: ConverterContext = {
selfId: SELF_ID,
imageUrlResolver: null,
mediaUrlResolver: null,
mediaSegmentSink: null,
messageIdResolver: productionResolver(store),
messageIdResolver: await productionResolver(store),
};
const event: FriendMessage = {
kind: 'friend_message',
@@ -152,7 +154,7 @@ describe('private reply id matches send receipt (#417, #433)', () => {
hashMessageIdInt32(fixture.quoteSeq, PEER_ID, PRIVATE_SENT_MESSAGE_EVENT),
);
store.storeMeta(sendId, {
await store.storeMeta(sendId, {
isGroup: false,
targetId: PEER_ID,
sequence: fixture.ntSeq,
@@ -169,7 +171,7 @@ describe('private reply id matches send receipt (#417, #433)', () => {
imageUrlResolver: null,
mediaUrlResolver: null,
mediaSegmentSink: null,
messageIdResolver: productionResolver(store),
messageIdResolver: await productionResolver(store),
};
const event: FriendMessage = {
@@ -211,7 +213,7 @@ describe('private reply id matches send receipt (#417, #433)', () => {
const sendId = hashMessageIdInt32(ntSeq, PEER_ID, PRIVATE_NT_MESSAGE_EVENT);
expect(sendId).not.toBe(hashMessageIdInt32(quoteSeq, PEER_ID, PRIVATE_SENT_MESSAGE_EVENT));
store.storeMeta(sendId, {
await store.storeMeta(sendId, {
isGroup: false,
targetId: PEER_ID,
sequence: ntSeq,
@@ -228,7 +230,7 @@ describe('private reply id matches send receipt (#417, #433)', () => {
imageUrlResolver: null,
mediaUrlResolver: null,
mediaSegmentSink: null,
messageIdResolver: productionResolver(store),
messageIdResolver: await productionResolver(store),
};
const event: FriendMessage = {
@@ -268,7 +270,7 @@ describe('private reply id matches send receipt (#417, #433)', () => {
const quoteTime = sentAt + 2;
const sendId = hashMessageIdInt32(ntSeq, PEER_ID, PRIVATE_NT_MESSAGE_EVENT);
store.storeMeta(sendId, {
await store.storeMeta(sendId, {
isGroup: false,
targetId: PEER_ID,
sequence: ntSeq,
@@ -285,7 +287,7 @@ describe('private reply id matches send receipt (#417, #433)', () => {
imageUrlResolver: null,
mediaUrlResolver: null,
mediaSegmentSink: null,
messageIdResolver: productionResolver(store),
messageIdResolver: await productionResolver(store),
};
const event: FriendMessage = {