kopia lustrzana https://github.com/wagtail/wagtail
Allow configuration or override of QueryDailyHits garbage collection
rodzic
48296e7568
commit
5869bc37bb
|
@ -16,6 +16,7 @@ Changelog
|
|||
* Added pagination to "choose destination" view when moving pages (Nick Smith, Žan Anderle)
|
||||
* Added ability to annotate search results with score (Karl Hobley)
|
||||
* Added ability to limit access to form submissions (Mikalai Radchuk)
|
||||
* Added the ability to configure the number of days search logs are kept for (Stephen Rice)
|
||||
* Fix: Migrations for wagtailcore and project template are now reversible (Benjamin Bach)
|
||||
* Fix: The default image format label text ('Full width', 'Left-aligned', 'Right-aligned') is now localised (Mikalai Radchuk)
|
||||
* Fix: Text on the front-end 'password required' form is now marked for translation (Janneke Janssen)
|
||||
|
|
|
@ -178,11 +178,6 @@ Search
|
|||
|
||||
.. code-block:: python
|
||||
|
||||
# Override the search results template for wagtailsearch
|
||||
WAGTAILSEARCH_RESULTS_TEMPLATE = 'myapp/search_results.html'
|
||||
WAGTAILSEARCH_RESULTS_TEMPLATE_AJAX = 'myapp/includes/search_listing.html'
|
||||
|
||||
# Replace the search backend
|
||||
WAGTAILSEARCH_BACKENDS = {
|
||||
'default': {
|
||||
'BACKEND': 'wagtail.wagtailsearch.backends.elasticsearch2',
|
||||
|
@ -190,7 +185,22 @@ Search
|
|||
}
|
||||
}
|
||||
|
||||
The search settings customise the search results templates as well as choosing a custom backend for search. For a full explanation, see :ref:`search`.
|
||||
Define a search backend. For a full explanation, see :ref:`wagtailsearch_backends`.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
WAGTAILSEARCH_RESULTS_TEMPLATE = 'myapp/search_results.html'
|
||||
WAGTAILSEARCH_RESULTS_TEMPLATE_AJAX = 'myapp/includes/search_listing.html'
|
||||
|
||||
Override the templates used by the search front-end views.
|
||||
|
||||
.. _wagtailsearch_hits_max_age:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
WAGTAILSEARCH_HITS_MAX_AGE = 14
|
||||
|
||||
Set the number of days (default 7) that search query logs are kept for; these are used to identify popular search terms for :ref:`promoted search results <editors-picks>`. Queries older than this will be removed by the :ref:`search_garbage_collect` command.
|
||||
|
||||
|
||||
Embeds
|
||||
|
|
|
@ -95,4 +95,4 @@ search_garbage_collect
|
|||
|
||||
:code:`./manage.py search_garbage_collect`
|
||||
|
||||
Wagtail keeps a log of search queries that are popular on your website. On high traffic websites, this log may get big and you may want to clean out old search queries. This command cleans out all search query logs that are more than one week old.
|
||||
Wagtail keeps a log of search queries that are popular on your website. On high traffic websites, this log may get big and you may want to clean out old search queries. This command cleans out all search query logs that are more than one week old (or a number of days configurable through the :ref:`WAGTAILSEARCH_HITS_MAX_AGE <wagtailsearch_hits_max_age>` setting).
|
||||
|
|
|
@ -46,6 +46,7 @@ Minor features
|
|||
* Added pagination to "choose destination" view when moving pages (Nick Smith, Žan Anderle)
|
||||
* Added ability to annotate search results with score - see :ref:`wagtailsearch_annotating_results_with_score` (Karl Hobley)
|
||||
* Added ability to limit access to form submissions - see :ref:`filter_form_submissions_for_user` (Mikalai Radchuk)
|
||||
* Added the ability to configure the number of days search logs are kept for, through the :ref:`WAGTAILSEARCH_HITS_MAX_AGE <wagtailsearch_hits_max_age>` setting (Stephen Rice)
|
||||
|
||||
|
||||
Bug fixes
|
||||
|
|
|
@ -2,6 +2,7 @@ from __future__ import absolute_import, unicode_literals
|
|||
|
||||
import datetime
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import models
|
||||
from django.utils import timezone
|
||||
from django.utils.encoding import python_2_unicode_compatible
|
||||
|
@ -60,11 +61,12 @@ class QueryDailyHits(models.Model):
|
|||
hits = models.IntegerField(default=0)
|
||||
|
||||
@classmethod
|
||||
def garbage_collect(cls):
|
||||
def garbage_collect(cls, days=None):
|
||||
"""
|
||||
Deletes all QueryDailyHits records that are older than 7 days
|
||||
Deletes all QueryDailyHits records that are older than a set number of days
|
||||
"""
|
||||
min_date = timezone.now().date() - datetime.timedelta(days=7)
|
||||
days = getattr(settings, 'WAGTAILSEARCH_HITS_MAX_AGE', 7) if days is None else days
|
||||
min_date = timezone.now().date() - datetime.timedelta(days)
|
||||
|
||||
cls.objects.filter(date__lt=min_date).delete()
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue