Skip to content

Commit

Permalink
refactor: Optimise landing page performance (#461)
Browse files Browse the repository at this point in the history
* refactor: Mark all datasets as browsable

* refactor: Optimise count by using estimate

* chore: Move estimate_count function to query.py

* revert: "chore: Move estimate_count function to query.py"

ref: cc28c65

* revert: "refactor: Optimise count by using estimate"

ref: 46b5d1d

* refactor: Remove query for getting row count of api_ref_data
  • Loading branch information
microamp authored Aug 14, 2024
1 parent b4640cd commit 3cf8ab9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 22 deletions.
4 changes: 2 additions & 2 deletions main/templates/browse/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
<div class="{% include "_side_block_classes.html" %} md:row-span-3">
<p class="text-xs m-4">
{% if browsable_datasets %}
{{ total_indexed_human }} bibliographic&nbsp;items
now indexed among&nbsp;sources:
Bibliographic&nbsp;items
are indexed among&nbsp;sources:
{% for ds_id in browsable_datasets %}
<a class="{% if dataset_id == ds_id %}font-bold{% endif %}" href="{% url "browse_dataset" ds_id %}"
>{{ ds_id }}</a>{% if not forloop.last %}, {% endif %}
Expand Down
21 changes: 1 addition & 20 deletions main/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,28 +56,9 @@ def home(request):

metrics.gui_home_page_hits.inc()

non_empty_datasets = (
RefData.objects.values_list('dataset', flat=True).
distinct())

total_indexed_citations = RefData.objects.count()
units = ('', 'k', 'M', 'G', 'T', 'P')
factor = 1000.0
magnitude = int(floor(log_(max(abs(total_indexed_citations), 1), factor)))
total_indexed_human = '%.2f%s' % (
total_indexed_citations / factor**magnitude,
units[magnitude],
)

browsable_datasets = [
ds_id
for ds_id in settings.RELATON_DATASETS
if ds_id in non_empty_datasets]

return render(request, 'browse/home.html', dict(
**shared_context,
total_indexed_human=total_indexed_human,
browsable_datasets=browsable_datasets,
browsable_datasets=settings.RELATON_DATASETS,
))


Expand Down

0 comments on commit 3cf8ab9

Please sign in to comment.