Small optimizations
This commit is contained in:
parent
995ff88c87
commit
d75a498d18
4 changed files with 26 additions and 27 deletions
|
@ -255,17 +255,18 @@ class Profile(models.Model):
|
||||||
|
|
||||||
@cache_wrapper(prefix="Pgbi2")
|
@cache_wrapper(prefix="Pgbi2")
|
||||||
def _get_basic_info(self):
|
def _get_basic_info(self):
|
||||||
profile_image_url = None
|
res = {
|
||||||
if self.profile_image:
|
|
||||||
profile_image_url = self.profile_image.url
|
|
||||||
return {
|
|
||||||
"first_name": self.user.first_name,
|
|
||||||
"last_name": self.user.last_name,
|
|
||||||
"email": self.user.email,
|
"email": self.user.email,
|
||||||
"username": self.user.username,
|
"username": self.user.username,
|
||||||
"mute": self.mute,
|
"mute": self.mute,
|
||||||
"profile_image_url": profile_image_url,
|
|
||||||
}
|
}
|
||||||
|
if self.user.first_name:
|
||||||
|
res["first_name"] = self.user.first_name
|
||||||
|
if self.user.last_name:
|
||||||
|
res["last_name"] = self.user.last_name
|
||||||
|
if self.profile_image:
|
||||||
|
res["profile_image_url"] = self.profile_image.url
|
||||||
|
return res
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def _cached_info(self):
|
def _cached_info(self):
|
||||||
|
@ -283,11 +284,11 @@ class Profile(models.Model):
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def first_name(self):
|
def first_name(self):
|
||||||
return self._cached_info["first_name"]
|
return self._cached_info.get("first_name", "")
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def last_name(self):
|
def last_name(self):
|
||||||
return self._cached_info["last_name"]
|
return self._cached_info.get("last_name", "")
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def email(self):
|
def email(self):
|
||||||
|
@ -299,7 +300,7 @@ class Profile(models.Model):
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def profile_image_url(self):
|
def profile_image_url(self):
|
||||||
return self._cached_info["profile_image_url"]
|
return self._cached_info.get("profile_image_url")
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def count_unseen_notifications(self):
|
def count_unseen_notifications(self):
|
||||||
|
|
|
@ -221,12 +221,6 @@ class Submission(models.Model):
|
||||||
return self.get_id_secret(self.id)
|
return self.get_id_secret(self.id)
|
||||||
|
|
||||||
def is_accessible_by(self, profile):
|
def is_accessible_by(self, profile):
|
||||||
from judge.utils.problems import (
|
|
||||||
user_completed_ids,
|
|
||||||
user_tester_ids,
|
|
||||||
user_editable_ids,
|
|
||||||
)
|
|
||||||
|
|
||||||
if not profile:
|
if not profile:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -236,15 +230,6 @@ class Submission(models.Model):
|
||||||
if profile.id == self.user_id:
|
if profile.id == self.user_id:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
if problem_id in user_editable_ids(profile):
|
|
||||||
return True
|
|
||||||
|
|
||||||
if self.problem_id in user_completed_ids(profile):
|
|
||||||
if self.problem.is_public:
|
|
||||||
return True
|
|
||||||
if problem_id in user_tester_ids(profile):
|
|
||||||
return True
|
|
||||||
|
|
||||||
if user.has_perm("judge.change_submission"):
|
if user.has_perm("judge.change_submission"):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -258,6 +243,21 @@ class Submission(models.Model):
|
||||||
if contest and contest.is_editable_by(user):
|
if contest and contest.is_editable_by(user):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
from judge.utils.problems import (
|
||||||
|
user_completed_ids,
|
||||||
|
user_tester_ids,
|
||||||
|
user_editable_ids,
|
||||||
|
)
|
||||||
|
|
||||||
|
if problem_id in user_editable_ids(profile):
|
||||||
|
return True
|
||||||
|
|
||||||
|
if self.problem_id in user_completed_ids(profile):
|
||||||
|
if self.problem.is_public:
|
||||||
|
return True
|
||||||
|
if problem_id in user_tester_ids(profile):
|
||||||
|
return True
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
|
@ -23,7 +23,6 @@ from judge.models import (
|
||||||
from judge.models.profile import Organization, OrganizationProfile
|
from judge.models.profile import Organization, OrganizationProfile
|
||||||
from judge.utils.cachedict import CacheDict
|
from judge.utils.cachedict import CacheDict
|
||||||
from judge.utils.diggpaginator import DiggPaginator
|
from judge.utils.diggpaginator import DiggPaginator
|
||||||
from judge.utils.problems import user_completed_ids
|
|
||||||
from judge.utils.tickets import filter_visible_tickets
|
from judge.utils.tickets import filter_visible_tickets
|
||||||
from judge.utils.views import TitleMixin
|
from judge.utils.views import TitleMixin
|
||||||
from judge.views.feed import FeedView
|
from judge.views.feed import FeedView
|
||||||
|
|
|
@ -41,7 +41,6 @@ from judge.models import ProblemTranslation
|
||||||
from judge.models import Profile
|
from judge.models import Profile
|
||||||
from judge.models import Submission
|
from judge.models import Submission
|
||||||
from judge.utils.problems import get_result_data
|
from judge.utils.problems import get_result_data
|
||||||
from judge.utils.problems import user_completed_ids, user_editable_ids, user_tester_ids
|
|
||||||
from judge.utils.problem_data import get_problem_case
|
from judge.utils.problem_data import get_problem_case
|
||||||
from judge.utils.raw_sql import join_sql_subquery, use_straight_join
|
from judge.utils.raw_sql import join_sql_subquery, use_straight_join
|
||||||
from judge.utils.views import DiggPaginatorMixin
|
from judge.utils.views import DiggPaginatorMixin
|
||||||
|
|
Loading…
Reference in a new issue