fix: better rebuilding of database

This commit is contained in:
2026-02-11 06:05:18 +01:00
parent 77e117ae06
commit b7b1a4881f
7 changed files with 102 additions and 27 deletions

View File

@@ -897,6 +897,9 @@ export class PostEngine extends EventEmitter {
onProgress(0, 'Deleting existing posts for project...');
// Notify UI that rebuild is starting so it can clear the list
this.emit('rebuildStarted');
// Delete all posts for the current project - clean slate rebuild
const existingPosts = await db.select({ id: posts.id }).from(posts).where(eq(posts.projectId, this.currentProjectId)).all();
if (existingPosts.length > 0) {
@@ -951,7 +954,7 @@ export class PostEngine extends EventEmitter {
const filePath = mdFiles[i];
const fileName = path.basename(filePath);
onProgress(10 + (80 * (i / mdFiles.length)), `Processing ${fileName}...`);
onProgress(10 + (80 * (i / mdFiles.length)), `Processing ${i + 1}/${mdFiles.length}: ${fileName}`);
const postData = await this.readPostFile(filePath);
@@ -1007,6 +1010,11 @@ export class PostEngine extends EventEmitter {
}
}
}
// Yield to event loop periodically so the window stays responsive
if (i % 10 === 0) {
await new Promise(resolve => setImmediate(resolve));
}
}
onProgress(100, 'Database rebuild complete');