Skip to content
Snippets Groups Projects
Commit 5659dec6 authored by Jorrit Schaap's avatar Jorrit Schaap
Browse files

SW-448: keep results for non existing paths in cache

parent c860fd7c
No related branches found
No related tags found
No related merge requests found
...@@ -128,7 +128,7 @@ class CacheManager: ...@@ -128,7 +128,7 @@ class CacheManager:
# Furthermore, once a deeper level du results is stored in the memory cache, then it is also available for fast lookup. # Furthermore, once a deeper level du results is stored in the memory cache, then it is also available for fast lookup.
# We just don't store these deep levels on disk. # We just don't store these deep levels on disk.
sub_cache = { path:du_result for path,du_result in self._cache['path_du_results'].items() sub_cache = { path:du_result for path,du_result in self._cache['path_du_results'].items()
if self.getDepthToProjectsDir(path) <= 1 } if self.getDepthToProjectsDir(path) <= 1 and du_result.get('found') }
cache_str = str(sub_cache) cache_str = str(sub_cache)
with open(tmp_path, 'w') as file: with open(tmp_path, 'w') as file:
...@@ -154,24 +154,24 @@ class CacheManager: ...@@ -154,24 +154,24 @@ class CacheManager:
if path in path_cache: if path in path_cache:
otdb_id = du_result.get('otdb_id') otdb_id = du_result.get('otdb_id')
if du_result['found']: if not path in path_cache or path_cache[path]['disk_usage'] != du_result['disk_usage']:
if not path in path_cache or path_cache[path]['disk_usage'] != du_result['disk_usage']: # update the cache entry, even when no du result found,
# update the cache entry, even when no du result found, # cause that will save disk queries next time.
# cause that will save disk queries next time. logger.info('updating cache entry: %s', du_result)
logger.info('updating cache entry: %s', du_result) path_cache[path] = du_result
path_cache[path] = du_result
path_cache[path]['cache_timestamp'] = datetime.datetime.utcnow() if otdb_id != None:
path_cache[path]['needs_update'] = False otdb_id2path_cache[otdb_id] = path
if otdb_id != None: if not du_result['found']:
otdb_id2path_cache[otdb_id] = path # even when the du for the path is not found,
else: # keep a copy in the cache for fast lookup by clients
if path in path_cache: # Make sure the size is 0
# no need to keep unknown path in cache du_result['disk_usage'] = 0
del path_cache[path] du_result['disk_usage_readable'] = humanreadablesize(0)
if otdb_id != None and otdb_id in otdb_id2path_cache:
del otdb_id2path_cache[otdb_id] path_cache[path]['cache_timestamp'] = datetime.datetime.utcnow()
path_cache[path]['needs_update'] = False
self._writeCacheToDisk() self._writeCacheToDisk()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment