Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# Generated by Django 5.2.4 on 2025-10-02 17:07

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


class Migration(migrations.Migration):

dependencies = [
('clubs', '0131_alter_club_tags'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.AlterField(
model_name='applicationsubmission',
name='status',
field=models.IntegerField(choices=[(1, 'Pending'), (2, 'Rejected after written application'), (3, 'Rejected after interview(s)'), (4, 'Accepted')], db_index=True, default=1),
),
migrations.AlterField(
model_name='badge',
name='purpose',
field=models.CharField(choices=[('fair', 'Fair'), ('org', 'Organization')], db_index=True, max_length=255),
),
migrations.AlterField(
model_name='club',
name='archived',
field=models.BooleanField(db_index=True, default=False),
),
migrations.AlterField(
model_name='clubapplication',
name='application_end_time',
field=models.DateTimeField(db_index=True),
),
migrations.AlterField(
model_name='clubapplication',
name='application_start_time',
field=models.DateTimeField(db_index=True),
),
migrations.AlterField(
model_name='clubapplication',
name='result_release_time',
field=models.DateTimeField(db_index=True),
),
migrations.AlterField(
model_name='clubfair',
name='end_time',
field=models.DateTimeField(db_index=True),
),
migrations.AlterField(
model_name='clubfair',
name='start_time',
field=models.DateTimeField(db_index=True),
),
migrations.AlterField(
model_name='event',
name='ics_uuid',
field=models.UUIDField(db_index=True, default=uuid.uuid4),
),
migrations.AlterField(
model_name='event',
name='type',
field=models.IntegerField(choices=[(0, 'Other'), (1, 'Recruitment'), (2, 'GBM'), (3, 'Speaker'), (4, 'Activities Fair'), (5, 'Social'), (6, 'Career')], db_index=True, default=1),
),
migrations.AlterField(
model_name='eventshowing',
name='end_time',
field=models.DateTimeField(db_index=True),
),
migrations.AlterField(
model_name='historicalclub',
name='archived',
field=models.BooleanField(db_index=True, default=False),
),
migrations.AlterField(
model_name='membership',
name='role',
field=models.IntegerField(choices=[(0, 'Owner'), (10, 'Officer'), (20, 'Member')], db_index=True, default=20),
),
migrations.AlterField(
model_name='ticket',
name='type',
field=models.CharField(db_index=True, max_length=100),
),
migrations.AddIndex(
model_name='club',
index=models.Index(fields=['approved', 'archived'], name='clubs_club_approve_a30dc8_idx'),
),
migrations.AddIndex(
model_name='clubfair',
index=models.Index(fields=['end_time', 'start_time'], name='fair_time_idx'),
),
migrations.AddIndex(
model_name='clubvisit',
index=models.Index(fields=['club', 'visit_type', 'created_at'], name='clubs_clubv_club_id_3cfb7e_idx'),
),
migrations.AddIndex(
model_name='eventshowing',
index=models.Index(fields=['start_time', 'end_time'], name='clubs_event_start_t_d0f1a9_idx'),
),
migrations.AddIndex(
model_name='eventshowing',
index=models.Index(fields=['event', 'start_time'], name='event_start_idx'),
),
migrations.AddIndex(
model_name='ticket',
index=models.Index(fields=['showing', 'type'], name='clubs_ticke_showing_94ab22_idx'),
),
migrations.AddIndex(
model_name='ticket',
index=models.Index(fields=['showing', 'owner'], name='clubs_ticke_showing_7450aa_idx'),
),
migrations.AddIndex(
model_name='ticket',
index=models.Index(fields=['showing', 'holder'], name='clubs_ticke_showing_86d999_idx'),
),
migrations.AddIndex(
model_name='ticket',
index=models.Index(condition=models.Q(('buyable', True), ('holder__isnull', True), ('owner__isnull', True)), fields=['showing', 'type'], name='ticket_available_idx'),
),
]
60 changes: 46 additions & 14 deletions backend/clubs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from django.core.mail import EmailMultiAlternatives
from django.core.validators import validate_email
from django.db import models, transaction
from django.db.models import Sum
from django.db.models import Q, Sum
Comment thread
julianweng marked this conversation as resolved.
from django.db.models.deletion import ProtectedError
from django.dispatch import receiver
from django.template.loader import render_to_string
Expand Down Expand Up @@ -306,7 +306,7 @@ class Club(models.Model):
approved_comment = models.TextField(null=True, blank=True)
approved_on = models.DateTimeField(null=True, blank=True, db_index=True)

archived = models.BooleanField(default=False)
archived = models.BooleanField(default=False, db_index=True)
archived_by = models.ForeignKey(
get_user_model(),
null=True,
Expand Down Expand Up @@ -781,6 +781,9 @@ class Meta:
),
("manage_club", "Manipulate club object and related objects"),
]
indexes = [
models.Index(fields=["approved", "archived"]),
]


class TargetStudentType(models.Model):
Expand Down Expand Up @@ -900,8 +903,8 @@ class ClubFair(models.Model):
information = models.TextField(blank=True)
registration_information = models.TextField(blank=True)

start_time = models.DateTimeField()
end_time = models.DateTimeField()
start_time = models.DateTimeField(db_index=True)
end_time = models.DateTimeField(db_index=True)

registration_start_time = models.DateTimeField(null=True, blank=True)
registration_end_time = models.DateTimeField()
Expand Down Expand Up @@ -954,6 +957,11 @@ def __str__(self):
f"({self.start_time.strftime(fmt)} - {self.end_time.strftime(fmt)})"
)

class Meta:
indexes = [
models.Index(fields=["end_time", "start_time"], name="fair_time_idx"),
]


class ClubFairRegistration(models.Model):
"""
Expand Down Expand Up @@ -993,7 +1001,7 @@ class Event(models.Model):
upload_to=get_event_small_file_name, null=True, blank=True
)
description = models.TextField(blank=True) # rich html
ics_uuid = models.UUIDField(default=uuid.uuid4)
ics_uuid = models.UUIDField(default=uuid.uuid4, db_index=True)
is_ics_event = models.BooleanField(default=False, blank=True)

OTHER = 0
Expand All @@ -1013,7 +1021,7 @@ class Event(models.Model):
(CAREER, "Career"),
)

type = models.IntegerField(choices=TYPES, default=RECRUITMENT)
type = models.IntegerField(choices=TYPES, default=RECRUITMENT, db_index=True)
pinned = models.BooleanField(default=False)

created_at = models.DateTimeField(auto_now_add=True)
Expand All @@ -1033,7 +1041,7 @@ class EventShowing(models.Model):

event = models.ForeignKey(Event, on_delete=models.CASCADE)
start_time = models.DateTimeField()
end_time = models.DateTimeField()
end_time = models.DateTimeField(db_index=True)
location = models.CharField(max_length=255, null=True, blank=True)
ticket_order_limit = models.IntegerField(default=10)
ticket_drop_time = models.DateTimeField(null=True, blank=True)
Expand All @@ -1044,6 +1052,12 @@ class EventShowing(models.Model):
def __str__(self):
return f"{self.event.name} showing at {self.start_time}"

class Meta:
indexes = [
models.Index(fields=["start_time", "end_time"]),
models.Index(fields=["event", "start_time"], name="event_start_idx"),
]


class Favorite(models.Model):
"""
Expand Down Expand Up @@ -1115,6 +1129,11 @@ class ClubVisit(models.Model):
def __str__(self):
return "<Visit: {} visited {}>".format(self.person.username, self.club.code)

class Meta:
indexes = [
models.Index(fields=["club", "visit_type", "created_at"]),
]


class ZoomMeetingVisit(models.Model):
"""
Expand Down Expand Up @@ -1395,7 +1414,7 @@ class Membership(models.Model):
person = models.ForeignKey(get_user_model(), on_delete=models.CASCADE)
club = models.ForeignKey(Club, on_delete=models.CASCADE)
title = models.CharField(max_length=255, default="Member")
role = models.IntegerField(choices=ROLE_CHOICES, default=ROLE_MEMBER)
role = models.IntegerField(choices=ROLE_CHOICES, default=ROLE_MEMBER, db_index=True)
description = models.TextField(max_length=1000, blank=True)
image = models.ImageField(
upload_to=get_membership_image_file_name, null=True, blank=True
Expand Down Expand Up @@ -1568,7 +1587,7 @@ class Badge(models.Model):
PURPOSE_CHOICES = [("fair", "Fair"), ("org", "Organization")]

label = models.CharField(max_length=255)
purpose = models.CharField(max_length=255, choices=PURPOSE_CHOICES)
purpose = models.CharField(max_length=255, choices=PURPOSE_CHOICES, db_index=True)
description = models.TextField(blank=True)

# The color of the badge to be displayed on the frontend.
Expand Down Expand Up @@ -1800,11 +1819,11 @@ class ClubApplication(CloneModel):

club = models.ForeignKey(Club, on_delete=models.CASCADE)
description = models.TextField(blank=True)
application_start_time = models.DateTimeField()
application_end_time = models.DateTimeField()
application_start_time = models.DateTimeField(db_index=True)
application_end_time = models.DateTimeField(db_index=True)
application_end_time_exception = models.BooleanField(default=False, blank=True)
name = models.TextField(blank=True)
result_release_time = models.DateTimeField()
result_release_time = models.DateTimeField(db_index=True)
application_cycle = models.ForeignKey(
ApplicationCycle, on_delete=models.SET_NULL, null=True
)
Expand Down Expand Up @@ -2035,7 +2054,7 @@ class ApplicationSubmission(models.Model):
(REJECTED_AFTER_INTERVIEW, "Rejected after interview(s)"),
(ACCEPTED, "Accepted"),
)
status = models.IntegerField(choices=STATUS_TYPES, default=PENDING)
status = models.IntegerField(choices=STATUS_TYPES, default=PENDING, db_index=True)
user = models.ForeignKey(get_user_model(), on_delete=models.CASCADE, null=False)
reason = models.TextField(blank=True)
application = models.ForeignKey(
Expand Down Expand Up @@ -2151,7 +2170,7 @@ class Ticket(models.Model):
null=True,
blank=True,
)
type = models.CharField(max_length=100)
type = models.CharField(max_length=100, db_index=True)
owner = models.ForeignKey(
get_user_model(),
related_name="owned_tickets",
Expand Down Expand Up @@ -2189,6 +2208,19 @@ class Ticket(models.Model):
)
objects = TicketManager()

class Meta:
indexes = [
models.Index(fields=["showing", "type"]),
models.Index(fields=["showing", "owner"]),
models.Index(fields=["showing", "holder"]),
# Speed up available ticket lookups for add-to-cart
models.Index(
fields=["showing", "type"],
name="ticket_available_idx",
condition=Q(owner__isnull=True, holder__isnull=True, buyable=True),
),
]

def delete(self, *args, **kwargs):
if self.transaction_record:
raise ProtectedError(
Expand Down
Loading