From 6984a34d25b9094095d5cd67a751655780412980 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Moreira?= Date: Mon, 23 Dec 2019 13:15:23 -0300 Subject: [PATCH] [web] improving how suggestions are verified if they are installed --- CHANGELOG.md | 1 + bauh/gems/web/controller.py | 24 +++++++++++++++--------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a949fee3..48684386 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -64,6 +64,7 @@ updates: - suggestions are now retrieved from [suggestions.txt](https://github.com/vinifmor/bauh-files/blob/master/snap/suggestions.txt) - Minor memory improvements + ### Fixes - AUR: - an exception happens when retrieving matches from the cached AUR index diff --git a/bauh/gems/web/controller.py b/bauh/gems/web/controller.py index 679f6f66..f95f732d 100644 --- a/bauh/gems/web/controller.py +++ b/bauh/gems/web/controller.py @@ -784,17 +784,23 @@ class WebApplicationManager(SoftwareManager): suggestion_list.sort(key=lambda s: s.get('priority', 0), reverse=True) if filter_installed: - installed = self.read_installed(disk_loader=None) - url_map = {self._strip_url_protocol(s['url']): idx for idx, s in enumerate(suggestion_list)} + installed = {self._strip_url_protocol(i.url) for i in self.read_installed(disk_loader=None).installed} + else: + installed = None - if installed.installed: - for i in installed.installed: - s_url = self._strip_url_protocol(i.url) - if s_url in url_map: - suggestion_list.pop(url_map[s_url]) + res = [] - to_map = suggestion_list if limit <= 0 else suggestion_list[0:limit] - res = [self._map_suggestion(s) for s in to_map] + for s in suggestion_list: + if limit <= 0 or len(res) < limit: + if installed: + surl = self._strip_url_protocol(s['url']) + + if surl in installed: + continue + + res.append(self._map_suggestion(s)) + else: + break if not self.env_settings and self.env_thread: self.env_thread.join()