improvement: suggestions are now retrieved asynchronously

This commit is contained in:
Vinicius Moreira
2019-08-06 19:08:34 -03:00
parent 2d8c9bdf20
commit 1565d418e9
2 changed files with 19 additions and 4 deletions

View File

@@ -5,8 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
## [0.5.1]
### Improvements:
- suggestions are now retrieved asynchronously. Response time takes 45% less.
### Fixes:
- flatpak dependency
- [flatpak dependency](https://github.com/vinifmor/fpakman/issues/36)
## [0.5.0] - 2019-08-06
### Improvements

View File

@@ -1,6 +1,7 @@
import time
from abc import ABC, abstractmethod
from argparse import Namespace
from threading import Thread
from typing import List, Dict
from fpakman.core.disk import DiskCacheLoader, DiskCacheLoaderFactory
@@ -290,10 +291,22 @@ class GenericApplicationManager(ApplicationManager):
return warnings
def _fill_suggestions(self, suggestions: list, man: ApplicationManager):
if self._is_enabled(man):
suggestions.extend(man.list_suggestions(6))
def list_suggestions(self, limit: int) -> List[Application]:
ti = time.time()
if self.managers:
suggestions = []
suggestions, threads = [], []
for man in self.managers:
if self._is_enabled(man):
suggestions.extend(man.list_suggestions(6))
t = Thread(target=self._fill_suggestions, args=(suggestions, man))
t.start()
threads.append(t)
for t in threads:
t.join()
tf = time.time() - ti
print(tf)
return suggestions