85 lines
2.7 KiB
Dart
85 lines
2.7 KiB
Dart
// lib/remote/collection_source_remote_ext.dart
|
|
//
|
|
// Caricamento remoti dal DB in modalità safe.
|
|
//
|
|
// Importante:
|
|
// - NON usa addEntries()
|
|
// - NON reinserisce remoti nel DB
|
|
// - NON spara EntryAddedEvent manuale
|
|
// - ricarica anche metadata/address/trash dopo reloadEntriesFromDb()
|
|
// per evitare che Paesi/Luoghi restino con count ma pagina vuota.
|
|
|
|
import 'package:aves/model/source/collection_source.dart';
|
|
import 'package:aves/services/common/services.dart';
|
|
import 'package:flutter/foundation.dart';
|
|
|
|
import 'remote_origin.dart';
|
|
|
|
extension CollectionSourceRemoteExt on CollectionSource {
|
|
Future<void> appendRemoteEntriesFromDb() async {
|
|
try {
|
|
final remotiDb = await localMediaDb.loadEntries(
|
|
origin: RemoteOrigin.value,
|
|
);
|
|
|
|
final visibili = remotiDb.where((e) => !e.trashed).toSet();
|
|
|
|
debugPrint(
|
|
'[remote-append] dbRemote=${remotiDb.length} '
|
|
'visibleRemote=${visibili.length} '
|
|
'remoteVisible=$remoteVisible',
|
|
);
|
|
|
|
if (visibili.isEmpty) {
|
|
debugPrint('[remote-append] nessun remoto visibile nel DB');
|
|
return;
|
|
}
|
|
|
|
// Il DB è già stato aggiornato dal fullSync/deltaSync.
|
|
// Qui ricarichiamo la source in RAM.
|
|
await reloadEntriesFromDb();
|
|
|
|
// Fondamentale:
|
|
// reloadEntriesFromDb() ricarica le entries base,
|
|
// ma non i metadata/address.
|
|
// Senza questo, Paesi/Luoghi possono mostrare count
|
|
// ma pagina vuota quando apri un Paese.
|
|
await loadCatalogMetadata();
|
|
await loadAddresses();
|
|
await loadTrashDetails();
|
|
|
|
// Dopo reloadEntriesFromDb + metadata/address, usa le entry remote
|
|
// attualmente presenti nella source, non quelle caricate prima dal DB.
|
|
final remoteEntries = allEntries
|
|
.where((e) => e.origin == RemoteOrigin.value && !e.trashed)
|
|
.toSet();
|
|
|
|
// Se i remoti sono già visibili, aggiorniamo subito i filtri derivati.
|
|
// Se invece siamo ancora in syncing, remoteVisible=false:
|
|
// NON aggiorniamo qui Paesi/Luoghi/Tag, perché i remoti sarebbero esclusi.
|
|
// Verranno aggiornati quando remoteVisible passa a true.
|
|
if (remoteVisible) {
|
|
updateDerivedFilters(remoteEntries);
|
|
|
|
debugPrint(
|
|
'[remote-append] derived filters updated immediately '
|
|
'remoteVisible=$remoteVisible remotes=${remoteEntries.length}',
|
|
);
|
|
} else {
|
|
debugPrint(
|
|
'[remote-append] derived filters skipped '
|
|
'remoteVisible=$remoteVisible remotes=${remoteEntries.length}',
|
|
);
|
|
}
|
|
|
|
debugPrint(
|
|
'[remote-append] reload + metadata done '
|
|
'allEntries=${allEntries.length} '
|
|
'visibleEntries=${visibleEntries.length} '
|
|
'folderMap=${folderMap.length}',
|
|
);
|
|
} catch (e, st) {
|
|
debugPrint('[remote-append] errore: $e\n$st');
|
|
}
|
|
}
|
|
}
|