mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-03 13:22:14 +00:00
perf(memory): lazy-load matrix shared client creation
This commit is contained in:
@@ -3,9 +3,21 @@ import type { CoreConfig } from "../../types.js";
|
||||
import type { MatrixClient } from "../sdk.js";
|
||||
import { LogService } from "../sdk/logger.js";
|
||||
import { resolveMatrixAuth, resolveMatrixAuthContext } from "./config.js";
|
||||
import { createMatrixClient } from "./create-client.js";
|
||||
import type { MatrixAuth } from "./types.js";
|
||||
|
||||
type MatrixCreateClientDeps = {
|
||||
createMatrixClient: typeof import("./create-client.js").createMatrixClient;
|
||||
};
|
||||
|
||||
let matrixCreateClientDepsPromise: Promise<MatrixCreateClientDeps> | undefined;
|
||||
|
||||
async function loadMatrixCreateClientDeps(): Promise<MatrixCreateClientDeps> {
|
||||
matrixCreateClientDepsPromise ??= import("./create-client.js").then((runtime) => ({
|
||||
createMatrixClient: runtime.createMatrixClient,
|
||||
}));
|
||||
return await matrixCreateClientDepsPromise;
|
||||
}
|
||||
|
||||
type SharedMatrixClientState = {
|
||||
client: MatrixClient;
|
||||
key: string;
|
||||
@@ -38,6 +50,7 @@ async function createSharedMatrixClient(params: {
|
||||
auth: MatrixAuth;
|
||||
timeoutMs?: number;
|
||||
}): Promise<SharedMatrixClientState> {
|
||||
const { createMatrixClient } = await loadMatrixCreateClientDeps();
|
||||
const client = await createMatrixClient({
|
||||
homeserver: params.auth.homeserver,
|
||||
userId: params.auth.userId,
|
||||
|
||||
Reference in New Issue
Block a user