|
14 | 14 | # You should have received a copy of the GNU General Public License |
15 | 15 | # along with Patchman. If not, see <http://www.gnu.org/licenses/> |
16 | 16 |
|
| 17 | +import concurrent.futures |
| 18 | + |
| 19 | +from django.db import connections |
| 20 | + |
17 | 21 | from util import tz_aware_datetime |
18 | 22 | from errata.models import Erratum |
19 | 23 | from packages.models import PackageUpdate |
@@ -61,24 +65,37 @@ def mark_errata_security_updates(): |
61 | 65 | """ For each set of erratum packages, modify any PackageUpdate that |
62 | 66 | should be marked as a security update. |
63 | 67 | """ |
| 68 | + connections.close_all() |
64 | 69 | elen = Erratum.objects.count() |
65 | | - pbar_start.send(sender=None, ptext=f'Scanning {elen} Errata', plen=elen) |
66 | | - for i, e in enumerate(Erratum.objects.all()): |
67 | | - pbar_update.send(sender=None, index=i + 1) |
68 | | - e.scan_for_security_updates() |
| 70 | + pbar_start.send(sender=None, ptext=f'Scanning {elen} Errata for security updates', plen=elen) |
| 71 | + i = 0 |
| 72 | + with concurrent.futures.ProcessPoolExecutor(max_workers=25) as executor: |
| 73 | + futures = [executor.submit(e.scan_for_security_updates) for e in Erratum.objects.all()] |
| 74 | + for future in concurrent.futures.as_completed(futures): |
| 75 | + pbar_update.send(sender=None, index=i + 1) |
| 76 | + i += 1 |
69 | 77 |
|
70 | 78 |
|
71 | 79 | def scan_package_updates_for_affected_packages(): |
72 | 80 | """ Scan PackageUpdates for packages affected by errata |
73 | 81 | """ |
74 | | - for pu in PackageUpdate.objects.all(): |
| 82 | + plen = PackageUpdate.objects.count() |
| 83 | + pbar_start.send(sender=None, ptext=f'Scanning {plen} Updates for affected packages', plen=plen) |
| 84 | + for i, pu in enumerate(PackageUpdate.objects.all()): |
| 85 | + pbar_update.send(sender=None, index=i + 1) |
75 | 86 | for e in pu.newpackage.provides_fix_in_erratum.all(): |
76 | 87 | e.affected_packages.add(pu.oldpackage) |
77 | 88 |
|
78 | 89 |
|
79 | | -def add_errata_affected_packages(): |
| 90 | +def enrich_errata(): |
| 91 | + """ Enrich Errata with data from osv.dev |
| 92 | + """ |
| 93 | + connections.close_all() |
80 | 94 | elen = Erratum.objects.count() |
81 | | - pbar_start.send(sender=None, ptext=f'Adding affected packages to {elen} Errata', plen=elen) |
82 | | - for i, e in enumerate(Erratum.objects.all()): |
83 | | - pbar_update.send(sender=None, index=i + 1) |
84 | | - e.fetch_osv_dev_data() |
| 95 | + pbar_start.send(sender=None, ptext=f'Adding osv.dev data to {elen} Errata', plen=elen) |
| 96 | + i = 0 |
| 97 | + with concurrent.futures.ProcessPoolExecutor(max_workers=25) as executor: |
| 98 | + futures = [executor.submit(e.fetch_osv_dev_data) for e in Erratum.objects.all()] |
| 99 | + for future in concurrent.futures.as_completed(futures): |
| 100 | + pbar_update.send(sender=None, index=i + 1) |
| 101 | + i += 1 |
0 commit comments