From a09ec5234a232b4285f8ac33c7adbbb9520e3445 Mon Sep 17 00:00:00 2001 From: Egor Matveev Date: Thu, 20 Jan 2022 00:48:23 +0300 Subject: [PATCH] indexes --- Main/migrations/0012_auto_20220120_0047.py | 49 ++++++++++++++++++++++ Main/models/extrafile.py | 5 +++ Main/models/friendship.py | 6 +++ Main/models/message.py | 5 +++ Main/models/progress.py | 5 +++ Main/models/settask.py | 5 +++ Main/models/solution.py | 6 +++ Main/models/solution_file.py | 5 +++ Main/views/SetView.py | 7 ++++ Main/views/__init__.py | 1 + 10 files changed, 94 insertions(+) create mode 100644 Main/migrations/0012_auto_20220120_0047.py create mode 100644 Main/views/SetView.py diff --git a/Main/migrations/0012_auto_20220120_0047.py b/Main/migrations/0012_auto_20220120_0047.py new file mode 100644 index 0000000..f10a09f --- /dev/null +++ b/Main/migrations/0012_auto_20220120_0047.py @@ -0,0 +1,49 @@ +# Generated by Django 3.2.4 on 2022-01-19 21:47 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('Main', '0011_remove_userinfo_token'), + ] + + operations = [ + migrations.AddIndex( + model_name='extrafile', + index=models.Index(fields=['task'], name='Main_extraf_task_id_423651_idx'), + ), + migrations.AddIndex( + model_name='friendship', + index=models.Index(fields=['from_user'], name='Main_friend_from_us_0923c9_idx'), + ), + migrations.AddIndex( + model_name='friendship', + index=models.Index(fields=['to_user'], name='Main_friend_to_user_389a97_idx'), + ), + migrations.AddIndex( + model_name='message', + index=models.Index(fields=['chat', '-time_sent'], name='Main_messag_chat_id_494037_idx'), + ), + migrations.AddIndex( + model_name='progress', + index=models.Index(fields=['user', 'task'], name='Main_progre_user_id_3ed604_idx'), + ), + migrations.AddIndex( + model_name='settask', + index=models.Index(fields=['set'], name='Main_settas_set_id_046a3e_idx'), + ), + migrations.AddIndex( + model_name='solution', + index=models.Index(fields=['task', 'user', '-time_sent'], name='Main_soluti_task_id_0d9c15_idx'), + ), + migrations.AddIndex( + model_name='solution', + index=models.Index(fields=['task', '-time_sent'], name='Main_soluti_task_id_878836_idx'), + ), + migrations.AddIndex( + model_name='solutionfile', + index=models.Index(fields=['solution'], name='Main_soluti_solutio_cebd76_idx'), + ), + ] diff --git a/Main/models/extrafile.py b/Main/models/extrafile.py index 6b11ca7..f25d77d 100644 --- a/Main/models/extrafile.py +++ b/Main/models/extrafile.py @@ -13,6 +13,11 @@ class ExtraFile(FileStorageMixin, models.Model): test_number = models.IntegerField(null=True) fs_id = models.IntegerField(null=True) + class Meta: + indexes = [ + models.Index(fields=['task']) + ] + @property def can_be_sample(self): return ( diff --git a/Main/models/friendship.py b/Main/models/friendship.py index 7c60c78..34ee665 100644 --- a/Main/models/friendship.py +++ b/Main/models/friendship.py @@ -6,3 +6,9 @@ class Friendship(models.Model): from_user = models.ForeignKey(User, on_delete=models.CASCADE, related_name="from_friendship") to_user = models.ForeignKey(User, on_delete=models.CASCADE, related_name="to_friendship") verified = models.BooleanField(default=False) + + class Meta: + indexes = [ + models.Index(fields=['from_user']), + models.Index(fields=['to_user']) + ] diff --git a/Main/models/message.py b/Main/models/message.py index c77f3cf..73a7a77 100644 --- a/Main/models/message.py +++ b/Main/models/message.py @@ -11,3 +11,8 @@ class Message(models.Model): text = models.TextField() read = models.BooleanField(default=False) time_sent = models.DateTimeField(default=timezone.now) + + class Meta: + indexes = [ + models.Index(fields=['chat', '-time_sent']) + ] diff --git a/Main/models/progress.py b/Main/models/progress.py index 56f9d4a..8407658 100644 --- a/Main/models/progress.py +++ b/Main/models/progress.py @@ -15,6 +15,11 @@ class Progress(models.Model): score = models.IntegerField(default=0) finished = models.BooleanField(default=False) + class Meta: + indexes = [ + models.Index(fields=['user', 'task']) + ] + @property def time(self): if not self.finished: diff --git a/Main/models/settask.py b/Main/models/settask.py index 9226691..bd90946 100644 --- a/Main/models/settask.py +++ b/Main/models/settask.py @@ -8,3 +8,8 @@ class SetTask(models.Model): set = models.ForeignKey(Set, on_delete=models.CASCADE, related_name="settasks") task = models.ForeignKey(Task, on_delete=models.CASCADE, related_name="settasks") name = models.CharField(max_length=2) + + class Meta: + indexes = [ + models.Index(fields=['set']) + ] diff --git a/Main/models/solution.py b/Main/models/solution.py index 7a96fe0..f1d379b 100644 --- a/Main/models/solution.py +++ b/Main/models/solution.py @@ -21,6 +21,12 @@ class Solution(models.Model): result = models.TextField(default=CONSTS["in_queue_status"]) test = models.IntegerField(default=None, null=True) + class Meta: + indexes = [ + models.Index(fields=['task', 'user', '-time_sent']), + models.Index(fields=['task', '-time_sent']) + ] + @property def language(self): return languages[self.language_id] diff --git a/Main/models/solution_file.py b/Main/models/solution_file.py index d1961ea..8a718b1 100644 --- a/Main/models/solution_file.py +++ b/Main/models/solution_file.py @@ -7,3 +7,8 @@ class SolutionFile(FileStorageMixin, models.Model): path = models.TextField() fs_id = models.IntegerField() solution = models.ForeignKey("Solution", on_delete=models.CASCADE) + + class Meta: + indexes = [ + models.Index(fields=['solution']) + ] diff --git a/Main/views/SetView.py b/Main/views/SetView.py new file mode 100644 index 0000000..1dd0be6 --- /dev/null +++ b/Main/views/SetView.py @@ -0,0 +1,7 @@ +from SprintLib.BaseView import BaseView + + +class SetView(BaseView): + required_login = True + endpoint = 'set' + view_file = 'set.html' diff --git a/Main/views/__init__.py b/Main/views/__init__.py index 84afa55..62656aa 100644 --- a/Main/views/__init__.py +++ b/Main/views/__init__.py @@ -18,3 +18,4 @@ from Main.views.SolutionsView import SolutionsView from Main.views.ChatView import ChatView from Main.views.ChatWithView import ChatWithView from Main.views.MessagesView import MessagesView +from Main.views.SetView import SetView