Skip to content

Commit 33cb887

Browse files
authored
Search: use doctype from indexed pages instead of the db (#7984)
Since we did a re-index, we can use this value from the page instead of querying from the db, now all results will have correct urls for the given doctype :) Closes #7762
1 parent 6b0ec72 commit 33cb887

File tree

4 files changed

+32
-13
lines changed

4 files changed

+32
-13
lines changed

readthedocs/search/api.py

-4
Original file line numberDiff line numberDiff line change
@@ -189,15 +189,13 @@ def _get_all_projects_data(self):
189189
alias='alias',
190190
version=VersionData(
191191
"latest",
192-
"sphinx",
193192
"https://requests.readthedocs.io/en/latest/",
194193
),
195194
),
196195
"requests-oauth": ProjectData(
197196
alias=None,
198197
version=VersionData(
199198
"latest",
200-
"sphinx_htmldir",
201199
"https://requests-oauth.readthedocs.io/en/latest/",
202200
),
203201
),
@@ -215,7 +213,6 @@ def _get_all_projects_data(self):
215213
alias=None,
216214
version=VersionData(
217215
slug=main_version.slug,
218-
doctype=main_version.documentation_type,
219216
docs_url=main_project.get_docs_url(version_slug=main_version.slug),
220217
),
221218
)
@@ -246,7 +243,6 @@ def _get_all_projects_data(self):
246243
project_alias = subproject.superprojects.values_list('alias', flat=True).first()
247244
version_data = VersionData(
248245
slug=version.slug,
249-
doctype=version.documentation_type,
250246
docs_url=url,
251247
)
252248
projects_data[subproject.slug] = ProjectData(

readthedocs/search/serializers.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
# Structure used for storing cached data of a version mostly.
2424
ProjectData = namedtuple('ProjectData', ['version', 'alias'])
25-
VersionData = namedtuple('VersionData', ['slug', 'docs_url', 'doctype'])
25+
VersionData = namedtuple('VersionData', ['slug', 'docs_url'])
2626

2727

2828
class ProjectHighlightSerializer(serializers.Serializer):
@@ -89,7 +89,6 @@ def _get_project_data(self, obj):
8989
version_data = VersionData(
9090
slug=obj.version,
9191
docs_url=docs_url,
92-
doctype=None,
9392
)
9493
projects_data[obj.project] = ProjectData(
9594
alias=project_alias,
@@ -126,7 +125,7 @@ def _get_full_path(self, obj):
126125

127126
# Generate an appropriate link for the doctypes that use htmldir,
128127
# and always end it with / so it goes directly to proxito.
129-
if project_data.version.doctype in {SPHINX_HTMLDIR, MKDOCS}:
128+
if obj.doctype in {SPHINX_HTMLDIR, MKDOCS}:
130129
path = re.sub('(^|/)index.html$', '/', path)
131130

132131
return docs_url.rstrip('/') + '/' + path.lstrip('/')

readthedocs/search/tests/test_api.py

+30
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,11 @@ def test_search_correct_link_for_normal_page_html_projects(self, api_client, doc
410410
project.versions.update(documentation_type=doctype)
411411
version = project.versions.all().first()
412412

413+
# Refresh index
414+
version_files = HTMLFile.objects.all().filter(version=version)
415+
for f in version_files:
416+
PageDocument().update(f)
417+
413418
search_params = {
414419
'project': project.slug,
415420
'version': version.slug,
@@ -428,6 +433,11 @@ def test_search_correct_link_for_index_page_html_projects(self, api_client, doct
428433
project.versions.update(documentation_type=doctype)
429434
version = project.versions.all().first()
430435

436+
# Refresh index
437+
version_files = HTMLFile.objects.all().filter(version=version)
438+
for f in version_files:
439+
PageDocument().update(f)
440+
431441
search_params = {
432442
'project': project.slug,
433443
'version': version.slug,
@@ -446,6 +456,11 @@ def test_search_correct_link_for_index_page_subdirectory_html_projects(self, api
446456
project.versions.update(documentation_type=doctype)
447457
version = project.versions.all().first()
448458

459+
# Refresh index
460+
version_files = HTMLFile.objects.all().filter(version=version)
461+
for f in version_files:
462+
PageDocument().update(f)
463+
449464
search_params = {
450465
'project': project.slug,
451466
'version': version.slug,
@@ -464,6 +479,11 @@ def test_search_correct_link_for_normal_page_htmldir_projects(self, api_client,
464479
project.versions.update(documentation_type=doctype)
465480
version = project.versions.all().first()
466481

482+
# Refresh index
483+
version_files = HTMLFile.objects.all().filter(version=version)
484+
for f in version_files:
485+
PageDocument().update(f)
486+
467487
search_params = {
468488
'project': project.slug,
469489
'version': version.slug,
@@ -482,6 +502,11 @@ def test_search_correct_link_for_index_page_htmldir_projects(self, api_client, d
482502
project.versions.update(documentation_type=doctype)
483503
version = project.versions.all().first()
484504

505+
# Refresh index
506+
version_files = HTMLFile.objects.all().filter(version=version)
507+
for f in version_files:
508+
PageDocument().update(f)
509+
485510
search_params = {
486511
'project': project.slug,
487512
'version': version.slug,
@@ -500,6 +525,11 @@ def test_search_correct_link_for_index_page_subdirectory_htmldir_projects(self,
500525
project.versions.update(documentation_type=doctype)
501526
version = project.versions.all().first()
502527

528+
# Refresh index
529+
version_files = HTMLFile.objects.all().filter(version=version)
530+
for f in version_files:
531+
PageDocument().update(f)
532+
503533
search_params = {
504534
'project': project.slug,
505535
'version': version.slug,

readthedocs/search/views.py

-6
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,10 @@ def _get_project(self, project_slug):
5757
return project
5858

5959
def _get_project_data(self, project, version_slug):
60-
version_doctype = (
61-
project.versions
62-
.values_list('documentation_type', flat=True)
63-
.get(slug=version_slug)
64-
)
6560
docs_url = project.get_docs_url(version_slug=version_slug)
6661
version_data = VersionData(
6762
slug=version_slug,
6863
docs_url=docs_url,
69-
doctype=version_doctype,
7064
)
7165
project_data = {
7266
project.slug: ProjectData(

0 commit comments

Comments
 (0)