|
11 | 11 | from readthedocs.core.history import ExtraSimpleHistoryAdmin, set_change_reason
|
12 | 12 | from readthedocs.core.utils import trigger_build
|
13 | 13 | from readthedocs.notifications.views import SendNotificationView
|
| 14 | +from readthedocs.projects.tasks.search import reindex_version |
14 | 15 | from readthedocs.redirects.models import Redirect
|
15 |
| -from readthedocs.search.utils import _indexing_helper |
16 | 16 |
|
17 | 17 | from .forms import FeatureForm
|
18 | 18 | from .models import (
|
@@ -264,7 +264,6 @@ class ProjectAdmin(ExtraSimpleHistoryAdmin):
|
264 | 264 | "run_spam_rule_checks",
|
265 | 265 | "build_default_version",
|
266 | 266 | "reindex_active_versions",
|
267 |
| - "wipe_all_versions", |
268 | 267 | "import_tags_from_vcs",
|
269 | 268 | ]
|
270 | 269 |
|
@@ -362,66 +361,26 @@ def reindex_active_versions(self, request, queryset):
|
362 | 361 | """Reindex all active versions of the selected projects to ES."""
|
363 | 362 | qs_iterator = queryset.iterator()
|
364 | 363 | for project in qs_iterator:
|
365 |
| - version_qs = Version.internal.filter(project=project) |
366 |
| - active_versions = version_qs.filter(active=True) |
| 364 | + versions_id_to_reindex = project.versions.for_reindex().values_list( |
| 365 | + "pk", flat=True |
| 366 | + ) |
367 | 367 |
|
368 |
| - if not active_versions.exists(): |
| 368 | + if not versions_id_to_reindex.exists(): |
369 | 369 | self.message_user(
|
370 | 370 | request,
|
371 |
| - "No active versions of project {}".format(project), |
| 371 | + "No versions to be re-indexed for project {}".format(project), |
372 | 372 | messages.ERROR,
|
373 | 373 | )
|
374 | 374 | else:
|
375 |
| - html_objs_qs = [] |
376 |
| - for version in active_versions.iterator(): |
377 |
| - html_objs = HTMLFile.objects.filter( |
378 |
| - project=project, version=version |
379 |
| - ) |
380 |
| - |
381 |
| - if html_objs.exists(): |
382 |
| - html_objs_qs.append(html_objs) |
383 |
| - |
384 |
| - if html_objs_qs: |
385 |
| - _indexing_helper(html_objs_qs, wipe=False) |
| 375 | + for version_id in versions_id_to_reindex.iterator(): |
| 376 | + reindex_version.delay(version_id) |
386 | 377 |
|
387 | 378 | self.message_user(
|
388 | 379 | request,
|
389 | 380 | "Task initiated successfully for {}".format(project),
|
390 | 381 | messages.SUCCESS,
|
391 | 382 | )
|
392 | 383 |
|
393 |
| - # TODO: rename method to mention "indexes" on its name |
394 |
| - @admin.action(description="Wipe all versions from ES") |
395 |
| - def wipe_all_versions(self, request, queryset): |
396 |
| - """Wipe indexes of all versions of selected projects.""" |
397 |
| - qs_iterator = queryset.iterator() |
398 |
| - for project in qs_iterator: |
399 |
| - version_qs = Version.internal.filter(project=project) |
400 |
| - if not version_qs.exists(): |
401 |
| - self.message_user( |
402 |
| - request, |
403 |
| - "No active versions of project {}.".format(project), |
404 |
| - messages.ERROR, |
405 |
| - ) |
406 |
| - else: |
407 |
| - html_objs_qs = [] |
408 |
| - for version in version_qs.iterator(): |
409 |
| - html_objs = HTMLFile.objects.filter( |
410 |
| - project=project, version=version |
411 |
| - ) |
412 |
| - |
413 |
| - if html_objs.exists(): |
414 |
| - html_objs_qs.append(html_objs) |
415 |
| - |
416 |
| - if html_objs_qs: |
417 |
| - _indexing_helper(html_objs_qs, wipe=True) |
418 |
| - |
419 |
| - self.message_user( |
420 |
| - request, |
421 |
| - "Task initiated successfully for {}.".format(project), |
422 |
| - messages.SUCCESS, |
423 |
| - ) |
424 |
| - |
425 | 384 | @admin.action(description="Import tags from the version control API")
|
426 | 385 | def import_tags_from_vcs(self, request, queryset):
|
427 | 386 | for project in queryset.iterator():
|
|
0 commit comments