Skip to content
Open
Changes from 2 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
57 changes: 41 additions & 16 deletions backend/clubs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ class Club(models.Model):
(APPLICATION_AND_INTERVIEW, "Application and Interview Required"),
)

approved = models.BooleanField(null=True, default=None)
approved = models.BooleanField(null=True, default=None, db_index=True)
approved_by = models.ForeignKey(
get_user_model(),
null=True,
Expand All @@ -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 @@ -993,7 +996,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 +1016,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 @@ -1032,8 +1035,8 @@ class EventShowing(models.Model):
"""

event = models.ForeignKey(Event, on_delete=models.CASCADE)
start_time = models.DateTimeField()
end_time = models.DateTimeField()
start_time = models.DateTimeField(db_index=True)
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 +1047,11 @@ 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"]),
]


class Favorite(models.Model):
"""
Expand Down Expand Up @@ -1107,14 +1115,21 @@ class ClubVisit(models.Model):
(MANAGE_PAGE, "Manage Page Visit"),
(FAIR_PAGE, "Fair Page Visit"),
)
visit_type = models.IntegerField(choices=VISIT_TYPES, default=CLUB_PAGE)
visit_type = models.IntegerField(
choices=VISIT_TYPES, default=CLUB_PAGE, db_index=True
)

created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)

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 +1410,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 All @@ -1411,6 +1426,9 @@ def __str__(self):

class Meta:
unique_together = (("club", "person"),)
indexes = [
models.Index(fields=["person", "club", "role"]),
]


def get_token():
Expand Down Expand Up @@ -1568,7 +1586,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 +1818,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 +2053,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 +2169,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 +2207,13 @@ class Ticket(models.Model):
)
objects = TicketManager()

class Meta:
indexes = [
models.Index(fields=["showing", "type"]),
models.Index(fields=["showing", "owner"]),
models.Index(fields=["showing", "holder"]),
]
Comment thread
julianweng marked this conversation as resolved.

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