perf: optimize app startup and background lifecycles

This commit is contained in:
inman committed 2026-08-19 00:56:15 +08:00
1 parent 31332f6d76
commit 927e13349b
121 files changed
+4359 -1400

No files matched your search

+20 -3
View File
@@ -17,7 +17,8 @@ const LEGACY_PENDING_STATUSES = new Set([
]);
const LEGACY_RETIRED_MESSAGE = '旧版自动部署任务已停用,请在项目配置中点击“提交审核”重新提交。';
type ProjectStore = Pick<OpencodeProjectStore, 'listProjects'>;
type ProjectStore = Pick<OpencodeProjectStore, 'listProjects'>
& Partial<Pick<OpencodeProjectStore, 'getActiveProject'>>;
type SubmittedBindingInput = {
appId: string;
@@ -211,8 +212,24 @@ export function createWorksSubmissionBindingStore(projectStore: ProjectStore) {
return project ? readWorksSubmissionBinding(project.path, project.id) : null;
}
async function start(): Promise<void> {
for (const project of await projectStore.listProjects()) {
async function start(projectId?: string | null): Promise<void> {
// Migration is deliberately scoped to the active project. The previous
// implementation enumerated every remembered project during app startup,
// which turned a compatibility read into a cold-start I/O spike. Tests
// and legacy stores that expose only listProjects retain a safe
// single-project fallback.
let projects: Awaited<ReturnType<ProjectStore['listProjects']>>;
if (projectId) {
projects = (await projectStore.listProjects()).filter((project) => project.id === projectId);
} else if (projectStore.getActiveProject) {
const activeProject = await projectStore.getActiveProject();
projects = activeProject ? [activeProject] : [];
} else {
const listedProjects = await projectStore.listProjects();
projects = listedProjects.length === 1 ? listedProjects : [];
}
for (const project of projects) {
try {
await readWorksSubmissionBinding(project.path, project.id);
} catch (error) {