From 773c761493732a9b779b2bd25160a1049c203491 Mon Sep 17 00:00:00 2001 From: Vinicius Moreira Date: Tue, 22 Oct 2019 17:43:57 -0300 Subject: [PATCH] [categories] not locking the boot when could read from the disk cache --- bauh/commons/category.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/bauh/commons/category.py b/bauh/commons/category.py index 0f9e3831..bbf4bc29 100644 --- a/bauh/commons/category.py +++ b/bauh/commons/category.py @@ -90,10 +90,19 @@ class CategoriesDownloader(Thread): def _set_categories(self, categories: dict): if categories: - self.logger.info(self._msg("Settings categories to {}".format(self.manager.__class__.__name__))) + self.logger.info(self._msg("Settings {} categories to {}".format(len(categories), self.manager.__class__.__name__))) self.manager.categories = categories - def run(self): - self._set_categories(self._read_categories_from_disk()) + def _download_and_set(self): self._set_categories(self.download_categories()) + + def run(self): + cached = self._read_categories_from_disk() + + if cached: + self._set_categories(cached) + Thread(target=self._download_and_set, daemon=True).start() + else: + self._download_and_set() + self.logger.info(self._msg('Finished'))