Check supported files early

Technically this can save some memory footprint
This commit is contained in:
Ming Ming 2021-12-20 02:09:38 +08:00
parent b82f83a23a
commit b5685d1d65
6 changed files with 23 additions and 11 deletions

View file

@ -171,10 +171,11 @@ class LsTrashbinBloc extends Bloc<LsTrashbinBlocEvent, LsTrashbinBlocState> {
);
}
Future<List<File>> _query(LsTrashbinBlocQuery ev) {
Future<List<File>> _query(LsTrashbinBlocQuery ev) async {
// caching contents in trashbin doesn't sounds useful
const fileRepo = FileRepo(FileWebdavDataSource());
return LsTrashbin(fileRepo)(ev.account);
final files = await LsTrashbin(fileRepo)(ev.account);
return files.where((f) => file_util.isSupportedFormat(f)).toList();
}
late final AppEventListener<FileRemovedEvent> _fileRemovedEventListener;

View file

@ -342,8 +342,10 @@ class ScanAccountDirBloc
path: file_util.unstripPath(account, settings.getShareFolderOr()),
),
);
final sharedFiles =
files.where((f) => !f.isOwned(account.username)).toList();
final sharedFiles = files
.where((f) =>
file_util.isSupportedFormat(f) && !f.isOwned(account.username))
.toList();
yield ScanAccountDirBlocSuccess(getState().files + sharedFiles);
} else {
yield ScanAccountDirBlocSuccess(getState().files);

View file

@ -2,6 +2,7 @@ import 'package:logging/logging.dart';
import 'package:nc_photos/account.dart';
import 'package:nc_photos/debug_util.dart';
import 'package:nc_photos/entity/file.dart';
import 'package:nc_photos/entity/file_util.dart' as file_util;
import 'package:nc_photos/exception.dart';
import 'package:nc_photos/exception_event.dart';
import 'package:nc_photos/remote_storage_util.dart' as remote_storage_util;
@ -14,13 +15,24 @@ class ScanDir {
///
/// Dirs with a .nomedia/.noimage file will be ignored. The returned stream
/// would emit either List<File> data or an exception
Stream<dynamic> call(Account account, File root) async* {
///
/// If [isSupportedFileOnly] == true, the returned files will be filtered by
/// [file_util.isSupportedFormat]
Stream<dynamic> call(
Account account,
File root, {
bool isSupportedFileOnly = true,
}) async* {
try {
final items = await Ls(fileRepo)(account, root);
if (_shouldScanIgnoreDir(items)) {
return;
}
yield items.where((element) => element.isCollection != true).toList();
yield items
.where((f) =>
f.isCollection != true &&
(!isSupportedFileOnly || file_util.isSupportedFormat(f)))
.toList();
for (final i in items.where((element) =>
element.isCollection == true &&
!element.path

View file

@ -258,8 +258,7 @@ class _ArchiveBrowserState extends State<ArchiveBrowser>
void _transformItems(List<File> files) {
_backingFiles = files
.where((element) =>
file_util.isSupportedFormat(element) && element.isArchived == true)
.where((f) => f.isArchived == true)
.sorted(compareFileDateTimeDescending);
itemStreamListItems = () sync* {

View file

@ -514,8 +514,7 @@ class _HomePhotosState extends State<HomePhotos>
/// Transform a File list to grid items
void _transformItems(List<File> files) {
_backingFiles = files
.where((element) =>
file_util.isSupportedFormat(element) && element.isArchived != true)
.where((f) => f.isArchived != true)
.sorted(compareFileDateTimeDescending);
final isMonthOnly = _thumbZoomLevel < 0;

View file

@ -339,7 +339,6 @@ class _TrashbinBrowserState extends State<TrashbinBrowser>
void _transformItems(List<File> files) {
_backingFiles = files
.where((element) => file_util.isSupportedFormat(element))
.sorted((a, b) {
if (a.trashbinDeletionTime == null && b.trashbinDeletionTime == null) {
// ?