refresh review

This commit is contained in:
Thibault Deckers 2022-12-05 19:51:37 +01:00
parent 9bd01b16f4
commit 0cf7eafca9
4 changed files with 34 additions and 29 deletions

View file

@ -672,7 +672,6 @@ class AvesEntry {
required bool background,
required bool persist,
required Set<EntryDataType> 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<bool> delete() {

View file

@ -392,31 +392,36 @@ abstract class CollectionSource with SourceBase, AlbumMixin, LocationMixin, TagM
Future<Set<String>> refreshUris(Set<String> changedUris, {AnalysisController? analysisController});
Future<void> refreshEntry(AvesEntry entry, Set<EntryDataType> dataTypes) async {
await entry.refresh(background: false, persist: true, dataTypes: dataTypes, geocoderLocale: settings.appliedLocale);
Future<void> refreshEntries(Set<AvesEntry> entries, Set<EntryDataType> 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<void> analyze(AnalysisController? analysisController, {Set<AvesEntry>? entries}) async {

View file

@ -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;

View file

@ -33,7 +33,7 @@ mixin SingleEntryEditorMixin on FeedbackMixin, PermissionAwareMixin {
Set<String> 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 {