Harden architecture hot paths
This commit is contained in:
@@ -116,7 +116,7 @@ async function getTaskCounts(projectPath: string): Promise<Record<string, number
|
||||
try {
|
||||
const store = new TaskStore(projectPath);
|
||||
await store.init();
|
||||
const tasks = await store.listTasks();
|
||||
const tasks = await store.listTasks({ slim: true });
|
||||
|
||||
const counts: Record<string, number> = {};
|
||||
for (const col of COLUMNS) {
|
||||
|
||||
@@ -108,6 +108,18 @@ export async function cleanupMergedTaskArtifacts(cwd: string, task: Pick<TaskDet
|
||||
}
|
||||
}
|
||||
|
||||
async function finalizePullRequestMerge(
|
||||
store: TaskStore,
|
||||
cwd: string,
|
||||
task: TaskDetail,
|
||||
prInfo: PrInfo,
|
||||
): Promise<void> {
|
||||
await cleanupMergedTaskArtifacts(cwd, task);
|
||||
await store.updateTask(task.id, { status: null, mergeRetries: 0 });
|
||||
await store.moveTask(task.id, "done");
|
||||
await store.logEntry(task.id, "Pull request merged", `PR #${prInfo.number}: ${prInfo.url}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Result of processing a PR merge task.
|
||||
* - "waiting": PR exists but not ready to merge (checks pending, reviews needed)
|
||||
@@ -188,10 +200,7 @@ export async function processPullRequestMergeTask(
|
||||
await store.updatePrInfo(task.id, refreshedPrInfo);
|
||||
|
||||
if (mergeStatus.prInfo.status === "merged") {
|
||||
await cleanupMergedTaskArtifacts(cwd, task);
|
||||
await store.moveTask(task.id, "done");
|
||||
await store.updateTask(task.id, { status: null, mergeRetries: 0 });
|
||||
await store.logEntry(task.id, "Pull request merged", `PR #${prInfo.number}: ${prInfo.url}`);
|
||||
await finalizePullRequestMerge(store, cwd, task, prInfo);
|
||||
return "merged";
|
||||
}
|
||||
|
||||
@@ -207,9 +216,6 @@ export async function processPullRequestMergeTask(
|
||||
await store.updateTask(task.id, { status: "merging-pr" });
|
||||
const mergedPr = await github.mergePr({ number: prInfo.number, method: "squash" });
|
||||
await store.updatePrInfo(task.id, { ...mergedPr, lastCheckedAt: new Date().toISOString() });
|
||||
await cleanupMergedTaskArtifacts(cwd, task);
|
||||
await store.moveTask(task.id, "done");
|
||||
await store.updateTask(task.id, { status: null, mergeRetries: 0 });
|
||||
await store.logEntry(task.id, "Pull request merged", `PR #${mergedPr.number}: ${mergedPr.url}`);
|
||||
await finalizePullRequestMerge(store, cwd, task, mergedPr);
|
||||
return "merged";
|
||||
}
|
||||
|
||||
@@ -161,7 +161,7 @@ export async function runTaskCreate(descriptionArg?: string, attachFiles?: strin
|
||||
export async function runTaskList(projectName?: string) {
|
||||
const projectContext = await getProjectContext(projectName);
|
||||
const store = projectContext?.store ?? await getStore(projectName);
|
||||
const tasks = await store.listTasks();
|
||||
const tasks = await store.listTasks({ slim: true });
|
||||
|
||||
if (tasks.length === 0) {
|
||||
console.log("\n No tasks yet. Create one with: fn task create\n");
|
||||
@@ -711,7 +711,7 @@ export async function runTaskImportGitHubInteractive(
|
||||
console.log(`\n Fetching issues from ${owner}/${repo}...\n`);
|
||||
|
||||
const store = await getStore(projectName);
|
||||
const existingTasks = await store.listTasks();
|
||||
const existingTasks = await store.listTasks({ slim: true });
|
||||
|
||||
// Build a set of already-imported issue URLs
|
||||
const importedUrls = new Map<string, string>();
|
||||
@@ -899,7 +899,7 @@ export async function runTaskImportFromGitHub(
|
||||
console.log(`\n Importing issues from ${owner}/${repo}...\n`);
|
||||
|
||||
const store = await getStore(projectName);
|
||||
const existingTasks = await store.listTasks();
|
||||
const existingTasks = await store.listTasks({ slim: true });
|
||||
|
||||
// Build a set of already-imported issue URLs
|
||||
const importedUrls = new Map<string, string>();
|
||||
|
||||
@@ -290,7 +290,7 @@ export default function kbExtension(pi: ExtensionAPI) {
|
||||
|
||||
async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
|
||||
const store = await getStore(ctx.cwd);
|
||||
const tasks = await store.listTasks();
|
||||
const tasks = await store.listTasks({ slim: true });
|
||||
|
||||
if (tasks.length === 0) {
|
||||
return {
|
||||
@@ -763,7 +763,7 @@ export default function kbExtension(pi: ExtensionAPI) {
|
||||
}
|
||||
|
||||
const store = await getStore(ctx.cwd);
|
||||
const existingTasks = await store.listTasks();
|
||||
const existingTasks = await store.listTasks({ slim: true });
|
||||
const createdTasks: Array<{ id: string; title: string }> = [];
|
||||
|
||||
for (const issue of issues) {
|
||||
@@ -841,7 +841,7 @@ export default function kbExtension(pi: ExtensionAPI) {
|
||||
|
||||
// Check if already imported
|
||||
const store = await getStore(ctx.cwd);
|
||||
const existingTasks = await store.listTasks();
|
||||
const existingTasks = await store.listTasks({ slim: true });
|
||||
const sourceUrl = issue.html_url;
|
||||
|
||||
for (const task of existingTasks) {
|
||||
@@ -936,7 +936,7 @@ export default function kbExtension(pi: ExtensionAPI) {
|
||||
|
||||
// Check which issues are already imported
|
||||
const store = await getStore(ctx.cwd);
|
||||
const existingTasks = await store.listTasks();
|
||||
const existingTasks = await store.listTasks({ slim: true });
|
||||
const importedUrls = new Set<string>();
|
||||
|
||||
for (const task of existingTasks) {
|
||||
|
||||
@@ -685,7 +685,7 @@ export async function getProjectInfo(name?: string): Promise<{
|
||||
const health = await central.getProjectHealth(project.projectId);
|
||||
|
||||
// Get task counts by column
|
||||
const tasks = await project.store.listTasks();
|
||||
const tasks = await project.store.listTasks({ slim: true });
|
||||
const taskCounts: Record<string, number> = {};
|
||||
for (const task of tasks) {
|
||||
taskCounts[task.column] = (taskCounts[task.column] || 0) + 1;
|
||||
@@ -791,7 +791,7 @@ export async function getProjectsWithStatus(): Promise<
|
||||
try {
|
||||
const store = new (await import("@fusion/core")).TaskStore(project.path);
|
||||
await store.init();
|
||||
const tasks = await store.listTasks();
|
||||
const tasks = await store.listTasks({ slim: true });
|
||||
taskCount = tasks.length;
|
||||
} catch {
|
||||
// If we can't read tasks, just report 0
|
||||
@@ -848,7 +848,7 @@ export async function getProjectTaskCounts(
|
||||
|
||||
if (!taskStore) return {};
|
||||
|
||||
const tasks = await taskStore.listTasks();
|
||||
const tasks = await taskStore.listTasks({ slim: true });
|
||||
const counts: Record<string, number> = {};
|
||||
|
||||
for (const task of tasks) {
|
||||
|
||||
Reference in New Issue
Block a user