See #890: tweaks / perf improvements

environments/review-docs-rate-jr6phc/deployments/2479
Eliot Berriot 2019-08-29 14:00:10 +02:00
rodzic b363d1117c
commit 7a7cc55143
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: DD6965E2476E5C27
6 zmienionych plików z 56 dodań i 34 usunięć

Wyświetl plik

@ -90,6 +90,10 @@ def get_boolean_filter(name):
return {"handler": lambda v: Q(**{name: clean_boolean_filter(v)})}
def get_generic_relation_filter(relation_name, choices):
return {"handler": lambda v: fields.get_generic_filter_query(v, relation_name=relation_name, choices=choices)}
class DummyTypedMultipleChoiceField(forms.TypedMultipleChoiceField):
def valid_value(self, value):
return True

Wyświetl plik

@ -11,6 +11,8 @@ from funkwhale_api.common import search
from funkwhale_api.federation import models as federation_models
from funkwhale_api.federation import utils as federation_utils
from funkwhale_api.moderation import models as moderation_models
from funkwhale_api.moderation import serializers as moderation_serializers
from funkwhale_api.moderation import utils as moderation_utils
from funkwhale_api.music import models as music_models
from funkwhale_api.users import models as users_models
from funkwhale_api.tags import models as tags_models
@ -356,6 +358,7 @@ class ManageReportFilterSet(filters.FilterSet):
"assigned_to": get_actor_filter("assigned_to"),
"target_owner": get_actor_filter("target_owner"),
"submitter_email": {"to": "submitter_email"},
"target": common_filters.get_generic_relation_filter("target", moderation_serializers.TARGET_CONFIG),
},
)
)
@ -372,6 +375,7 @@ class ManageNoteFilterSet(filters.FilterSet):
filter_fields={
"uuid": {"to": "uuid"},
"author": get_actor_filter("author"),
"target": common_filters.get_generic_relation_filter("target", moderation_utils.NOTE_TARGET_FIELDS),
},
)
)

Wyświetl plik

@ -11,6 +11,7 @@ from funkwhale_api.federation import fields as federation_fields
from funkwhale_api.federation import tasks as federation_tasks
from funkwhale_api.moderation import models as moderation_models
from funkwhale_api.moderation import serializers as moderation_serializers
from funkwhale_api.moderation import utils as moderation_utils
from funkwhale_api.music import models as music_models
from funkwhale_api.music import serializers as music_serializers
from funkwhale_api.tags import models as tags_models
@ -680,21 +681,9 @@ class ManageReportSerializer(serializers.ModelSerializer):
class ManageNoteSerializer(serializers.ModelSerializer):
author = ManageBaseActorSerializer(required=False)
author = ManageBaseActorSerializer(required=False, read_only=True)
target = common_fields.GenericRelation(
{
"report": {
"queryset": moderation_models.Report.objects.all(),
"id_attr": "uuid",
"id_field": serializers.UUIDField(),
},
"account": {
"queryset": federation_models.Actor.objects.all(),
"id_attr": "full_username",
"id_field": serializers.EmailField(),
"get_query": moderation_serializers.get_actor_query,
},
}
moderation_utils.NOTE_TARGET_FIELDS
)
class Meta:

Wyświetl plik

@ -470,7 +470,8 @@ class ManageReportViewSet(
queryset = (
moderation_models.Report.objects.all()
.order_by("-creation_date")
.select_related()
.select_related('submitter', 'target_owner', 'assigned_to', 'target_content_type')
.prefetch_related('target')
)
serializer_class = serializers.ManageReportSerializer
filterset_class = filters.ManageReportFilterSet
@ -487,7 +488,9 @@ class ManageNoteViewSet(
):
lookup_field = "uuid"
queryset = (
moderation_models.Note.objects.all().order_by("-creation_date").select_related()
moderation_models.Note.objects.all().order_by("-creation_date")
.select_related('author', 'target_content_type')
.prefetch_related('target')
)
serializer_class = serializers.ManageNoteSerializer
filterset_class = filters.ManageNoteFilterSet

Wyświetl plik

@ -170,25 +170,25 @@ def get_target_owner(target):
return mapping[target.__class__](target)
TARGET_CONFIG = {
"artist": {"queryset": music_models.Artist.objects.all()},
"album": {"queryset": music_models.Album.objects.all()},
"track": {"queryset": music_models.Track.objects.all()},
"library": {
"queryset": music_models.Library.objects.all(),
"id_attr": "uuid",
"id_field": serializers.UUIDField(),
},
"playlist": {"queryset": playlists_models.Playlist.objects.all()},
"account": {
"queryset": federation_models.Actor.objects.all(),
"id_attr": "full_username",
"id_field": serializers.EmailField(),
"get_query": get_actor_query,
},
}
TARGET_FIELD = common_fields.GenericRelation(
{
"artist": {"queryset": music_models.Artist.objects.all()},
"album": {"queryset": music_models.Album.objects.all()},
"track": {"queryset": music_models.Track.objects.all()},
"library": {
"queryset": music_models.Library.objects.all(),
"id_attr": "uuid",
"id_field": serializers.UUIDField(),
},
"playlist": {"queryset": playlists_models.Playlist.objects.all()},
"account": {
"queryset": federation_models.Actor.objects.all(),
"id_attr": "full_username",
"id_field": serializers.EmailField(),
"get_query": get_actor_query,
},
}
TARGET_CONFIG
)

Wyświetl plik

@ -0,0 +1,22 @@
from rest_framework import serializers
from funkwhale_api.federation import models as federation_models
from . import models
from . import serializers as moderation_serializers
NOTE_TARGET_FIELDS = {
"report": {
"queryset": models.Report.objects.all(),
"id_attr": "uuid",
"id_field": serializers.UUIDField(),
},
"account": {
"queryset": federation_models.Actor.objects.all(),
"id_attr": "full_username",
"id_field": serializers.EmailField(),
"get_query": moderation_serializers.get_actor_query,
},
}