Skip to content

Commit

Permalink
Proper pagination for Dependencies tab #138
Browse files Browse the repository at this point in the history
Also improve QS performance for the inventory tab

Signed-off-by: tdruez <[email protected]>
  • Loading branch information
tdruez committed Jul 17, 2024
1 parent bc6476a commit 6b22815
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@
</form>
</li>
<li class="nav-item">
<div class="h6 mt-2 mb-0 smaller">{{ page_obj.paginator.count|intcomma }} results</div>
<div class="h6 mt-2 mb-0 smaller">
{% if page_obj.paginator.count != inventory_count %}
{{ page_obj.paginator.count|intcomma }} of
<a href="?all=true#inventory">{{ inventory_count|intcomma }} results</a>
{% else %}
{{ page_obj.paginator.count|intcomma }} results
{% endif %}
</div>
</li>
</ul>
</div>
Expand Down Expand Up @@ -52,7 +59,7 @@
</tr>
</thead>
<tbody class="text-break">
{% for dependency in filter_dependency.qs %}
{% for dependency in page_obj.object_list %}
<tr class="{% cycle 'odd' '' %}">
<td>
{% if dependency.for_package %}
Expand Down Expand Up @@ -102,4 +109,7 @@
{% endfor %}
</tbody>
</table>
<div class="d-flex justify-content-center">
{% include 'pagination/object_list_pagination.html' %}
</div>
{% endspaceless %}
73 changes: 52 additions & 21 deletions product_portfolio/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,39 +638,70 @@ def get_context_data(self, **kwargs):

context["inventory_count"] = self.object.productinventoryitem_set.count()

licenses_prefetch = models.Prefetch(
"licenses", License.objects.select_related("usage_policy")
)

productpackage_qs = (
self.object.productpackages.select_related(
"package__dataspace",
"package__usage_policy",
"review_status",
"purpose",
)
.prefetch_related(
licenses_prefetch,
)
.order_by(
"feature",
"package__type",
"package__namespace",
"package__name",
"package__version",
"package__filename",
)
)

filter_productpackage = ProductPackageFilterSet(
self.request.GET,
queryset=self.object.productpackages,
queryset=productpackage_qs,
dataspace=self.object.dataspace,
prefix="inventory",
anchor="#inventory",
)

productcomponent_qs = (
self.object.productcomponents.select_related(
"component__dataspace",
"component__owner__dataspace",
"component__usage_policy",
"review_status",
"purpose",
)
.prefetch_related(
"component__packages",
"component__children",
licenses_prefetch,
)
.order_by(
"feature",
"component__name",
"component__version",
"name",
"version",
)
)

filter_productcomponent = ProductComponentFilterSet(
self.request.GET,
queryset=self.object.productcomponents,
queryset=productcomponent_qs,
dataspace=self.object.dataspace,
prefix="inventory",
anchor="#inventory",
)

productcomponent_qs = filter_productcomponent.qs.order_by(
"feature",
"component__name",
"component__version",
"name",
"version",
)

productpackage_qs = filter_productpackage.qs.order_by(
"feature",
"package__type",
"package__namespace",
"package__name",
"package__version",
"package__filename",
)

productcomponent_qs = filter_productcomponent.qs
productpackage_qs = filter_productpackage.qs
# 1. Combine components and packages into a single list of object
filtered_inventory_items = list(productcomponent_qs) + list(productpackage_qs)

Expand Down Expand Up @@ -924,8 +955,8 @@ def get_context_data(self, **kwargs):
context_data = super().get_context_data(**kwargs)

dependency_qs = self.object.dependencies.select_related(
"for_package",
"resolved_to_package",
"for_package__dataspace",
"resolved_to_package__dataspace",
)

filter_dependency = DependencyFilterSet(
Expand Down

0 comments on commit 6b22815

Please sign in to comment.