fix: merge tags did not update disc

This commit is contained in:
2026-02-15 21:08:41 +01:00
parent 97c0ee6877
commit 8b70214d15
3 changed files with 49 additions and 0 deletions

View File

@@ -519,6 +519,38 @@ export class PostEngine extends EventEmitter {
return this.dbRowToPostData(dbPost, '');
}
/**
* Sync a published post's file with current database metadata (e.g., tags).
* This is needed when metadata changes outside of normal post editing flow,
* such as tag merge or rename operations.
*
* @param postId - The post ID to sync
* @returns true if file was updated, false if post is not published or doesn't exist
*/
async syncPublishedPostFile(postId: string): Promise<boolean> {
const db = getDatabase().getLocal();
const dbPost = await db.select().from(posts).where(eq(posts.id, postId)).get();
if (!dbPost || !dbPost.filePath) {
// Not a published post or doesn't exist
return false;
}
// Read content from the existing file
const fileData = await this.readPostFile(dbPost.filePath);
if (!fileData) {
return false;
}
// Build the full post data with DB metadata (tags) and file content
const postData = this.dbRowToPostData(dbPost, fileData.content);
// Re-write the file with updated metadata
await this.writePostFile(postData);
return true;
}
async getAllPosts(options?: PaginationOptions): Promise<PaginatedResult<PostData>> {
const db = getDatabase().getLocal();
const limit = options?.limit ?? 500;

View File

@@ -7,6 +7,7 @@ import { eq, and, asc, sql, like } from 'drizzle-orm';
import { getDatabase } from '../database';
import { tags, posts } from '../database/schema';
import { taskManager } from './TaskManager';
import { getPostEngine } from './PostEngine';
/**
* Tag data stored in the database
@@ -379,6 +380,9 @@ export class TagEngine extends EventEmitter {
})
.where(eq(posts.id, postId));
// Sync published post's file with updated tags
await getPostEngine().syncPublishedPostFile(postId);
updated++;
onProgress((updated / total) * 80, `Updated ${updated}/${total} posts...`);
}
@@ -486,6 +490,9 @@ export class TagEngine extends EventEmitter {
})
.where(eq(posts.id, postId));
// Sync published post's file with updated tags
await getPostEngine().syncPublishedPostFile(postId);
totalPostsUpdated++;
}
}
@@ -601,6 +608,9 @@ export class TagEngine extends EventEmitter {
})
.where(eq(posts.id, postId));
// Sync published post's file with updated tags
await getPostEngine().syncPublishedPostFile(postId);
updated++;
onProgress((updated / total) * 80, `Updated ${updated}/${total} posts...`);
}