mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-07 01:14:15 +02:00
[aur] caching categories to the disk | not locking the application boot while the AUR categories are being retrieved
This commit is contained in:
@@ -22,7 +22,7 @@ from bauh.gems.arch import BUILD_DIR, aur, pacman, makepkg, pkgbuild, message, c
|
||||
from bauh.gems.arch.aur import AURClient
|
||||
from bauh.gems.arch.mapper import ArchDataMapper
|
||||
from bauh.gems.arch.model import ArchPackage
|
||||
from bauh.gems.arch.worker import AURIndexUpdater, ArchDiskCacheUpdater, ArchCompilationOptimizer, CategoriesDownloader
|
||||
from bauh.gems.arch.worker import AURIndexUpdater, ArchDiskCacheUpdater, ArchCompilationOptimizer, AURCategoriesMapper
|
||||
|
||||
URL_GIT = 'https://aur.archlinux.org/{}.git'
|
||||
URL_PKG_DOWNLOAD = 'https://aur.archlinux.org/cgit/aur.git/snapshot/{}.tar.gz'
|
||||
@@ -51,11 +51,11 @@ class ArchManager(SoftwareManager):
|
||||
self.logger = context.logger
|
||||
self.enabled = True
|
||||
self.arch_distro = context.distro == 'arch'
|
||||
self.categories_downloader = CategoriesDownloader(context.http_client, context.logger)
|
||||
self.categories_mapper = AURCategoriesMapper(context.http_client, context.logger, self, self.context.disk_cache)
|
||||
self.categories_map = {}
|
||||
|
||||
def _upgrade_search_result(self, apidata: dict, installed_pkgs: dict, downgrade_enabled: bool, res: SearchResult, disk_loader: DiskCacheLoader):
|
||||
app = self.mapper.map_api_data(apidata, installed_pkgs['not_signed'])
|
||||
app = self.mapper.map_api_data(apidata, installed_pkgs['not_signed'], self.categories_map)
|
||||
app.downgrade_enabled = downgrade_enabled
|
||||
|
||||
if app.installed:
|
||||
@@ -66,7 +66,7 @@ class ArchManager(SoftwareManager):
|
||||
else:
|
||||
res.new.append(app)
|
||||
|
||||
Thread(target=self.mapper.fill_package_build, args=(app,)).start()
|
||||
Thread(target=self.mapper.fill_package_build, args=(app,), daemon=True).start()
|
||||
|
||||
def search(self, words: str, disk_loader: DiskCacheLoader, limit: int = -1) -> SearchResult:
|
||||
self.comp_optimizer.join()
|
||||
@@ -75,7 +75,7 @@ class ArchManager(SoftwareManager):
|
||||
res = SearchResult([], [], 0)
|
||||
|
||||
installed = {}
|
||||
read_installed = Thread(target=lambda: installed.update(pacman.list_and_map_installed()))
|
||||
read_installed = Thread(target=lambda: installed.update(pacman.list_and_map_installed()), daemon=True)
|
||||
read_installed.start()
|
||||
|
||||
api_res = self.aur_client.search(words)
|
||||
@@ -117,9 +117,8 @@ class ArchManager(SoftwareManager):
|
||||
|
||||
if pkgsinfo:
|
||||
for pkgdata in pkgsinfo:
|
||||
pkg = self.mapper.map_api_data(pkgdata, not_signed)
|
||||
pkg = self.mapper.map_api_data(pkgdata, not_signed, self.categories_map)
|
||||
pkg.downgrade_enabled = downgrade_enabled
|
||||
pkg.categories = self.categories_map.get(pkg.name)
|
||||
|
||||
if disk_loader:
|
||||
disk_loader.fill(pkg)
|
||||
@@ -161,6 +160,7 @@ class ArchManager(SoftwareManager):
|
||||
apps = []
|
||||
if installed and installed['not_signed']:
|
||||
self.dcache_updater.join()
|
||||
self.categories_mapper.join()
|
||||
|
||||
self._fill_aur_pkgs(installed['not_signed'], apps, disk_loader, internet_available)
|
||||
|
||||
@@ -684,7 +684,7 @@ class ArchManager(SoftwareManager):
|
||||
return False
|
||||
|
||||
def cache_to_disk(self, pkg: ArchPackage, icon_bytes: bytes, only_icon: bool):
|
||||
pass
|
||||
pass
|
||||
|
||||
def requires_root(self, action: str, pkg: ArchPackage):
|
||||
return action != 'search'
|
||||
@@ -693,10 +693,7 @@ class ArchManager(SoftwareManager):
|
||||
self.dcache_updater.start()
|
||||
self.comp_optimizer.start()
|
||||
self.aur_index_updater.start()
|
||||
categories = self.categories_downloader.get_categories()
|
||||
|
||||
if categories:
|
||||
self.categories_map = categories
|
||||
self.categories_mapper.start()
|
||||
|
||||
def list_updates(self, internet_available: bool) -> List[PackageUpdate]:
|
||||
installed = self.read_installed(disk_loader=None, internet_available=internet_available).installed
|
||||
@@ -731,9 +728,10 @@ class ArchManager(SoftwareManager):
|
||||
api_res = self.aur_client.get_info(sug_names)
|
||||
|
||||
if api_res:
|
||||
self.categories_mapper.join()
|
||||
for pkg in api_res:
|
||||
if pkg.get('Name') in sug_names:
|
||||
res.append(PackageSuggestion(self.mapper.map_api_data(pkg, {}), suggestions.ALL.get(pkg['Name'])))
|
||||
res.append(PackageSuggestion(self.mapper.map_api_data(pkg, {}, self.categories_map), suggestions.ALL.get(pkg['Name'])))
|
||||
|
||||
return res
|
||||
|
||||
|
||||
Reference in New Issue
Block a user