63 lines
1.9 KiB
Text
63 lines
1.9 KiB
Text
// 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
|
|
// - NON invalida country/place/state/tag
|
|
//
|
|
// Il sync remoto scrive già nel DB.
|
|
// Qui dobbiamo solo ricaricare la source in RAM in modo coerente.
|
|
|
|
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.
|
|
//
|
|
// reloadEntriesFromDb() nel tuo CollectionSource:
|
|
// - carica tutte le entry dal DB
|
|
// - aggiorna _rawEntries
|
|
// - aggiorna _entryById
|
|
// - ricostruisce folderMap
|
|
//
|
|
// Non chiama updateDerivedFilters(), quindi evita di rompere
|
|
// Paesi/Luoghi/Tag durante il toggle remote.
|
|
await reloadEntriesFromDb();
|
|
|
|
debugPrint(
|
|
'[remote-append] reloadEntriesFromDb done '
|
|
'allEntries=${allEntries.length} '
|
|
'visibleEntries=${visibleEntries.length} '
|
|
'folderMap=${folderMap.length}',
|
|
);
|
|
} catch (e, st) {
|
|
debugPrint('[remote-append] errore: $e\n$st');
|
|
}
|
|
}
|
|
}
|