Skip to content

Commit 1d923d4

Browse files
authored
Proxito: test new implementation more broadly (#10599)
* Proxito: test new implementation more broadly With this we can now exclude some projects from using the new implementation while testing it more broadly by changing the date of the feature. When we are ready to enable it for all projects, we can remove the USE_UNRESOLVER_WITH_PROXITO, and leave the other setting while we migrate the missing projects. * Format * Revert tests They will break on .com :( * Update from review
1 parent 713bdbd commit 1d923d4

File tree

5 files changed

+26
-16
lines changed

5 files changed

+26
-16
lines changed

readthedocs/api/v2/serializers.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,7 @@ class ProjectAdminSerializer(ProjectSerializer):
4343
general API, mostly for fields used in the build process
4444
"""
4545

46-
features = serializers.SlugRelatedField(
47-
many=True,
48-
read_only=True,
49-
slug_field='feature_id',
50-
)
51-
46+
features = serializers.ReadOnlyField()
5247
environment_variables = serializers.SerializerMethodField()
5348
skip = serializers.SerializerMethodField()
5449

readthedocs/projects/models.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,9 +1300,11 @@ def get_canonical_custom_domain(self):
13001300

13011301
return self.domains.filter(canonical=True).first()
13021302

1303-
@property
1303+
@cached_property
13041304
def features(self):
1305-
return Feature.objects.for_project(self)
1305+
return list(
1306+
Feature.objects.for_project(self).values_list("feature_id", flat=True)
1307+
)
13061308

13071309
def has_feature(self, feature_id):
13081310
"""
@@ -1312,7 +1314,7 @@ def has_feature(self, feature_id):
13121314
we consider the project to have the flag. This is used for deprecating a
13131315
feature or changing behavior for new projects
13141316
"""
1315-
return self.features.filter(feature_id=feature_id).exists()
1317+
return feature_id in self.features
13161318

13171319
def get_feature_value(self, feature, positive, negative):
13181320
"""
@@ -1450,9 +1452,6 @@ def __init__(self, *args, **kwargs):
14501452
def save(self, *args, **kwargs):
14511453
return 0
14521454

1453-
def has_feature(self, feature_id):
1454-
return feature_id in self.features
1455-
14561455
@property
14571456
def show_advertising(self):
14581457
"""Whether this project is ad-free (don't access the database)."""
@@ -1924,6 +1923,7 @@ def add_features(sender, **kwargs):
19241923
DISABLE_PAGEVIEWS = "disable_pageviews"
19251924
RESOLVE_PROJECT_FROM_HEADER = "resolve_project_from_header"
19261925
USE_UNRESOLVER_WITH_PROXITO = "use_unresolver_with_proxito"
1926+
USE_OLD_PROXITO_IMPLEMENTATION = "use_old_proxito_implementation"
19271927
ALLOW_VERSION_WARNING_BANNER = "allow_version_warning_banner"
19281928

19291929
# Versions sync related features
@@ -2015,6 +2015,12 @@ def add_features(sender, **kwargs):
20152015
"Proxito: Use new unresolver implementation for serving documentation files."
20162016
),
20172017
),
2018+
(
2019+
USE_OLD_PROXITO_IMPLEMENTATION,
2020+
_(
2021+
"Proxito: Use old Proxito implementation (no unresolver) for serving documentation files."
2022+
),
2023+
),
20182024
(
20192025
ALLOW_VERSION_WARNING_BANNER,
20202026
_("Dashboard: Allow project to use the version warning banner."),

readthedocs/proxito/middleware.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,9 @@ def process_request(self, request): # noqa
269269

270270
# This is hacky because Django wants a module for the URLConf,
271271
# instead of also accepting string
272-
if project.urlconf and not project.has_feature(
273-
Feature.USE_UNRESOLVER_WITH_PROXITO
272+
if project.urlconf and (
273+
project.has_feature(Feature.USE_OLD_PROXITO_IMPLEMENTATION)
274+
or not project.has_feature(Feature.USE_UNRESOLVER_WITH_PROXITO)
274275
):
275276
# Stop Django from caching URLs
276277
# https://github.com/django/django/blob/7cf7d74/django/urls/resolvers.py#L65-L69 # noqa

readthedocs/proxito/views/serve.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,10 @@ def get(
140140
# and we don't want to issue infinite redirects.
141141
pass
142142

143-
if unresolved_domain.project.has_feature(Feature.USE_UNRESOLVER_WITH_PROXITO):
143+
use_new_implementation = not unresolved_domain.project.has_feature(
144+
Feature.USE_OLD_PROXITO_IMPLEMENTATION
145+
) and unresolved_domain.project.has_feature(Feature.USE_UNRESOLVER_WITH_PROXITO)
146+
if use_new_implementation:
144147
return self.get_using_unresolver(request)
145148

146149
original_version_slug = version_slug
@@ -528,7 +531,10 @@ def get(self, request, proxito_path, template_name="404.html"):
528531
log.debug('Executing 404 handler.')
529532

530533
unresolved_domain = request.unresolved_domain
531-
if unresolved_domain.project.has_feature(Feature.USE_UNRESOLVER_WITH_PROXITO):
534+
use_new_implementation = not unresolved_domain.project.has_feature(
535+
Feature.USE_OLD_PROXITO_IMPLEMENTATION
536+
) and unresolved_domain.project.has_feature(Feature.USE_UNRESOLVER_WITH_PROXITO)
537+
if use_new_implementation:
532538
return self.get_using_unresolver(request, proxito_path)
533539

534540
# Parse the URL using the normal urlconf, so we get proper subdomain/translation data

readthedocs/rtd_tests/tests/test_backend.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,8 @@ def test_use_shallow_clone(self):
294294
repo.update()
295295
repo.checkout('submodule')
296296
self.assertTrue(repo.use_shallow_clone())
297+
# Clear cache
298+
del self.project.features
297299
fixture.get(
298300
Feature,
299301
projects=[self.project],

0 commit comments

Comments
 (0)