Merge duplicate screenshot references during key import#3521
Merge duplicate screenshot references during key import#3521
Conversation
When the same key+screenshot pair appears multiple times during import, merge their positions and text instead of silently dropping duplicates. This preserves alternative key positions in the same screenshot image. The approach collects and merges all ScreenshotInfoDto entries per unique (key, screenshot) pair before persisting, ensuring no metadata is lost. https://claude.ai/code/session_01EpxKwLXnkjPV52rPvE6mxG
📝 WalkthroughWalkthroughThis PR refactors the reference deduplication mechanism in Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
backend/data/src/main/kotlin/io/tolgee/service/key/ResolvingKeyImporter.kt (1)
228-248: Add explicit label forreturn@forEachto improve clarity.With nested
forEachloops (outer at line 228, inner at line 230),return@forEachat line 247 implicitly returns from the innermostforEach. While this is correct behavior, an explicit label would make the intent clearer.📝 Suggested improvement
- it.screenshots?.forEach { screenshot -> + it.screenshots?.forEach screenshots@{ screenshot -> ... - return@forEach + return@screenshots }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@backend/data/src/main/kotlin/io/tolgee/service/key/ResolvingKeyImporter.kt` around lines 228 - 248, The nested forEach uses an unlabeled return@forEach which is ambiguous; add an explicit label to the outer loop (e.g. keysToImport.forEach outer@ { ... }) and change the inner early-return to use that label (return@outer) so it is clear you are returning from the outer keysToImport.forEach rather than the inner it.screenshots?.forEach; update references around getOrCreateKey, createdScreenshots and mergedReferences accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@backend/data/src/main/kotlin/io/tolgee/service/key/ResolvingKeyImporter.kt`:
- Around line 228-248: The nested forEach uses an unlabeled return@forEach which
is ambiguous; add an explicit label to the outer loop (e.g. keysToImport.forEach
outer@ { ... }) and change the inner early-return to use that label
(return@outer) so it is clear you are returning from the outer
keysToImport.forEach rather than the inner it.screenshots?.forEach; update
references around getOrCreateKey, createdScreenshots and mergedReferences
accordingly.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: d508d82c-a0d7-4b24-b1de-af5af8d15049
📒 Files selected for processing (1)
backend/data/src/main/kotlin/io/tolgee/service/key/ResolvingKeyImporter.kt
|
Test would be nice. |
|
@JanCizmar Good point, I'll create some tests in cooldown ^^ |
|
This PR is stale because it has been open for 30 days with no activity. |
Summary
This change improves the key import process to properly handle duplicate screenshot references by merging them instead of skipping them. When the same key is associated with the same screenshot multiple times during import, the positions and text are now combined into a single reference.
Key Changes
addedReferencesSet withmergedReferencesLinkedHashMap to track and merge duplicate referencesMergedReferenceDatadata class to store merged reference information including the key, screenshot result, and combined metadatascreenshotService.addReference()calls until after all references are processed and merged, ensuring only the final merged references are added to the databaseImplementation Details
https://claude.ai/code/session_01EpxKwLXnkjPV52rPvE6mxG
Summary by CodeRabbit
Release Notes