Skip to content

Commit

Permalink
Optimize queries for rendering the relations #659
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Druez <[email protected]>
  • Loading branch information
tdruez committed Apr 12, 2023
1 parent 0929eda commit a938f53
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
8 changes: 4 additions & 4 deletions scanpipe/templates/scanpipe/codebase_relation.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
<table class="table is-bordered is-narrow is-hoverable is-fullwidth">
<thead>
<tr>
<th>From resource</th>
<th style="width: 45%">From resource</th>
<th>Match type</th>
<th>To resource</th>
<th style="width: 45%">To resource</th>
</tr>
</thead>
<tbody>
Expand All @@ -32,7 +32,7 @@
{% if not request.GET.missing_only %}
<tr>
{% if forloop.first %}
<td class="break-all" style="min-width: 200px;" rowspan="{{ resource.related_to.count }}">
<td class="break-all" style="min-width: 200px;" rowspan="{{ resource.related_to.all|length }}">
<a class="modal-button is-black-link" data-target="file-content-modal" data-raw_url="{{ resource.get_raw_url }}" aria-haspopup="true">
<i class="far fa-file"></i>
</a>
Expand Down Expand Up @@ -90,7 +90,7 @@
{% if not request.GET.missing_only %}
<tr>
{% if forloop.first %}
<td class="break-all" style="min-width: 200px;" rowspan="{{ resource.related_from.count }}">
<td class="break-all" style="min-width: 200px;" rowspan="{{ resource.related_from.all|length }}">
<a class="modal-button is-black-link" data-target="file-content-modal" data-raw_url="{{ resource.get_raw_url }}" aria-haspopup="true">
<i class="far fa-file"></i>
</a>
Expand Down
13 changes: 9 additions & 4 deletions scanpipe/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -818,13 +818,18 @@ def get_context_data(self, **kwargs):
project = self.object
project_files = project.codebaseresources.files()

from_codebase_resources = project_files.from_codebase().prefetch_related(
"related_to__to_resource"
)
to_codebase_resources = project_files.to_codebase().prefetch_related(
"related_from__from_resource"
)

context.update(
{
"project": project,
"from_codebase_resources": project_files.from_codebase(),
"to_codebase_resources": project_files.to_codebase(),
# "missing_in_to": project_files.missing_in_to(),
# "missing_in_from": project_files.missing_in_from(),
"from_codebase_resources": from_codebase_resources,
"to_codebase_resources": to_codebase_resources,
}
)
return context
Expand Down

0 comments on commit a938f53

Please sign in to comment.