feat: complete realtime challenge matchmaking
This commit is contained in:
@@ -77,6 +77,10 @@ class ContestQuestion(models.Model):
|
||||
|
||||
|
||||
class RealtimeMatch(models.Model):
|
||||
class MatchType(models.TextChoices):
|
||||
RANDOM = "random", "随机匹配"
|
||||
CHALLENGE = "challenge", "联机码约战"
|
||||
|
||||
class Status(models.TextChoices):
|
||||
WAITING = "waiting", "等待对手"
|
||||
ACTIVE = "active", "进行中"
|
||||
@@ -85,6 +89,12 @@ class RealtimeMatch(models.Model):
|
||||
|
||||
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
||||
contest = models.ForeignKey(Contest, on_delete=models.PROTECT)
|
||||
match_type = models.CharField(
|
||||
max_length=16,
|
||||
choices=MatchType.choices,
|
||||
default=MatchType.RANDOM,
|
||||
)
|
||||
challenge_code = models.CharField(max_length=8, unique=True, null=True, blank=True)
|
||||
player_one = models.ForeignKey(
|
||||
settings.AUTH_USER_MODEL, on_delete=models.PROTECT, related_name="matches_as_player_one"
|
||||
)
|
||||
@@ -106,13 +116,20 @@ class RealtimeMatch(models.Model):
|
||||
related_name="won_matches",
|
||||
)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
expires_at = models.DateTimeField(null=True, blank=True)
|
||||
started_at = models.DateTimeField(null=True, blank=True)
|
||||
completed_at = models.DateTimeField(null=True, blank=True)
|
||||
|
||||
class Meta:
|
||||
indexes = [
|
||||
models.Index(
|
||||
fields=("contest", "status", "player_one_rating", "created_at"),
|
||||
fields=(
|
||||
"contest",
|
||||
"match_type",
|
||||
"status",
|
||||
"player_one_rating",
|
||||
"created_at",
|
||||
),
|
||||
name="matchmaking_lookup_idx",
|
||||
)
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user