Skip to content

Commit

Permalink
Improve the stability of the "Check for new Package versions" feature #…
Browse files Browse the repository at this point in the history
…17

Signed-off-by: tdruez <[email protected]>
  • Loading branch information
tdruez committed Dec 18, 2023
1 parent 05a3a25 commit 16011ef
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 15 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Release notes
=============

### Version 5.0.1-dev

- Improve the stability of the "Check for new Package versions" feature.
https://github.com/nexB/dejacode/issues/17

### Version 5.0.0

Initial release.
2 changes: 1 addition & 1 deletion dejacode/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from dejacode.celery import app as celery_app

VERSION = "5.0.0"
VERSION = "5.0.1-dev"
__version__ = VERSION
__all__ = ["celery_app"]

Expand Down
4 changes: 2 additions & 2 deletions dejacode_toolkit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def request_get(self, url, **kwargs):
response.raise_for_status()
return response.json()
except (requests.RequestException, ValueError, TypeError) as exception:
logger.debug(f"{self.label} [Exception] {exception}")
logger.error(f"{self.label} [Exception] {exception}")

def request_post(self, url, **kwargs):
"""
Expand All @@ -135,4 +135,4 @@ def request_post(self, url, **kwargs):
response.raise_for_status()
return response.json()
except (requests.RequestException, ValueError, TypeError) as exception:
logger.debug(f"{self.label} [Exception] {exception}")
logger.error(f"{self.label} [Exception] {exception}")
26 changes: 15 additions & 11 deletions product_portfolio/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1737,29 +1737,33 @@ def check_package_version_ajax_view(request, dataspace, name, version=""):
max_purls_per_request = 50
results = []
for purl_batch in chunked(purls, chunk_size=max_purls_per_request):
payload = {"purl": purl_batch, "page_size": len(purl_batch)}
response = purldb.request_get(payload)
results.extend(response["results"])
response = purldb.get_package_list(
page_size=max_purls_per_request,
extra_payload={"purl": purl_batch},
)
if response and response.get("results"):
results.extend(response["results"])

def get_latest_version_entry(current_uuid):
latest_version_entry = request.session.get(current_uuid)
if latest_version_entry:
return latest_version_entry

latest_version_entry = purldb.get_package(f"{current_uuid}/latest_version")
request.session[current_uuid] = latest_version_entry
return latest_version_entry
if latest_version_entry:
request.session[current_uuid] = latest_version_entry
return latest_version_entry

upgrade_available = []
for purldb_entry in results:
current_uuid = purldb_entry.get("uuid")
current_version = purldb_entry.get("version")
latest_version_entry = get_latest_version_entry(current_uuid)
latest_version = latest_version_entry.get("version")
if current_version != latest_version:
purldb_entry["latest_version"] = latest_version
purldb_entry["latest_version_uuid"] = latest_version_entry.get("uuid")
upgrade_available.append(purldb_entry)
if latest_version_entry := get_latest_version_entry(current_uuid):
latest_version = latest_version_entry.get("version")
if current_version != latest_version:
purldb_entry["latest_version"] = latest_version
purldb_entry["latest_version_uuid"] = latest_version_entry.get("uuid")
upgrade_available.append(purldb_entry)

return JsonResponse({"success": "success", "upgrade_available": upgrade_available})

Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = dejacode
version = 5.0.0
version = 5.0.1-dev
license = AGPL-3.0-only
description = Automate open source license compliance and ensure supply chain integrity
long_description = file:README.rst
Expand Down

0 comments on commit 16011ef

Please sign in to comment.