Remove deprecated search_garbage_collect

Wagtail 5.0 advised that this old command should no longer be used.
https://docs.wagtail.org/en/stable/releases/5.0.html#managing-stored-search-queries

However, it was not fully removed from the documentation or the code.
pull/10934/head
LB Johnston 2023-09-28 07:04:00 +10:00 zatwierdzone przez LB (Ben Johnston)
rodzic a008554b9c
commit ee533ac1a7
3 zmienionych plików z 0 dodań i 66 usunięć

Wyświetl plik

@ -148,12 +148,6 @@ python manage.py rebuild_references_index --verbosity 0
Displays a summary of the contents of the references index. This shows the number of objects indexed against each model type, and can be useful to identify which models are being indexed without rebuilding the index itself.
## search_garbage_collect
```sh
./manage.py search_garbage_collect
```
(wagtail_update_image_renditions)=
## wagtail_update_image_renditions

Wyświetl plik

@ -1,16 +0,0 @@
from django.core.management.base import BaseCommand
from wagtail.search import models
class Command(BaseCommand):
def handle(self, **options):
# Clean daily hits
self.stdout.write("Cleaning daily hits records…")
models.QueryDailyHits.garbage_collect()
self.stdout.write("Done")
# Clean queries
self.stdout.write("Cleaning query records…")
models.Query.garbage_collect()
self.stdout.write("Done")

Wyświetl plik

@ -1,4 +1,3 @@
from django.core import management
from django.test import SimpleTestCase, TestCase
from wagtail.search import models
@ -109,49 +108,6 @@ class TestQueryPopularity(TestCase):
self.assertEqual(popular_queries[2], models.Query.get("little popular query"))
class TestGarbageCollectCommand(TestCase):
def test_garbage_collect_command(self):
nowdt = datetime.datetime.now()
old_hit_date = (nowdt - datetime.timedelta(days=14)).date()
recent_hit_date = (nowdt - datetime.timedelta(days=1)).date()
# Add 10 hits that are more than one week old. The related queries and the daily hits
# should be deleted by the search_garbage_collect command.
querie_ids_to_be_deleted = []
for i in range(10):
q = models.Query.get(f"Hello {i}")
q.add_hit(date=old_hit_date)
querie_ids_to_be_deleted.append(q.id)
# Add 10 hits that are less than one week old. These ones should not be deleted.
recent_querie_ids = []
for i in range(10):
q = models.Query.get(f"World {i}")
q.add_hit(date=recent_hit_date)
recent_querie_ids.append(q.id)
management.call_command("search_garbage_collect", stdout=StringIO())
self.assertFalse(
models.Query.objects.filter(id__in=querie_ids_to_be_deleted).exists()
)
self.assertFalse(
models.QueryDailyHits.objects.filter(
date=old_hit_date, query_id__in=querie_ids_to_be_deleted
).exists()
)
self.assertEqual(
models.Query.objects.filter(id__in=recent_querie_ids).count(), 10
)
self.assertEqual(
models.QueryDailyHits.objects.filter(
date=recent_hit_date, query_id__in=recent_querie_ids
).count(),
10,
)
class TestSeparateFiltersFromQuery(SimpleTestCase):
def test_only_query(self):
filters, query = separate_filters_from_query("hello world")