Skip to content

Commit

Permalink
Sadness
Browse files Browse the repository at this point in the history
  • Loading branch information
rixx committed Sep 27, 2024
1 parent 56b9f0c commit 62e7c50
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/pretalx/person/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import random
import uuid
from contextlib import suppress
from functools import cache
from hashlib import md5
from urllib.parse import urljoin

Expand Down Expand Up @@ -141,6 +140,7 @@ def __str__(self) -> str:
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.permission_cache = {}
self.event_profile_cache = {}
self.team_permissions = {}

def has_perm(self, perm, obj, *args, **kwargs):
Expand Down Expand Up @@ -171,7 +171,6 @@ def save(self, *args, **kwargs):
gravatar_cache.apply_async(args=(self.pk,), ignore_result=True)
return result

@cache # noqa: B019
def event_profile(self, event):
"""Retrieve (and/or create) the event.
Expand All @@ -180,15 +179,21 @@ def event_profile(self, event):
:type event: :class:`pretalx.event.models.event.Event`
:retval: :class:`pretalx.person.models.profile.EventProfile`
"""
from pretalx.person.models.profile import SpeakerProfile
if event.pk and (profile := self.event_profile_cache.get(event.pk)):
return profile

try:
return self.profiles.select_related("event").get(event=event)
profile = self.profiles.select_related("event").get(event=event)
except Exception:
from pretalx.person.models.profile import SpeakerProfile

profile = SpeakerProfile(event=event, user=self)
if self.pk:
profile.save()
return profile

if event.pk:
self.event_profile_cache[event.pk] = profile
return profile

def get_locale_for_event(self, event):
if self.locale in event.locales:
Expand Down

0 comments on commit 62e7c50

Please sign in to comment.