Skip to content

Commit

Permalink
Addons: improve DB query for projects_feature table (#10871)
Browse files Browse the repository at this point in the history
This small improvements reduces the db query from ~20ms to ~1ms.
  • Loading branch information
humitos committed Oct 26, 2023
1 parent f75e4de commit 90f1791
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion readthedocs/proxito/views/hosting.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,13 @@ def _v0(self, project, version, build, filename, url, user):
)
# Make one DB query here and then check on Python code
# TODO: make usage of ``Project.addons.<name>_enabled`` to decide if enabled
project_features = project.features.all().values_list("feature_id", flat=True)
#
# NOTE: using ``feature_id__startswith="addons_"`` to make the query faster.
# It went down from 20ms to 1ms since it does not have to check the
# `Project.pub_date` against all the features.
project_features = project.features.filter(
feature_id__startswith="addons_"
).values_list("feature_id", flat=True)

data = {
"api_version": "0",
Expand Down

0 comments on commit 90f1791

Please sign in to comment.