mirror of
https://github.com/ae-utbm/sith.git
synced 2024-12-23 00:01:16 +00:00
fix N+1 queries on user search
This commit is contained in:
parent
9591162cc9
commit
0b509f2200
@ -4,6 +4,7 @@ from typing import Annotated
|
|||||||
from annotated_types import MinLen
|
from annotated_types import MinLen
|
||||||
from django.contrib.staticfiles.storage import staticfiles_storage
|
from django.contrib.staticfiles.storage import staticfiles_storage
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
|
from django.urls import reverse
|
||||||
from django.utils.text import slugify
|
from django.utils.text import slugify
|
||||||
from haystack.query import SearchQuerySet
|
from haystack.query import SearchQuerySet
|
||||||
from ninja import FilterSchema, ModelSchema, Schema
|
from ninja import FilterSchema, ModelSchema, Schema
|
||||||
@ -37,13 +38,13 @@ class UserProfileSchema(ModelSchema):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def resolve_profile_url(obj: User) -> str:
|
def resolve_profile_url(obj: User) -> str:
|
||||||
return obj.get_absolute_url()
|
return reverse("core:user_profile", kwargs={"user_id": obj.pk})
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def resolve_profile_pict(obj: User) -> str:
|
def resolve_profile_pict(obj: User) -> str:
|
||||||
if obj.profile_pict_id is None:
|
if obj.profile_pict_id is None:
|
||||||
return staticfiles_storage.url("core/img/unknown.jpg")
|
return staticfiles_storage.url("core/img/unknown.jpg")
|
||||||
return obj.profile_pict.get_download_url()
|
return reverse("core:download", kwargs={"file_id": obj.profile_pict_id})
|
||||||
|
|
||||||
|
|
||||||
class SithFileSchema(ModelSchema):
|
class SithFileSchema(ModelSchema):
|
||||||
|
Loading…
Reference in New Issue
Block a user