Skip to content

Commit

Permalink
Optimized imports + fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonLovesDoggo committed Apr 6, 2024
1 parent b1616c2 commit 2c59af7
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 15 deletions.
2 changes: 1 addition & 1 deletion gameserver/api/routes.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import datetime
from typing import Any, List

from django.db.models import Case, F, OuterRef, Q, Subquery, When
from django.db.models import F, OuterRef, Subquery
from django.shortcuts import get_object_or_404
from ninja import NinjaAPI, Schema

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Generated by Django 4.0.1 on 2024-03-11 01:49

import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion

import gameserver.models.profile


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Generated by Django 5.0.4 on 2024-04-04 13:44

from django.db import migrations, models

import gameserver


Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Generated by Django 5.0.4 on 2024-04-06 16:06

import gameserver.models.profile
from django.db import migrations, models

import gameserver.models.profile


class Migration(migrations.Migration):
dependencies = [
Expand Down
2 changes: 1 addition & 1 deletion gameserver/models/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def update_or_create(
cls.objects.create(
participation=participant, flag_count=int(update_flags), points=change_in_score
)

with transaction.atomic():
queryset.select_for_update() # prevent race conditions with other team members

Expand Down
17 changes: 11 additions & 6 deletions gameserver/models/contest.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
import logging
from datetime import timedelta

import aiohttp
from django.apps import apps
from django.contrib.auth.models import Permission
from django.contrib.contenttypes.models import ContentType
from django.contrib.sites.models import Site
from django.core.cache import cache
from django.core.cache.utils import make_template_fragment_key
from django.core.validators import MinValueValidator
from django.db import models
from django.db.models import Count, F, Max, Min, OuterRef, Q, Subquery, Sum
from django.db.models.expressions import Window
from django.db.models.functions import Coalesce, Rank
from django.db.models.signals import post_save
from django.dispatch import receiver
from django.urls import reverse
from django.utils import timezone
from django.utils.functional import cached_property
Expand All @@ -24,7 +19,6 @@
from ..templatetags.common_tags import strfdelta
from . import abstract

logger = logging.getLogger(__name__)
# Create your models here.


Expand Down Expand Up @@ -436,6 +430,17 @@ def is_firstblood(self):

return prev_correct_submissions.count() == 1 and prev_correct_submissions.first() == self

@property
async def ais_firstblooded(self):
prev_correct_submissions = ContestSubmission.objects.filter(
problem=self.problem, submission__is_correct=True, pk__lte=self.pk
)

return (
await prev_correct_submissions.acount() == 1
and await prev_correct_submissions.afirst() == self
)

def save(self, *args, **kwargs):
for key in cache.get(f"contest_ranks_{self.participation.contest.pk}", default=[]):
cache.delete(key)
Expand Down
2 changes: 1 addition & 1 deletion gameserver/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.urls import include, path
from django.urls import path

from . import views
from .api.routes import api
Expand Down
1 change: 1 addition & 0 deletions gameserver/utils/challenge.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
logger.error("failed to connect to challenge cluster")
raise Exception("failed to connect to challenge cluster")


def create_challenge_instance(challenge_spec, problem_id, problem_flag, instance_owner, wait=False):
def generate_identifier():
return uuid.uuid4().hex[-7:]
Expand Down
5 changes: 1 addition & 4 deletions gameserver/views/contest.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,7 @@ def get_form_kwargs(self, *args, **kwargs):
def form_valid(self, form):
team = form.cleaned_data["participant"]

if (
self.request.in_contest
and self.request.user.current_contest.contest == self.object
):
if self.request.in_contest and self.request.user.current_contest.contest == self.object:
contest_participation = models.ContestParticipation.objects.get_or_create(
team=team, contest=self.object
)[0]
Expand Down

0 comments on commit 2c59af7

Please sign in to comment.