mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-01-22 16:56:19 +01:00
Check supported files early
Technically this can save some memory footprint
This commit is contained in:
parent
b82f83a23a
commit
b5685d1d65
6 changed files with 23 additions and 11 deletions
|
@ -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
|
// caching contents in trashbin doesn't sounds useful
|
||||||
const fileRepo = FileRepo(FileWebdavDataSource());
|
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;
|
late final AppEventListener<FileRemovedEvent> _fileRemovedEventListener;
|
||||||
|
|
|
@ -342,8 +342,10 @@ class ScanAccountDirBloc
|
||||||
path: file_util.unstripPath(account, settings.getShareFolderOr()),
|
path: file_util.unstripPath(account, settings.getShareFolderOr()),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
final sharedFiles =
|
final sharedFiles = files
|
||||||
files.where((f) => !f.isOwned(account.username)).toList();
|
.where((f) =>
|
||||||
|
file_util.isSupportedFormat(f) && !f.isOwned(account.username))
|
||||||
|
.toList();
|
||||||
yield ScanAccountDirBlocSuccess(getState().files + sharedFiles);
|
yield ScanAccountDirBlocSuccess(getState().files + sharedFiles);
|
||||||
} else {
|
} else {
|
||||||
yield ScanAccountDirBlocSuccess(getState().files);
|
yield ScanAccountDirBlocSuccess(getState().files);
|
||||||
|
|
|
@ -2,6 +2,7 @@ import 'package:logging/logging.dart';
|
||||||
import 'package:nc_photos/account.dart';
|
import 'package:nc_photos/account.dart';
|
||||||
import 'package:nc_photos/debug_util.dart';
|
import 'package:nc_photos/debug_util.dart';
|
||||||
import 'package:nc_photos/entity/file.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.dart';
|
||||||
import 'package:nc_photos/exception_event.dart';
|
import 'package:nc_photos/exception_event.dart';
|
||||||
import 'package:nc_photos/remote_storage_util.dart' as remote_storage_util;
|
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
|
/// Dirs with a .nomedia/.noimage file will be ignored. The returned stream
|
||||||
/// would emit either List<File> data or an exception
|
/// 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 {
|
try {
|
||||||
final items = await Ls(fileRepo)(account, root);
|
final items = await Ls(fileRepo)(account, root);
|
||||||
if (_shouldScanIgnoreDir(items)) {
|
if (_shouldScanIgnoreDir(items)) {
|
||||||
return;
|
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) =>
|
for (final i in items.where((element) =>
|
||||||
element.isCollection == true &&
|
element.isCollection == true &&
|
||||||
!element.path
|
!element.path
|
||||||
|
|
|
@ -258,8 +258,7 @@ class _ArchiveBrowserState extends State<ArchiveBrowser>
|
||||||
|
|
||||||
void _transformItems(List<File> files) {
|
void _transformItems(List<File> files) {
|
||||||
_backingFiles = files
|
_backingFiles = files
|
||||||
.where((element) =>
|
.where((f) => f.isArchived == true)
|
||||||
file_util.isSupportedFormat(element) && element.isArchived == true)
|
|
||||||
.sorted(compareFileDateTimeDescending);
|
.sorted(compareFileDateTimeDescending);
|
||||||
|
|
||||||
itemStreamListItems = () sync* {
|
itemStreamListItems = () sync* {
|
||||||
|
|
|
@ -514,8 +514,7 @@ class _HomePhotosState extends State<HomePhotos>
|
||||||
/// Transform a File list to grid items
|
/// Transform a File list to grid items
|
||||||
void _transformItems(List<File> files) {
|
void _transformItems(List<File> files) {
|
||||||
_backingFiles = files
|
_backingFiles = files
|
||||||
.where((element) =>
|
.where((f) => f.isArchived != true)
|
||||||
file_util.isSupportedFormat(element) && element.isArchived != true)
|
|
||||||
.sorted(compareFileDateTimeDescending);
|
.sorted(compareFileDateTimeDescending);
|
||||||
|
|
||||||
final isMonthOnly = _thumbZoomLevel < 0;
|
final isMonthOnly = _thumbZoomLevel < 0;
|
||||||
|
|
|
@ -339,7 +339,6 @@ class _TrashbinBrowserState extends State<TrashbinBrowser>
|
||||||
|
|
||||||
void _transformItems(List<File> files) {
|
void _transformItems(List<File> files) {
|
||||||
_backingFiles = files
|
_backingFiles = files
|
||||||
.where((element) => file_util.isSupportedFormat(element))
|
|
||||||
.sorted((a, b) {
|
.sorted((a, b) {
|
||||||
if (a.trashbinDeletionTime == null && b.trashbinDeletionTime == null) {
|
if (a.trashbinDeletionTime == null && b.trashbinDeletionTime == null) {
|
||||||
// ?
|
// ?
|
||||||
|
|
Loading…
Reference in a new issue