[improvement][arch] faster caching data process during initialization

This commit is contained in:
Vinícius Moreira
2020-05-15 16:55:48 -03:00
parent 23284f7ffe
commit 2f55793e8d
5 changed files with 51 additions and 17 deletions

View File

@@ -1,3 +1,4 @@
import glob
import logging
import os
import re
@@ -13,7 +14,7 @@ from bauh.api.abstract.handler import TaskManager
from bauh.commons.html import bold
from bauh.commons.system import run_cmd, new_root_subprocess, ProcessHandler
from bauh.gems.arch import pacman, disk, CUSTOM_MAKEPKG_FILE, CONFIG_DIR, BUILD_DIR, \
AUR_INDEX_FILE, get_icon_path, database, mirrors
AUR_INDEX_FILE, get_icon_path, database, mirrors, ARCH_CACHE_PATH
from bauh.gems.arch.aur import URL_INDEX
from bauh.view.util.translation import I18n
@@ -75,6 +76,8 @@ class ArchDiskCacheUpdater(Thread):
self.aur = bool(arch_config['aur'])
self.controller = controller
self.internet_available = internet_available
self.installed_hash_path = '{}/installed.sha1'.format(ARCH_CACHE_PATH)
self.installed_cache_dir = '{}/installed'.format(ARCH_CACHE_PATH)
def update_prepared(self, pkgname: str, add: bool = True):
if add:
@@ -97,10 +100,31 @@ class ArchDiskCacheUpdater(Thread):
ti = time.time()
self.task_man.register_task(self.task_id, self.i18n['arch.task.disk_cache'], get_icon_path())
self.task_man.update_progress(self.task_id, 1, '')
self.logger.info("Checking already cached package data")
cache_dirs = [fpath for fpath in glob.glob('{}/*'.format(self.installed_cache_dir)) if os.path.isdir(fpath)]
not_cached_names = None
if cache_dirs: # if there are cache data
installed_names = pacman.list_installed_names()
cached_pkgs = {cache_dir.split('/')[-1] for cache_dir in cache_dirs}
not_cached_names = installed_names.difference(cached_pkgs)
if not not_cached_names:
self.task_man.update_progress(self.task_id, 100, '')
self.task_man.finish_task(self.task_id)
tf = time.time()
time_msg = '{0:.2f} seconds'.format(tf - ti)
self.logger.info('Finished: no package data to cache ({})'.format(time_msg))
return
self.logger.info('Pre-caching installed Arch packages data to disk')
installed = self.controller.read_installed(disk_loader=None, internet_available=self.internet_available,
only_apps=False, pkg_types=None, limit=-1).installed
only_apps=False, pkg_types=None, limit=-1, names=not_cached_names).installed
self.task_man.update_progress(self.task_id, 0, self.i18n['arch.task.disk_cache.reading'])
@@ -111,13 +135,14 @@ class ArchDiskCacheUpdater(Thread):
self.progress = self.to_index * 2
self.update_prepared(None, add=False)
saved += disk.save_several(pkgs, when_prepared=self.update_prepared, after_written=self.update_indexed)
# overwrite == True because the verification already happened
saved += disk.save_several(pkgs, when_prepared=self.update_prepared, after_written=self.update_indexed, overwrite=True)
self.task_man.update_progress(self.task_id, 100, None)
self.task_man.finish_task(self.task_id)
tf = time.time()
time_msg = 'Took {0:.2f} seconds'.format(tf - ti)
self.logger.info('Pre-cached data of {} Arch packages to the disk. {}'.format(saved, time_msg))
time_msg = '{0:.2f} seconds'.format(tf - ti)
self.logger.info('Finished: pre-cached data of {} Arch packages to the disk ({})'.format(saved, time_msg))
class ArchCompilationOptimizer(Thread):