mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-02-09 02:36:31 +01:00
Rescan only after multiple metadata updates
This commit is contained in:
parent
63772e6e17
commit
4bb837875c
1 changed files with 18 additions and 1 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
import 'dart:async';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:bloc/bloc.dart';
|
import 'package:bloc/bloc.dart';
|
||||||
|
@ -165,6 +166,7 @@ class ScanDirBloc extends Bloc<ScanDirBlocEvent, ScanDirBlocState> {
|
||||||
close() {
|
close() {
|
||||||
_fileRemovedEventListener.end();
|
_fileRemovedEventListener.end();
|
||||||
_fileMetadataUpdatedEventListener.end();
|
_fileMetadataUpdatedEventListener.end();
|
||||||
|
_metadataUpdatedSubscription?.cancel();
|
||||||
return super.close();
|
return super.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -218,7 +220,19 @@ class ScanDirBloc extends Bloc<ScanDirBlocEvent, ScanDirBlocState> {
|
||||||
// no data in this bloc, ignore
|
// no data in this bloc, ignore
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
add(_ScanDirBlocExternalEvent());
|
|
||||||
|
_successiveMetadataUpdatedCount += 1;
|
||||||
|
_metadataUpdatedSubscription?.cancel();
|
||||||
|
// only trigger the event on the 10th update or 10s after the last update
|
||||||
|
if (_successiveMetadataUpdatedCount % 10 == 0) {
|
||||||
|
add(_ScanDirBlocExternalEvent());
|
||||||
|
} else {
|
||||||
|
_metadataUpdatedSubscription =
|
||||||
|
Future.delayed(const Duration(seconds: 10)).asStream().listen((_) {
|
||||||
|
add(_ScanDirBlocExternalEvent());
|
||||||
|
_successiveMetadataUpdatedCount = 0;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Stream<ScanDirBlocState> _queryOffline(
|
Stream<ScanDirBlocState> _queryOffline(
|
||||||
|
@ -251,5 +265,8 @@ class ScanDirBloc extends Bloc<ScanDirBlocEvent, ScanDirBlocState> {
|
||||||
AppEventListener<FileRemovedEvent> _fileRemovedEventListener;
|
AppEventListener<FileRemovedEvent> _fileRemovedEventListener;
|
||||||
AppEventListener<FileMetadataUpdatedEvent> _fileMetadataUpdatedEventListener;
|
AppEventListener<FileMetadataUpdatedEvent> _fileMetadataUpdatedEventListener;
|
||||||
|
|
||||||
|
int _successiveMetadataUpdatedCount = 0;
|
||||||
|
StreamSubscription<void> _metadataUpdatedSubscription;
|
||||||
|
|
||||||
static final _log = Logger("bloc.scan_dir.ScanDirBloc");
|
static final _log = Logger("bloc.scan_dir.ScanDirBloc");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue