mirror of
https://code.eliotberriot.com/funkwhale/funkwhale.git
synced 2025-10-04 17:49:16 +02:00
Revert "Revert "Fix #994: use PostgreSQL full-text-search""
This reverts commit 7b0db234e2
.
This commit is contained in:
parent
c2cb510eb9
commit
57949c02c1
14 changed files with 368 additions and 38 deletions
|
@ -11,6 +11,8 @@ import pydub
|
|||
from django.conf import settings
|
||||
from django.contrib.contenttypes.fields import GenericRelation
|
||||
from django.contrib.postgres.fields import JSONField
|
||||
from django.contrib.postgres.search import SearchVectorField
|
||||
from django.contrib.postgres.indexes import GinIndex
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from django.core.files.base import ContentFile
|
||||
from django.core.serializers.json import DjangoJSONEncoder
|
||||
|
@ -19,7 +21,6 @@ from django.db.models.signals import post_save, pre_save
|
|||
from django.dispatch import receiver
|
||||
from django.urls import reverse
|
||||
from django.utils import timezone
|
||||
|
||||
from versatileimagefield.fields import VersatileImageField
|
||||
|
||||
from funkwhale_api import musicbrainz
|
||||
|
@ -56,10 +57,14 @@ class APIModelMixin(models.Model):
|
|||
api_includes = []
|
||||
creation_date = models.DateTimeField(default=timezone.now, db_index=True)
|
||||
import_hooks = []
|
||||
body_text = SearchVectorField(blank=True)
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
ordering = ["-creation_date"]
|
||||
indexes = [
|
||||
GinIndex(fields=["body_text"]),
|
||||
]
|
||||
|
||||
@classmethod
|
||||
def get_or_create_from_api(cls, mbid):
|
||||
|
@ -171,7 +176,12 @@ class ArtistQuerySet(common_models.LocalFromFidQuerySet, models.QuerySet):
|
|||
|
||||
def with_albums(self):
|
||||
return self.prefetch_related(
|
||||
models.Prefetch("albums", queryset=Album.objects.with_tracks_count())
|
||||
models.Prefetch(
|
||||
"albums",
|
||||
queryset=Album.objects.with_tracks_count().select_related(
|
||||
"attachment_cover", "attributed_to"
|
||||
),
|
||||
)
|
||||
)
|
||||
|
||||
def annotate_playable_by_actor(self, actor):
|
||||
|
@ -524,6 +534,9 @@ class Track(APIModelMixin):
|
|||
|
||||
class Meta:
|
||||
ordering = ["album", "disc_number", "position"]
|
||||
indexes = [
|
||||
GinIndex(fields=["body_text"]),
|
||||
]
|
||||
|
||||
def __str__(self):
|
||||
return self.title
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue