mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-01-22 16:56:19 +01:00
Fix always querying root dir from remote
This commit is contained in:
parent
c0e65e1c51
commit
687aa0bf24
1 changed files with 25 additions and 11 deletions
|
@ -398,10 +398,15 @@ abstract class FileDataSource {
|
|||
|
||||
class FileWebdavDataSource implements FileDataSource {
|
||||
@override
|
||||
list(Account account, File f) async {
|
||||
list(
|
||||
Account account,
|
||||
File f, {
|
||||
int depth,
|
||||
}) async {
|
||||
_log.fine("[list] ${f.path}");
|
||||
final response = await Api(account).files().propfind(
|
||||
path: f.path,
|
||||
depth: depth,
|
||||
getlastmodified: 1,
|
||||
resourcetype: 1,
|
||||
getetag: 1,
|
||||
|
@ -582,17 +587,26 @@ class FileCachedDataSource implements FileDataSource {
|
|||
try {
|
||||
cache = await _appDbSrc.list(account, f);
|
||||
// compare the cached root
|
||||
final cacheRoot = cache.firstWhere(
|
||||
(element) => element.path.trimAny("/") == trimmedRootPath,
|
||||
orElse: () => null);
|
||||
if (cacheRoot?.etag?.isNotEmpty == true && cacheRoot.etag == f.etag) {
|
||||
// cache is good
|
||||
_log.fine("[list] etag matched for ${_getCacheKey(account, f)}");
|
||||
return cache;
|
||||
} else {
|
||||
_log.info(
|
||||
"[list] Remote content updated for ${_getCacheKey(account, f)}");
|
||||
final cacheEtag = cache
|
||||
.firstWhere((element) => element.path.trimAny("/") == trimmedRootPath)
|
||||
.etag;
|
||||
if (cacheEtag != null) {
|
||||
// compare the etag to see if the content has been updated
|
||||
var remoteEtag = f.etag;
|
||||
if (remoteEtag == null) {
|
||||
// no etag supplied, we need to query it form remote
|
||||
final remote = await _remoteSrc.list(account, f, depth: 0);
|
||||
assert(remote.length == 1);
|
||||
remoteEtag = remote.first.etag;
|
||||
}
|
||||
if (cacheEtag == remoteEtag) {
|
||||
// cache is good
|
||||
_log.fine("[list] etag matched for ${_getCacheKey(account, f)}");
|
||||
return cache;
|
||||
}
|
||||
}
|
||||
_log.info(
|
||||
"[list] Remote content updated for ${_getCacheKey(account, f)}");
|
||||
} catch (e, stacktrace) {
|
||||
// no cache
|
||||
if (e is! CacheNotFoundException) {
|
||||
|
|
Loading…
Reference in a new issue