mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-02-02 06:46:22 +01:00
Fix exception when syncing dir with path only
This commit is contained in:
parent
8bc9b8c8fd
commit
05f7ecf55f
4 changed files with 30 additions and 5 deletions
|
@ -92,7 +92,7 @@ class FileSqliteCacheUpdater {
|
|||
try {
|
||||
await _c.npDb.syncDirFiles(
|
||||
account: account.toDb(),
|
||||
dirFileId: dir.fileId!,
|
||||
dirFile: dir.toDbKey(),
|
||||
files: remote.map((e) => e.toDb()).toList(),
|
||||
);
|
||||
} finally {
|
||||
|
|
|
@ -214,7 +214,7 @@ abstract class NpDb {
|
|||
/// Add or replace files in db
|
||||
Future<void> syncDirFiles({
|
||||
required DbAccount account,
|
||||
required int dirFileId,
|
||||
required DbFileKey dirFile,
|
||||
required List<DbFile> files,
|
||||
});
|
||||
|
||||
|
|
|
@ -261,7 +261,7 @@ extension SqliteDbFileExtension on SqliteDb {
|
|||
|
||||
Future<void> syncDirFiles({
|
||||
required ByAccount account,
|
||||
required int dirFileId,
|
||||
required DbFileKey dirFile,
|
||||
required List<CompleteFileCompanion> objs,
|
||||
}) async {
|
||||
_log.info("[syncDirFiles] files: [length: ${objs.length}]");
|
||||
|
@ -286,6 +286,11 @@ extension SqliteDbFileExtension on SqliteDb {
|
|||
idMap.addAll(insertMap);
|
||||
}
|
||||
|
||||
final dirFileId = dirFile.fileId ??
|
||||
await _queryFileIdByRelativePath(
|
||||
account: ByAccount.sql(sqlAccount),
|
||||
relativePath: dirFile.relativePath!,
|
||||
).notNull();
|
||||
final dirRowId = idMap[dirFileId];
|
||||
if (dirRowId == null) {
|
||||
_log.severe("[syncDirFiles] Dir not inserted");
|
||||
|
@ -549,6 +554,26 @@ extension SqliteDbFileExtension on SqliteDb {
|
|||
await (delete(dirFiles)..where((t) => t.dir.equals(rowId.fileRowId))).go();
|
||||
}
|
||||
|
||||
Future<int?> _queryFileIdByRelativePath({
|
||||
required ByAccount account,
|
||||
required String relativePath,
|
||||
}) async {
|
||||
_log.info("[_queryFileIdByRelativePath] relativePath: $relativePath");
|
||||
final query = _queryFiles().let((q) {
|
||||
q
|
||||
..setQueryMode(
|
||||
FilesQueryMode.expression,
|
||||
expressions: [
|
||||
files.fileId,
|
||||
],
|
||||
)
|
||||
..setAccount(account)
|
||||
..byRelativePath(relativePath);
|
||||
return q.build()..limit(1);
|
||||
});
|
||||
return query.map((r) => r.read(files.fileId)!).getSingleOrNull();
|
||||
}
|
||||
|
||||
/// Update Db files
|
||||
///
|
||||
/// Return a list of files that are not yet inserted to the DB (thus not
|
||||
|
|
|
@ -309,14 +309,14 @@ class NpDbSqlite implements NpDb {
|
|||
@override
|
||||
Future<void> syncDirFiles({
|
||||
required DbAccount account,
|
||||
required int dirFileId,
|
||||
required DbFileKey dirFile,
|
||||
required List<DbFile> files,
|
||||
}) async {
|
||||
final sqlFiles = await files.toSql();
|
||||
await _db.use((db) async {
|
||||
await db.syncDirFiles(
|
||||
account: ByAccount.db(account),
|
||||
dirFileId: dirFileId,
|
||||
dirFile: dirFile,
|
||||
objs: sqlFiles,
|
||||
);
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue