perf(client): defer chat persistence dependencies

This commit is contained in:
2026-07-15 17:58:06 +08:00
parent 86ffbbcdbc
commit 05ca15be48
15 changed files with 115 additions and 81 deletions
+5 -3
View File
@@ -1,7 +1,7 @@
"use client";
import type { ChatMediaKind } from "@/data/dto/chat";
import { getChatRepository } from "@/data/repositories/chat_repository";
import { loadChatRepository } from "@/data/repositories/chat_repository_loader";
import { Result, type Result as ResultT } from "@/utils/result";
import { localChatMediaRowToBlob } from "./chat_media_blob";
@@ -19,7 +19,8 @@ export interface CacheRemoteChatMediaBlobInput
export async function resolveCachedChatMediaBlob(
input: ResolveCachedChatMediaBlobInput,
): Promise<ResultT<Blob | null>> {
const result = await getChatRepository().getCachedMedia(input);
const repository = await loadChatRepository();
const result = await repository.getCachedMedia(input);
if (Result.isErr(result)) return result;
if (!result.data) return Result.ok(null);
return Result.ok(localChatMediaRowToBlob(result.data));
@@ -28,7 +29,8 @@ export async function resolveCachedChatMediaBlob(
export async function cacheRemoteChatMediaBlob(
input: CacheRemoteChatMediaBlobInput,
): Promise<ResultT<Blob>> {
const result = await getChatRepository().cacheRemoteMedia(input);
const repository = await loadChatRepository();
const result = await repository.cacheRemoteMedia(input);
if (Result.isErr(result)) return result;
const blob = localChatMediaRowToBlob(result.data);
if (!blob) return Result.err(new Error("Cached media has no readable bytes."));
+3 -2
View File
@@ -1,4 +1,4 @@
import { getChatRepository } from "@/data/repositories/chat_repository";
import { loadChatRepository } from "@/data/repositories/chat_repository_loader";
import {
resolveChatCacheOwnerKey,
type ChatCacheIdentityResolver,
@@ -44,7 +44,8 @@ export async function loadSplashLatestMessagePreview({
export async function fetchSplashLatestMessagePreview(): Promise<
ResultT<string | null>
> {
const result = await getChatRepository().getHistory(1, 0);
const repository = await loadChatRepository();
const result = await repository.getHistory(1, 0);
if (Result.isErr(result)) return Result.err(result.error);
return Result.ok(getLatestSplashMessagePreview(result.data.messages));