From 90f17910c1486e002a900028ddf8bd85729eeb78 Mon Sep 17 00:00:00 2001 From: Manuel Kaufmann Date: Thu, 26 Oct 2023 11:53:22 +0200 Subject: [PATCH] Addons: improve DB query for `projects_feature` table (#10871) This small improvements reduces the db query from ~20ms to ~1ms. --- readthedocs/proxito/views/hosting.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/readthedocs/proxito/views/hosting.py b/readthedocs/proxito/views/hosting.py index 1e9bcc510ce..e0dd251e2e0 100644 --- a/readthedocs/proxito/views/hosting.py +++ b/readthedocs/proxito/views/hosting.py @@ -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._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",