From c82a0f11418048c76654599297f3b2b9dfa07eb2 Mon Sep 17 00:00:00 2001 From: Papoteur Date: Sat, 1 May 2021 12:35:10 +0200 Subject: [PATCH 1/4] Improve time spent in _get_id. Before the modification, this function represents 35% of the time spent in get_packages. After, it is just 30% --- python/dnfdaemon/server/__init__.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/python/dnfdaemon/server/__init__.py b/python/dnfdaemon/server/__init__.py index e1fb6aa..eb78c2b 100644 --- a/python/dnfdaemon/server/__init__.py +++ b/python/dnfdaemon/server/__init__.py @@ -1061,11 +1061,10 @@ def _get_po_available(self, id): def _get_id(self, pkg): """Get a package id from a given package.""" - values = [pkg.name, str(pkg.epoch), pkg.version, pkg.release, pkg.arch] if callable(pkg.ui_from_repo): - values.append(pkg.ui_from_repo()) + values = [pkg.name, str(pkg.epoch), pkg.version, pkg.release, pkg.arch, pkg.ui_from_repo()] else: - values.append(pkg.ui_from_repo) + values = [pkg.name, str(pkg.epoch), pkg.version, pkg.release, pkg.arch, pkg.ui_from_repo] return ",".join(values) def _get_action(self, po): From 38d37e1ca84cf24d1aac017a44fb10d20b084346 Mon Sep 17 00:00:00 2001 From: Papoteur Date: Sat, 1 May 2021 18:10:24 +0200 Subject: [PATCH 2/4] Add a specific function for get_packages for standard fields decription, size and group This give an important improvement in time of GetPackages at start of application and relaod. Gain is about 20% of the period of loading cache. --- daemon/dnfdaemon-system.py | 5 ++++- python/dnfdaemon/server/__init__.py | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/daemon/dnfdaemon-system.py b/daemon/dnfdaemon-system.py index b9811ac..df21a20 100755 --- a/daemon/dnfdaemon-system.py +++ b/daemon/dnfdaemon-system.py @@ -235,7 +235,10 @@ def GetPackages(self, pkg_filter, fields, sender=None): :param sender: """ self.working_start(sender, write=False) - value = self.get_packages(pkg_filter, fields) + if fields == ['summary', 'size', 'group']: + value = self.get_packages_ndsg(pkg_filter) + else: + value = self.get_packages(pkg_filter, fields) return self.working_ended(value) @Logger diff --git a/python/dnfdaemon/server/__init__.py b/python/dnfdaemon/server/__init__.py index eb78c2b..a9a95bf 100644 --- a/python/dnfdaemon/server/__init__.py +++ b/python/dnfdaemon/server/__init__.py @@ -387,6 +387,20 @@ def get_packages(self, pkg_filter, attrs): value = [self._get_po_list(po, attrs) for po in pkgs] return json.dumps(value) + @Logger + def get_packages_ndsg(self, pkg_filter): + """Get packages and attribute values based on a filter. + + :param pkg_filter: pkg pkg_filter string ('installed','updates' etc) + :param attrs: list of attributes to get. + """ + value = [] + if pkg_filter in ['installed', 'available', 'updates', 'obsoletes', + 'recent', 'extras', 'updates_all']: + pkgs = getattr(self.base.packages, pkg_filter) + value = [[self._get_id(po), po.summary, po.size, po.group] for po in pkgs] + return json.dumps(value) + def get_attribute(self, id, attr): """Get package attribute. From 6a48497a969e6155ac7db8f1c53b5f65f1fda8c7 Mon Sep 17 00:00:00 2001 From: papoteur-mga Date: Mon, 24 May 2021 10:18:02 +0200 Subject: [PATCH 3/4] Provides the list of package of a transaction with distinction in to_install packages: normal dependencies and weak dependencies Thus in dnfdragora, the weak dependencies can be displayed separately (see issue #185). An entry 'install_weak' is added in the package disctionnary. --- python/dnfdaemon/server/__init__.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/python/dnfdaemon/server/__init__.py b/python/dnfdaemon/server/__init__.py index a9a95bf..8f876de 100644 --- a/python/dnfdaemon/server/__init__.py +++ b/python/dnfdaemon/server/__init__.py @@ -39,6 +39,7 @@ import dnf.yum import functools import hawkey +import libdnf import json import logging import operator @@ -853,7 +854,7 @@ def _get_transaction(self): out_list = [] sublist = [] tx_list = {} - for t in ('downgrade', 'remove', 'install', 'reinstall', 'update'): + for t in ('downgrade', 'remove', 'install', 'install_weak', 'reinstall', 'update'): tx_list[t] = [] replaces = {} @@ -872,7 +873,10 @@ def _get_transaction(self): elif tsi.action == dnf.transaction.PKG_ERASE: tx_list['remove'].append(tsi) elif tsi.action == dnf.transaction.PKG_INSTALL: - tx_list['install'].append(tsi) + if tsi.reason == libdnf.transaction.TransactionItemReason_WEAK_DEPENDENCY: + tx_list['install_weak'].append(tsi) + else: + tx_list['install'].append(tsi) elif tsi.action == dnf.transaction.PKG_REINSTALL: tx_list['reinstall'].append(tsi) elif tsi.action == dnf.transaction.PKG_UPGRADE: @@ -880,6 +884,7 @@ def _get_transaction(self): # build action tree for (action, pkglist) in [ ('install', tx_list['install']), + ('install_weak', tx_list['install_weak']), ('update', tx_list['update']), ('remove', tx_list['remove']), ('reinstall', tx_list['reinstall']), @@ -1078,7 +1083,7 @@ def _get_id(self, pkg): if callable(pkg.ui_from_repo): values = [pkg.name, str(pkg.epoch), pkg.version, pkg.release, pkg.arch, pkg.ui_from_repo()] else: - values = [pkg.name, str(pkg.epoch), pkg.version, pkg.release, pkg.arch, pkg.ui_from_repo] + values = [pkg.name, str(pkg.epoch), pkg.version, pkg.release, pkg.arch, pkg.ui_from_repo] return ",".join(values) def _get_action(self, po): From 4077cc0b4e878075eb283571dfa464d770da7262 Mon Sep 17 00:00:00 2001 From: papoteur-mga Date: Sun, 6 Jun 2021 15:40:09 +0200 Subject: [PATCH 4/4] Use 'weak-deps' as keyword for weak dependencies list in packages of a transaction --- python/dnfdaemon/server/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python/dnfdaemon/server/__init__.py b/python/dnfdaemon/server/__init__.py index 8f876de..cfacafe 100644 --- a/python/dnfdaemon/server/__init__.py +++ b/python/dnfdaemon/server/__init__.py @@ -854,7 +854,7 @@ def _get_transaction(self): out_list = [] sublist = [] tx_list = {} - for t in ('downgrade', 'remove', 'install', 'install_weak', 'reinstall', 'update'): + for t in ('downgrade', 'remove', 'install', 'weak-deps', 'reinstall', 'update'): tx_list[t] = [] replaces = {} @@ -874,7 +874,7 @@ def _get_transaction(self): tx_list['remove'].append(tsi) elif tsi.action == dnf.transaction.PKG_INSTALL: if tsi.reason == libdnf.transaction.TransactionItemReason_WEAK_DEPENDENCY: - tx_list['install_weak'].append(tsi) + tx_list['weak-deps'].append(tsi) else: tx_list['install'].append(tsi) elif tsi.action == dnf.transaction.PKG_REINSTALL: @@ -884,7 +884,7 @@ def _get_transaction(self): # build action tree for (action, pkglist) in [ ('install', tx_list['install']), - ('install_weak', tx_list['install_weak']), + ('weak-deps', tx_list['weak-deps']), ('update', tx_list['update']), ('remove', tx_list['remove']), ('reinstall', tx_list['reinstall']),