Sync category records during emoji category updates#7
Sync category records during emoji category updates#7dingyi222666 merged 2 commits intoChatLunaLab:mainfrom
Conversation
📝 WalkthroughWalkthroughNormalizes category names by trimming inputs across service methods, prevents creation of empty categories, reuses or auto-creates categories as needed, and ensures emoji count recalculations and database updates when categories change or are imported. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! 此拉取请求旨在解决 WebUI 中表情符号分类更新与数据库不同步的问题。通过增强分类添加、表情符号分类更新和分类表情符号计数更新的逻辑,确保了数据的一致性,并改进了对分类名称的验证和处理。 Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
这次的 Pull Request 修复了 WebUI 修改表情分类时数据库同步的问题,做得很好。主要的改动包括:
addCategory方法现在能处理已存在分类的情况,并可以更新其描述。updateEmojiCategory方法在更新表情分类后,会正确地同步更新旧分类和新分类的表情数量。updateCategoryEmojiCount方法现在能够自动创建尚不存在的分类。
这些改动增强了系统的健壮性和数据一致性。我发现一处可以优化的地方,即在 updateCategoryEmojiCount 中创建新分类时可以避免一次额外的数据库写入,具体建议见评论。
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/service.ts`:
- Around line 1422-1427: The count is wrong when stored emoji.category contains
surrounding whitespace: use a trimmed comparison when computing counts by
normalizing stored categories before matching (e.g., in the filter over
this._emojiStorage, compare emoji.category.trim() to normalizedCategoryName) and
apply the same normalization to the other block referenced (lines 1429–1435)
that updates/creates categories so all category comparisons and updates use
trimmed values. Ensure you only adjust comparisons/updates (not DB schema) and
reference normalizedCategoryName and this._emojiStorage / emoji.category when
making the change.
Ensure stored emoji.category and category.name values are trimmed when comparing against normalizedCategoryName to prevent whitespace mismatches that cause incorrect emoji counts and failed category lookups.
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/service.ts`:
- Around line 1118-1119: The early-exit comparison uses the raw emoji.category
(const oldCategory = emoji.category) which may include leading/trailing
whitespace and falsely fail equality against nextCategory; change the comparison
to use a trimmed oldCategory (e.g., use emoji.category?.trim() or set const
oldCategory = (emoji.category || '').trim()) or trim both sides before comparing
so the early return if (oldCategory === nextCategory) correctly avoids redundant
DB updates and count recalculations in the function handling the emoji update.
- Line 874: getCategoryByName currently compares stored category names directly
(cat.name === name) which fails if stored names have extra whitespace; modify
getCategoryByName to compare trimmed values (e.g., compare cat.name?.trim() ===
name?.trim()) so lookups match regardless of leading/trailing spaces, mirroring
the trimmed comparison used in updateCategoryEmojiCount and ensuring
null/undefined safety.
| throw new Error('分类名称不能为空') | ||
| } | ||
|
|
||
| const existingCategory = await this.getCategoryByName(categoryName) |
There was a problem hiding this comment.
getCategoryByName does not trim stored category names, causing lookup inconsistency.
The getCategoryByName method (line 945-949) compares cat.name === name without trimming stored values. If any stored category name contains leading/trailing whitespace, lookups will fail even when categoryName is correctly trimmed here. This is inconsistent with the trimmed comparison now used in updateCategoryEmojiCount (line 1430).
Consider updating getCategoryByName to use trimmed comparison:
Proposed fix
async getCategoryByName(name: string): Promise<Category | null> {
+ const normalizedName = name.trim()
return (
- Object.values(this._categories).find((cat) => cat.name === name) ||
+ Object.values(this._categories).find((cat) => cat.name.trim() === normalizedName) ||
null
)
}🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/service.ts` at line 874, getCategoryByName currently compares stored
category names directly (cat.name === name) which fails if stored names have
extra whitespace; modify getCategoryByName to compare trimmed values (e.g.,
compare cat.name?.trim() === name?.trim()) so lookups match regardless of
leading/trailing spaces, mirroring the trimmed comparison used in
updateCategoryEmojiCount and ensuring null/undefined safety.
| const oldCategory = emoji.category | ||
| if (oldCategory === nextCategory) return true |
There was a problem hiding this comment.
Early-exit comparison uses untrimmed oldCategory, may cause redundant DB writes.
If an emoji's stored category contains trailing/leading whitespace (e.g., "Memes "), and the user submits the same category trimmed ("Memes"), the comparison oldCategory === nextCategory will be false, triggering an unnecessary update and count recalculations.
Consider trimming oldCategory for the comparison:
Proposed fix
const oldCategory = emoji.category
- if (oldCategory === nextCategory) return true
+ if (oldCategory.trim() === nextCategory) return true📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const oldCategory = emoji.category | |
| if (oldCategory === nextCategory) return true | |
| const oldCategory = emoji.category | |
| if (oldCategory.trim() === nextCategory) return true |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/service.ts` around lines 1118 - 1119, The early-exit comparison uses the
raw emoji.category (const oldCategory = emoji.category) which may include
leading/trailing whitespace and falsely fail equality against nextCategory;
change the comparison to use a trimmed oldCategory (e.g., use
emoji.category?.trim() or set const oldCategory = (emoji.category || '').trim())
or trim both sides before comparing so the early return if (oldCategory ===
nextCategory) correctly avoids redundant DB updates and count recalculations in
the function handling the emoji update.
|
忘记看了,今晚看一下 |
|
又忘记了,明日... |
Fix #5 WebUI修改分类联动数据库的问题
Summary by CodeRabbit