mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-03-25 08:24:43 +01:00
Fix db not clean up correctly after removing root dir on server
This commit is contained in:
parent
7c56697dde
commit
c2a7096ab6
1 changed files with 27 additions and 19 deletions
|
@ -199,7 +199,9 @@ class FileCacheRemover {
|
||||||
/// to dirStore.
|
/// to dirStore.
|
||||||
Future<void> call(Account account, File f) async {
|
Future<void> call(Account account, File f) async {
|
||||||
await appDb.use((db) async {
|
await appDb.use((db) async {
|
||||||
if (f.isCollection == true) {
|
if (f.isCollection != false) {
|
||||||
|
// removing dir is basically a superset of removing file, so we'll treat
|
||||||
|
// unspecified file as dir
|
||||||
final transaction = db.transaction(
|
final transaction = db.transaction(
|
||||||
[AppDb.dirStoreName, AppDb.file2StoreName], idbModeReadWrite);
|
[AppDb.dirStoreName, AppDb.file2StoreName], idbModeReadWrite);
|
||||||
final dirStore = transaction.objectStore(AppDb.dirStoreName);
|
final dirStore = transaction.objectStore(AppDb.dirStoreName);
|
||||||
|
@ -223,11 +225,25 @@ Future<void> _removeFileFromAppDb(
|
||||||
File file, {
|
File file, {
|
||||||
required ObjectStore fileStore,
|
required ObjectStore fileStore,
|
||||||
}) async {
|
}) async {
|
||||||
assert(file.isCollection != true);
|
|
||||||
try {
|
try {
|
||||||
await fileStore.delete(AppDbFile2Entry.toPrimaryKeyForFile(account, file));
|
if (file.fileId == null) {
|
||||||
|
final index = fileStore.index(AppDbFile2Entry.strippedPathIndexName);
|
||||||
|
final key = await index
|
||||||
|
.getKey(AppDbFile2Entry.toStrippedPathIndexKeyForFile(account, file));
|
||||||
|
if (key != null) {
|
||||||
|
_log.fine("[_removeFileFromAppDb] Removing fileStore entry: $key");
|
||||||
|
await fileStore.delete(key);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
await AppDbFile2Entry.toPrimaryKeyForFile(account, file).run((key) {
|
||||||
|
_log.fine("[_removeFileFromAppDb] Removing fileStore entry: $key");
|
||||||
|
return fileStore.delete(key);
|
||||||
|
});
|
||||||
|
}
|
||||||
} catch (e, stackTrace) {
|
} catch (e, stackTrace) {
|
||||||
_log.shout("[_removeFileFromAppDb] Failed removing fileStore entry", e,
|
_log.shout(
|
||||||
|
"[_removeFileFromAppDb] Failed removing fileStore entry: ${logFilename(file.path)}",
|
||||||
|
e,
|
||||||
stackTrace);
|
stackTrace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -239,16 +255,17 @@ Future<void> _removeDirFromAppDb(
|
||||||
required ObjectStore dirStore,
|
required ObjectStore dirStore,
|
||||||
required ObjectStore fileStore,
|
required ObjectStore fileStore,
|
||||||
}) async {
|
}) async {
|
||||||
assert(dir.isCollection == true);
|
|
||||||
// delete the dir itself
|
// delete the dir itself
|
||||||
try {
|
try {
|
||||||
await AppDbDirEntry.toPrimaryKeyForDir(account, dir).runFuture((key) async {
|
await AppDbDirEntry.toPrimaryKeyForDir(account, dir).run((key) {
|
||||||
_log.fine("[_removeDirFromAppDb] Removing dirStore entry: $key");
|
_log.fine("[_removeDirFromAppDb] Removing dirStore entry: $key");
|
||||||
await dirStore.delete(key);
|
return dirStore.delete(key);
|
||||||
});
|
});
|
||||||
} catch (e, stackTrace) {
|
} catch (e, stackTrace) {
|
||||||
_log.shout(
|
if (dir.isCollection != null) {
|
||||||
"[_removeDirFromAppDb] Failed removing dirStore entry", e, stackTrace);
|
_log.shout("[_removeDirFromAppDb] Failed removing dirStore entry", e,
|
||||||
|
stackTrace);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// then its children
|
// then its children
|
||||||
final childrenRange = KeyRange.bound(
|
final childrenRange = KeyRange.bound(
|
||||||
|
@ -267,16 +284,7 @@ Future<void> _removeDirFromAppDb(
|
||||||
|
|
||||||
// delete files from fileStore
|
// delete files from fileStore
|
||||||
// first the dir
|
// first the dir
|
||||||
try {
|
await _removeFileFromAppDb(account, dir, fileStore: fileStore);
|
||||||
await AppDbFile2Entry.toPrimaryKeyForFile(account, dir)
|
|
||||||
.runFuture((key) async {
|
|
||||||
_log.fine("[_removeDirFromAppDb] Removing fileStore entry: $key");
|
|
||||||
await fileStore.delete(key);
|
|
||||||
});
|
|
||||||
} catch (e, stackTrace) {
|
|
||||||
_log.shout(
|
|
||||||
"[_removeDirFromAppDb] Failed removing fileStore entry", e, stackTrace);
|
|
||||||
}
|
|
||||||
// then files under this dir and sub-dirs
|
// then files under this dir and sub-dirs
|
||||||
final range = KeyRange.bound(
|
final range = KeyRange.bound(
|
||||||
AppDbFile2Entry.toStrippedPathIndexLowerKeyForDir(account, dir),
|
AppDbFile2Entry.toStrippedPathIndexLowerKeyForDir(account, dir),
|
||||||
|
|
Loading…
Add table
Reference in a new issue