fix: not updating disk cached data of installed apps

This commit is contained in:
Vinicius Moreira
2019-07-25 17:37:15 -03:00
parent 3a52bbf837
commit fd9bcd43e7
3 changed files with 10 additions and 22 deletions

View File

@@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- retrieving some Snaps data (icon, description and confinement) through Ubuntu API instead of Snap Store - retrieving some Snaps data (icon, description and confinement) through Ubuntu API instead of Snap Store
### Fixes: ### Fixes:
- not showing app disk cached description when listing installed apps - not showing app disk cached description when listing installed apps
- not updating disk cached data of installed apps
## [0.4.0] - 2019-07-25 ## [0.4.0] - 2019-07-25
### Features ### Features

View File

@@ -21,7 +21,7 @@ class FlatpakAsyncDataLoader(AsyncDataLoader):
self.http_session = http_session self.http_session = http_session
self.attempts = attempts self.attempts = attempts
self.api_cache = api_cache self.api_cache = api_cache
self.to_persist = {} # stores all data loaded by the instance self.persist = False
self.timeout = timeout self.timeout = timeout
def run(self): def run(self):
@@ -55,10 +55,7 @@ class FlatpakAsyncDataLoader(AsyncDataLoader):
self.api_cache.add(self.app.base_data.id, loaded_data) self.api_cache.add(self.app.base_data.id, loaded_data)
self.app.status = ApplicationStatus.READY self.app.status = ApplicationStatus.READY
self.persist = self.app.supports_disk_cache()
if self.app.supports_disk_cache():
self.to_persist[self.app.base_data.id] = self.app
break break
else: else:
self.log_msg("Could not retrieve app data for id '{}'. Server response: {}. Body: {}".format( self.log_msg("Could not retrieve app data for id '{}'. Server response: {}. Body: {}".format(
@@ -70,12 +67,8 @@ class FlatpakAsyncDataLoader(AsyncDataLoader):
self.app.status = ApplicationStatus.READY self.app.status = ApplicationStatus.READY
def cache_to_disk(self): if self.persist:
if self.to_persist: self.manager.cache_to_disk(app=self.app, icon_bytes=None, only_icon=False)
for app in self.to_persist.values():
self.manager.cache_to_disk(app=app, icon_bytes=None, only_icon=False)
self.to_persist = {}
def clone(self) -> "FlatpakAsyncDataLoader": def clone(self) -> "FlatpakAsyncDataLoader":
return FlatpakAsyncDataLoader(manager=self.manager, return FlatpakAsyncDataLoader(manager=self.manager,

View File

@@ -21,7 +21,7 @@ class SnapAsyncDataLoader(AsyncDataLoader):
self.attempts = attempts self.attempts = attempts
self.api_cache = api_cache self.api_cache = api_cache
self.timeout = timeout self.timeout = timeout
self.to_persist = {} # stores all data loaded by the instance self.persist = False
self.download_icons = download_icons self.download_icons = download_icons
def run(self): def run(self):
@@ -61,10 +61,7 @@ class SnapAsyncDataLoader(AsyncDataLoader):
self.app.base_data.description = api_data['description'] self.app.base_data.description = api_data['description']
self.app.status = ApplicationStatus.READY self.app.status = ApplicationStatus.READY
self.persist = self.app.supports_disk_cache()
if self.app.supports_disk_cache():
self.to_persist[self.app.base_data.id] = self.app
break break
else: else:
self.log_msg("Could not retrieve app data for id '{}'. Server response: {}. Body: {}".format(self.app.base_data.id, res.status_code, res.content.decode()), Fore.RED) self.log_msg("Could not retrieve app data for id '{}'. Server response: {}. Body: {}".format(self.app.base_data.id, res.status_code, res.content.decode()), Fore.RED)
@@ -75,6 +72,9 @@ class SnapAsyncDataLoader(AsyncDataLoader):
self.app.status = ApplicationStatus.READY self.app.status = ApplicationStatus.READY
if self.persist:
self.manager.cache_to_disk(app=self.app, icon_bytes=None, only_icon=False)
def clone(self) -> "SnapAsyncDataLoader": def clone(self) -> "SnapAsyncDataLoader":
return SnapAsyncDataLoader(manager=self.manager, return SnapAsyncDataLoader(manager=self.manager,
api_cache=self.api_cache, api_cache=self.api_cache,
@@ -83,9 +83,3 @@ class SnapAsyncDataLoader(AsyncDataLoader):
timeout=self.timeout, timeout=self.timeout,
app=self.app) app=self.app)
def cache_to_disk(self):
if self.to_persist:
for app in self.to_persist.values():
self.manager.cache_to_disk(app=app, icon_bytes=None, only_icon=False)
self.to_persist = {}