kopia lustrzana https://dev.funkwhale.audio/funkwhale/funkwhale
See #890: tweaks / perf improvements
rodzic
b363d1117c
commit
7a7cc55143
|
@ -90,6 +90,10 @@ def get_boolean_filter(name):
|
||||||
return {"handler": lambda v: Q(**{name: clean_boolean_filter(v)})}
|
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):
|
class DummyTypedMultipleChoiceField(forms.TypedMultipleChoiceField):
|
||||||
def valid_value(self, value):
|
def valid_value(self, value):
|
||||||
return True
|
return True
|
||||||
|
|
|
@ -11,6 +11,8 @@ from funkwhale_api.common import search
|
||||||
from funkwhale_api.federation import models as federation_models
|
from funkwhale_api.federation import models as federation_models
|
||||||
from funkwhale_api.federation import utils as federation_utils
|
from funkwhale_api.federation import utils as federation_utils
|
||||||
from funkwhale_api.moderation import models as moderation_models
|
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 models as music_models
|
||||||
from funkwhale_api.users import models as users_models
|
from funkwhale_api.users import models as users_models
|
||||||
from funkwhale_api.tags import models as tags_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"),
|
"assigned_to": get_actor_filter("assigned_to"),
|
||||||
"target_owner": get_actor_filter("target_owner"),
|
"target_owner": get_actor_filter("target_owner"),
|
||||||
"submitter_email": {"to": "submitter_email"},
|
"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={
|
filter_fields={
|
||||||
"uuid": {"to": "uuid"},
|
"uuid": {"to": "uuid"},
|
||||||
"author": get_actor_filter("author"),
|
"author": get_actor_filter("author"),
|
||||||
|
"target": common_filters.get_generic_relation_filter("target", moderation_utils.NOTE_TARGET_FIELDS),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
|
@ -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.federation import tasks as federation_tasks
|
||||||
from funkwhale_api.moderation import models as moderation_models
|
from funkwhale_api.moderation import models as moderation_models
|
||||||
from funkwhale_api.moderation import serializers as moderation_serializers
|
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 models as music_models
|
||||||
from funkwhale_api.music import serializers as music_serializers
|
from funkwhale_api.music import serializers as music_serializers
|
||||||
from funkwhale_api.tags import models as tags_models
|
from funkwhale_api.tags import models as tags_models
|
||||||
|
@ -680,21 +681,9 @@ class ManageReportSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
|
|
||||||
class ManageNoteSerializer(serializers.ModelSerializer):
|
class ManageNoteSerializer(serializers.ModelSerializer):
|
||||||
author = ManageBaseActorSerializer(required=False)
|
author = ManageBaseActorSerializer(required=False, read_only=True)
|
||||||
target = common_fields.GenericRelation(
|
target = common_fields.GenericRelation(
|
||||||
{
|
moderation_utils.NOTE_TARGET_FIELDS
|
||||||
"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,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
|
@ -470,7 +470,8 @@ class ManageReportViewSet(
|
||||||
queryset = (
|
queryset = (
|
||||||
moderation_models.Report.objects.all()
|
moderation_models.Report.objects.all()
|
||||||
.order_by("-creation_date")
|
.order_by("-creation_date")
|
||||||
.select_related()
|
.select_related('submitter', 'target_owner', 'assigned_to', 'target_content_type')
|
||||||
|
.prefetch_related('target')
|
||||||
)
|
)
|
||||||
serializer_class = serializers.ManageReportSerializer
|
serializer_class = serializers.ManageReportSerializer
|
||||||
filterset_class = filters.ManageReportFilterSet
|
filterset_class = filters.ManageReportFilterSet
|
||||||
|
@ -487,7 +488,9 @@ class ManageNoteViewSet(
|
||||||
):
|
):
|
||||||
lookup_field = "uuid"
|
lookup_field = "uuid"
|
||||||
queryset = (
|
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
|
serializer_class = serializers.ManageNoteSerializer
|
||||||
filterset_class = filters.ManageNoteFilterSet
|
filterset_class = filters.ManageNoteFilterSet
|
||||||
|
|
|
@ -170,25 +170,25 @@ def get_target_owner(target):
|
||||||
|
|
||||||
return mapping[target.__class__](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(
|
TARGET_FIELD = common_fields.GenericRelation(
|
||||||
{
|
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,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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,
|
||||||
|
},
|
||||||
|
}
|
Ładowanie…
Reference in New Issue