mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-02-02 06:46:22 +01:00
Fix dir collection not populating correctly when offline
This commit is contained in:
parent
cb62b76d87
commit
64a4fa825f
2 changed files with 50 additions and 15 deletions
|
@ -298,6 +298,8 @@ class CollectionItemsController {
|
||||||
Future<void> _load() async {
|
Future<void> _load() async {
|
||||||
try {
|
try {
|
||||||
List<CollectionItem>? items;
|
List<CollectionItem>? items;
|
||||||
|
ExceptionEvent? originalException;
|
||||||
|
try {
|
||||||
await for (final r in ListCollectionItem(_c)(account, collection)) {
|
await for (final r in ListCollectionItem(_c)(account, collection)) {
|
||||||
items = r;
|
items = r;
|
||||||
_dataStreamController.add(CollectionItemStreamData(
|
_dataStreamController.add(CollectionItemStreamData(
|
||||||
|
@ -306,18 +308,46 @@ class CollectionItemsController {
|
||||||
hasNext: true,
|
hasNext: true,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
} catch (e, stackTrace) {
|
||||||
|
_log.severe("[_load] Failed while ListCollectionItem, try with local",
|
||||||
|
e, stackTrace);
|
||||||
|
originalException = ExceptionEvent(e, stackTrace);
|
||||||
|
}
|
||||||
|
if (originalException != null) {
|
||||||
|
// try again with local repos
|
||||||
|
try {
|
||||||
|
await for (final r
|
||||||
|
in ListCollectionItem(_c.withLocalRepo())(account, collection)) {
|
||||||
|
items = r;
|
||||||
|
_dataStreamController.add(CollectionItemStreamData(
|
||||||
|
items: r,
|
||||||
|
rawItems: r,
|
||||||
|
hasNext: true,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
} catch (e, stackTrace) {
|
||||||
|
_log.severe(
|
||||||
|
"[_load] Failed while ListCollectionItem with local repos",
|
||||||
|
e,
|
||||||
|
stackTrace);
|
||||||
|
originalException.throwMe();
|
||||||
|
}
|
||||||
|
}
|
||||||
if (items != null) {
|
if (items != null) {
|
||||||
_dataStreamController.add(CollectionItemStreamData(
|
_dataStreamController.add(CollectionItemStreamData(
|
||||||
items: items,
|
items: items,
|
||||||
rawItems: items,
|
rawItems: items,
|
||||||
hasNext: false,
|
hasNext: false,
|
||||||
));
|
));
|
||||||
|
if (originalException == null) {
|
||||||
|
// only update if the data is queried from remote
|
||||||
final newCollection =
|
final newCollection =
|
||||||
await UpdateCollectionPostLoad(_c)(account, collection, items);
|
await UpdateCollectionPostLoad(_c)(account, collection, items);
|
||||||
if (newCollection != null) {
|
if (newCollection != null) {
|
||||||
onCollectionUpdated(newCollection);
|
onCollectionUpdated(newCollection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (e, stackTrace) {
|
} catch (e, stackTrace) {
|
||||||
_dataStreamController
|
_dataStreamController
|
||||||
..addError(e, stackTrace)
|
..addError(e, stackTrace)
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import 'package:clock/clock.dart';
|
import 'package:clock/clock.dart';
|
||||||
import 'package:kiwi/kiwi.dart';
|
|
||||||
import 'package:logging/logging.dart';
|
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';
|
||||||
|
@ -41,14 +40,17 @@ class PopulateAlbum {
|
||||||
assert(album.provider is AlbumDirProvider);
|
assert(album.provider is AlbumDirProvider);
|
||||||
final provider = album.provider as AlbumDirProvider;
|
final provider = album.provider as AlbumDirProvider;
|
||||||
final products = <AlbumItem>[];
|
final products = <AlbumItem>[];
|
||||||
|
var hasGood = false;
|
||||||
|
ExceptionEvent? firstException;
|
||||||
for (final d in provider.dirs) {
|
for (final d in provider.dirs) {
|
||||||
final stream = ScanDir(_c.fileRepo)(account, d);
|
final stream = ScanDir(_c.fileRepo)(account, d);
|
||||||
await for (final result in stream) {
|
await for (final result in stream) {
|
||||||
if (result is ExceptionEvent) {
|
if (result is ExceptionEvent) {
|
||||||
_log.shout(
|
_log.severe(
|
||||||
"[_populateDirAlbum] Failed while scanning dir: ${logFilename(d.path)}",
|
"[_populateDirAlbum] Failed while scanning dir: ${logFilename(d.path)}",
|
||||||
result.error,
|
result.error,
|
||||||
result.stackTrace);
|
result.stackTrace);
|
||||||
|
firstException = result;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
products.addAll((result as List).cast<File>().map((f) => AlbumFileItem(
|
products.addAll((result as List).cast<File>().map((f) => AlbumFileItem(
|
||||||
|
@ -57,8 +59,12 @@ class PopulateAlbum {
|
||||||
file: f,
|
file: f,
|
||||||
ownerId: f.ownerId ?? account.userId,
|
ownerId: f.ownerId ?? account.userId,
|
||||||
)));
|
)));
|
||||||
|
hasGood = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!hasGood && firstException != null) {
|
||||||
|
firstException.throwMe();
|
||||||
|
}
|
||||||
return products;
|
return products;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,8 +73,7 @@ class PopulateAlbum {
|
||||||
assert(album.provider is AlbumTagProvider);
|
assert(album.provider is AlbumTagProvider);
|
||||||
final provider = album.provider as AlbumTagProvider;
|
final provider = album.provider as AlbumTagProvider;
|
||||||
final products = <AlbumItem>[];
|
final products = <AlbumItem>[];
|
||||||
final c = KiwiContainer().resolve<DiContainer>();
|
final files = await ListTaggedFile(_c)(account, provider.tags);
|
||||||
final files = await ListTaggedFile(c)(account, provider.tags);
|
|
||||||
products.addAll(files.map((f) => AlbumFileItem(
|
products.addAll(files.map((f) => AlbumFileItem(
|
||||||
addedBy: account.userId,
|
addedBy: account.userId,
|
||||||
addedAt: clock.now(),
|
addedAt: clock.now(),
|
||||||
|
|
Loading…
Reference in a new issue