-
-
Notifications
You must be signed in to change notification settings - Fork 319
fix: Partially fix long running import #3300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
1cb7261
03370ba
a3276b4
9e5e03a
877b299
f7e962d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -65,8 +65,12 @@ class CoreImportFilesProcessor( | |
| val errors = mutableListOf<ErrorResponseBody>() | ||
| val warnings = mutableListOf<ErrorResponseBody>() | ||
|
|
||
| private val importedTranslations = | ||
| mutableMapOf<ImportLanguage, MutableMap<ImportKey, MutableList<ImportTranslation>>>() | ||
|
|
||
| fun processFiles(files: Collection<ImportFileDto>?) { | ||
| errors.addAll(processFilesRecursive(files)) | ||
| importDataManager.populateStoredTranslationsFrom(importedTranslations) | ||
| renderPossibleNamespacesWarning() | ||
| } | ||
|
|
||
|
|
@@ -231,18 +235,22 @@ class CoreImportFilesProcessor( | |
| private fun FileProcessorContext.processLanguages() { | ||
| this.languages.forEach { entry -> | ||
| val languageEntity = entry.value | ||
| importDataManager.storedLanguages.add(languageEntity) | ||
|
|
||
| if (!shouldBeImported(languageEntity)) { | ||
| languageEntity.ignored = true | ||
| return@forEach | ||
| } | ||
| } | ||
|
|
||
| preselectExistingLanguage(languageEntity) | ||
| if (saveData) { | ||
| importService.saveLanguages(this.languages.values) | ||
| if (saveData) { | ||
| importService.saveLanguages(this.languages.values.filterNot { it.ignored }) | ||
| } | ||
|
|
||
| this.languages.forEach { entry -> | ||
| val languageEntity = entry.value | ||
| importDataManager.storedLanguages.add(languageEntity) | ||
|
|
||
| if (!languageEntity.ignored) { | ||
| preselectExistingLanguage(languageEntity) | ||
| } | ||
| importDataManager.populateStoredTranslations(entry.value) | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -319,13 +327,27 @@ class CoreImportFilesProcessor( | |
| } | ||
|
|
||
| private fun FileProcessorContext.processTranslations() { | ||
| this.translations.forEach { entry -> | ||
| val keyEntity = getOrCreateKey(entry.key) | ||
| entry.value.forEach translationForeach@{ newTranslation -> | ||
| processTranslation(newTranslation, keyEntity) | ||
| val translationsByKeys = translations.mapKeys { (keyName, _) -> | ||
| getOrCreateKey(keyName).apply { | ||
| shouldBeImported = shouldImportKey(name) | ||
| } | ||
| } | ||
|
|
||
| translationsByKeys.forEach { (key, translations) -> | ||
| translations.forEach { translation -> | ||
| importedTranslations.putIfAbsent(translation.language, mutableMapOf()) | ||
| importedTranslations.getValue(translation.language).putIfAbsent(key, mutableListOf()) | ||
| importedTranslations.getValue(translation.language).getValue(key).add(translation) | ||
| } | ||
| keyEntity.shouldBeImported = shouldImportKey(keyEntity.name) | ||
| } | ||
|
|
||
| translationsByKeys.forEach { (key, translations) -> | ||
| translations.forEach { translation -> | ||
| translation.key = key | ||
| processTranslation(translation) | ||
| } | ||
|
Comment on lines
+336
to
+348
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Collision detection regressed: every first translation is now rejected By adding each - val storedTranslations = importedTranslations[newTranslation.language]
- ?.get(newTranslation.key)
- ?: emptyList()
+ val storedTranslations = importedTranslations[newTranslation.language]
+ ?.get(newTranslation.key)
+ ?.filter { it !== newTranslation }
+ ?: emptyList()and reuse Also applies to: 385-388 🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
| if (saveData) { | ||
| importDataManager.saveAllStoredTranslations() | ||
| } | ||
|
|
@@ -340,9 +362,7 @@ class CoreImportFilesProcessor( | |
|
|
||
| private fun FileProcessorContext.processTranslation( | ||
| newTranslation: ImportTranslation, | ||
| keyEntity: ImportKey, | ||
| ) { | ||
| newTranslation.key = keyEntity | ||
| val (isCollision, fileCollisions) = checkForInFileCollisions(newTranslation) | ||
| if (isCollision) { | ||
| fileEntity.addIssues(fileCollisions) | ||
|
|
@@ -363,9 +383,8 @@ class CoreImportFilesProcessor( | |
| var isCollision = false | ||
| val issues = | ||
| mutableListOf<Pair<FileIssueType, Map<FileIssueParamType, String>>>() | ||
| val storedTranslations = | ||
| importDataManager | ||
| .getStoredTranslations(newTranslation.key, newTranslation.language) | ||
| val storedTranslations = importedTranslations[newTranslation.language]?.get(newTranslation.key) ?: emptyList() | ||
|
|
||
| if (storedTranslations.isNotEmpty()) { | ||
| isCollision = true | ||
| storedTranslations.forEach { collision -> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commented assertions hide test failures and provide false confidence.
All validation logic is commented out, so the test exercises the import but verifies nothing. This typically signals that the test is failing and assertions were disabled rather than fixed. Given the collision-detection bug in
CoreImportFilesProcessor.kt(see my comments there), this test likely fails because translations are incorrectly rejected during import.Restore the assertions and fix the underlying import bug: