Fix always querying root dir from remote

This commit is contained in:
Ming Ming 2021-04-24 23:01:23 +08:00
parent c0e65e1c51
commit 687aa0bf24

View file

@ -398,10 +398,15 @@ abstract class FileDataSource {
class FileWebdavDataSource implements FileDataSource { class FileWebdavDataSource implements FileDataSource {
@override @override
list(Account account, File f) async { list(
Account account,
File f, {
int depth,
}) async {
_log.fine("[list] ${f.path}"); _log.fine("[list] ${f.path}");
final response = await Api(account).files().propfind( final response = await Api(account).files().propfind(
path: f.path, path: f.path,
depth: depth,
getlastmodified: 1, getlastmodified: 1,
resourcetype: 1, resourcetype: 1,
getetag: 1, getetag: 1,
@ -582,17 +587,26 @@ class FileCachedDataSource implements FileDataSource {
try { try {
cache = await _appDbSrc.list(account, f); cache = await _appDbSrc.list(account, f);
// compare the cached root // compare the cached root
final cacheRoot = cache.firstWhere( final cacheEtag = cache
(element) => element.path.trimAny("/") == trimmedRootPath, .firstWhere((element) => element.path.trimAny("/") == trimmedRootPath)
orElse: () => null); .etag;
if (cacheRoot?.etag?.isNotEmpty == true && cacheRoot.etag == f.etag) { if (cacheEtag != null) {
// cache is good // compare the etag to see if the content has been updated
_log.fine("[list] etag matched for ${_getCacheKey(account, f)}"); var remoteEtag = f.etag;
return cache; if (remoteEtag == null) {
} else { // no etag supplied, we need to query it form remote
_log.info( final remote = await _remoteSrc.list(account, f, depth: 0);
"[list] Remote content updated for ${_getCacheKey(account, f)}"); 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) { } catch (e, stacktrace) {
// no cache // no cache
if (e is! CacheNotFoundException) { if (e is! CacheNotFoundException) {