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

@@ -56,10 +56,6 @@ export function findDatalineDeviceByTerType(terType: number): DatalineDeviceCont
return BY_TER.get(terType);
}
export function isDatalineDeviceUin(uin: number): boolean {
return BY_UIN.has(uin);
}
export function datalineFriendListEntries(): DatalineFriendEntry[] {
return DATALINE_DEVICES.map((device) => ({
user_id: device.uin,
@@ -68,14 +64,6 @@ export function datalineFriendListEntries(): DatalineFriendEntry[] {
}));
}
export function appendDatalineFriendEntries<T extends { user_id: number }>(
friends: readonly T[],
): Array<T | DatalineFriendEntry> {
const occupied = new Set(friends.map((friend) => friend.user_id));
const extras = datalineFriendListEntries().filter((entry) => !occupied.has(entry.user_id));
return extras.length === 0 ? [...friends] : [...friends, ...extras];
}
export function appIdForTerType(terType: number): number {
return terType === DATALINE_TER_PC ? 1 : 1001;
}
+4 -4
View File
@@ -11,7 +11,7 @@ import type { JsonObject, JsonValue } from '@snowluma/common/json';
* callers pass it through with zero adaptation.
*/
export interface ReplyEventLookup {
findEvent(messageId: number): JsonObject | null;
findEvent(messageId: number): JsonObject | null | Promise<JsonObject | null>;
}
const MAX_TEXT_PREVIEW = 50;
@@ -282,17 +282,17 @@ function readTitle(node: unknown): string | null {
* and a 1-level peek catches 90% of real-world "what's this referring
* to" questions.
*/
export function formatReply(
export async function formatReply(
messageStore: ReplyEventLookup,
identity: IdentityService,
replyId: number,
): string {
): Promise<string> {
try {
if (!replyId) {
return '[回复:0]';
}
const event = messageStore.findEvent(replyId);
const event = await messageStore.findEvent(replyId);
if (!event) {
return `[回复:${replyId}]`;
File diff suppressed because it is too large. Load diff
+1 -12
View File
@@ -111,15 +111,6 @@ export function decompressData(
return { ok: true, text: Buffer.from(data).toString('utf8'), outputBytes: data.length };
}
export function parseU64OrZero(value: string): number {
if (!value) {
return 0;
}
const n = parseInt(value, 10);
return isNaN(n) ? 0 : n;
}
/** Sync Identity lookup. Miss is unresolved (0). Decoder must not invent a UIN. */
export function resolveUidToUin(identity: IdentityService, groupId: number, uid: string): number {
if (!uid) {
@@ -203,9 +194,7 @@ export function decodeNestedOperatorUid(bytes: Uint8Array, context: string): str
} catch (error) {
throw new Error(
`${context} operator info decode failed (${describeOperatorBytes(bytes)})`,
{
cause: error,
},
{ cause: error },
);
}