diff --git a/lib/model/entry.dart b/lib/model/entry.dart index 0be186e26..4536385b9 100644 --- a/lib/model/entry.dart +++ b/lib/model/entry.dart @@ -672,7 +672,6 @@ class AvesEntry { required bool background, required bool persist, required Set dataTypes, - required Locale geocoderLocale, }) async { // clear derived fields _bestDate = null; @@ -687,8 +686,6 @@ class AvesEntry { if (updatedEntry != null) { await applyNewFields(updatedEntry.toMap(), persist: persist); } - await catalog(background: background, force: dataTypes.contains(EntryDataType.catalog), persist: persist); - await locate(background: background, force: dataTypes.contains(EntryDataType.address), geocoderLocale: geocoderLocale); } Future delete() { diff --git a/lib/model/source/collection_source.dart b/lib/model/source/collection_source.dart index 94424e2b5..41599a7f9 100644 --- a/lib/model/source/collection_source.dart +++ b/lib/model/source/collection_source.dart @@ -392,31 +392,36 @@ abstract class CollectionSource with SourceBase, AlbumMixin, LocationMixin, TagM Future> refreshUris(Set changedUris, {AnalysisController? analysisController}); - Future refreshEntry(AvesEntry entry, Set dataTypes) async { - await entry.refresh(background: false, persist: true, dataTypes: dataTypes, geocoderLocale: settings.appliedLocale); + Future refreshEntries(Set entries, Set dataTypes) async { + const background = false; + const persist = true; - final id = entry.id; - await Future.forEach(EntryDataType.values, (dataType) async { - switch (dataType) { - case EntryDataType.aspectRatio: - onAspectRatioChanged(); - break; - case EntryDataType.catalog: - await metadataDb.updateCatalogMetadata(id, entry.catalogMetadata); - onCatalogMetadataChanged(); - break; - case EntryDataType.address: - await metadataDb.updateAddress(id, entry.addressDetails); - onAddressMetadataChanged(); - break; - case EntryDataType.basic: - case EntryDataType.references: - break; - } + await Future.forEach(entries, (entry) async { + await entry.refresh(background: background, persist: persist, dataTypes: dataTypes); }); - updateDerivedFilters({entry}); - eventBus.fire(EntryRefreshedEvent({entry})); + if (dataTypes.contains(EntryDataType.aspectRatio)) { + onAspectRatioChanged(); + } + + if (dataTypes.contains(EntryDataType.catalog)) { + await Future.forEach(entries, (entry) async { + await entry.catalog(background: background, force: dataTypes.contains(EntryDataType.catalog), persist: persist); + await metadataDb.updateCatalogMetadata(entry.id, entry.catalogMetadata); + }); + onCatalogMetadataChanged(); + } + + if (dataTypes.contains(EntryDataType.address)) { + await Future.forEach(entries, (entry) async { + await entry.locate(background: background, force: dataTypes.contains(EntryDataType.address), geocoderLocale: settings.appliedLocale); + await metadataDb.updateAddress(entry.id, entry.addressDetails); + }); + onAddressMetadataChanged(); + } + + updateDerivedFilters(entries); + eventBus.fire(EntryRefreshedEvent(entries)); } Future analyze(AnalysisController? analysisController, {Set? entries}) async { diff --git a/lib/model/source/media_store_source.dart b/lib/model/source/media_store_source.dart index d64c2e0f1..3bf804a3a 100644 --- a/lib/model/source/media_store_source.dart +++ b/lib/model/source/media_store_source.dart @@ -271,8 +271,7 @@ class MediaStoreSource extends CollectionSource { } if (entriesToRefresh.isNotEmpty) { - final allDataTypes = EntryDataType.values.toSet(); - await Future.forEach(entriesToRefresh, (entry) => refreshEntry(entry, allDataTypes)); + await refreshEntries(entriesToRefresh, EntryDataType.values.toSet()); } return tempUris; diff --git a/lib/widgets/viewer/action/single_entry_editor.dart b/lib/widgets/viewer/action/single_entry_editor.dart index 0209c1652..96565002b 100644 --- a/lib/widgets/viewer/action/single_entry_editor.dart +++ b/lib/widgets/viewer/action/single_entry_editor.dart @@ -33,7 +33,7 @@ mixin SingleEntryEditorMixin on FeedbackMixin, PermissionAwareMixin { Set obsoleteTags = targetEntry.tags; String? obsoleteCountryCode = targetEntry.addressDetails?.countryCode; - await source.refreshEntry(targetEntry, dataTypes); + await source.refreshEntries({targetEntry}, dataTypes); // invalidate filters derived from values before edition // this invalidation must happen after the source is refreshed, @@ -45,7 +45,11 @@ mixin SingleEntryEditorMixin on FeedbackMixin, PermissionAwareMixin { source.invalidateTagFilterSummary(tags: obsoleteTags); } } else { - await targetEntry.refresh(background: false, persist: false, dataTypes: dataTypes, geocoderLocale: settings.appliedLocale); + const background = false; + const persist = false; + await targetEntry.refresh(background: background, persist: persist, dataTypes: dataTypes); + await targetEntry.catalog(background: background, force: dataTypes.contains(EntryDataType.catalog), persist: persist); + await targetEntry.locate(background: background, force: dataTypes.contains(EntryDataType.address), geocoderLocale: settings.appliedLocale); } showFeedback(context, l10n.genericSuccessFeedback); } else {