Automagic: Update clear-cache and do removals first

This commit is contained in:
Mike Auty
2023-04-04 23:57:35 +01:00
parent 60292c2da1
commit f33ea67e86
2 changed files with 9 additions and 14 deletions
+1 -5
View File
@@ -224,8 +224,4 @@ def list_plugins() -> Dict[str, Type[interfaces.plugins.PluginInterface]]:
def clear_cache(complete=False):
glob_pattern = "*.cache"
if not complete:
glob_pattern = "data_" + glob_pattern
for cache_filename in glob.glob(os.path.join(constants.CACHE_PATH, glob_pattern)):
os.unlink(cache_filename)
os.unlink(os.path.join(constants.CACHE_PATH, constants.IDENTIFIERS_FILENAME))
@@ -310,6 +310,14 @@ class SqliteCache(CacheManagerInterface):
new_locations = on_disk_locations.difference(cached_locations)
missing_locations = cached_locations.difference(on_disk_locations)
# Missing entries
if missing_locations:
self._database.cursor().execute(
f"DELETE FROM cache WHERE location IN ({','.join(['?'] * len(missing_locations))})",
[x for x in missing_locations],
)
self._database.commit()
cache_update = set()
files_to_timestamp = on_disk_locations.intersection(cached_locations)
if files_to_timestamp:
@@ -437,15 +445,6 @@ class SqliteCache(CacheManagerInterface):
progress_callback(100, "Reading remote ISF list")
self._database.commit()
# Missing entries
if missing_locations:
self._database.cursor().execute(
f"DELETE FROM cache WHERE location IN ({','.join(['?'] * len(missing_locations))})",
[x for x in missing_locations],
)
self._database.commit()
def get_identifier_dictionary(
self, operating_system: Optional[str] = None, local_only: bool = False
) -> Dict[bytes, str]: