Repository: Cloud-CV/EvalAI

Issue:
Add indexing in database.



Discussion:
Hello,

Is anyone already working on this? I will like to look into it.

Resolving patch:
diff --git a/apps/challenges/migrations/0031_add_db_index_to_challenge_related_models.py b/apps/challenges/migrations/0031_add_db_index_to_challenge_related_models.py
new file mode 100644
--- /dev/null
+++ b/apps/challenges/migrations/0031_add_db_index_to_challenge_related_models.py
@@ -0,0 +1,80 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.10.2 on 2017-09-15 02:24
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('challenges', '0030_add_boolean_field_in_star_model'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='challenge',
+            name='approved_by_admin',
+            field=models.BooleanField(db_index=True, default=False, verbose_name='Approved By Admin'),
+        ),
+        migrations.AlterField(
+            model_name='challenge',
+            name='end_date',
+            field=models.DateTimeField(blank=True, db_index=True, null=True, verbose_name='End Date (UTC)'),
+        ),
+        migrations.AlterField(
+            model_name='challenge',
+            name='is_disabled',
+            field=models.BooleanField(db_index=True, default=False),
+        ),
+        migrations.AlterField(
+            model_name='challenge',
+            name='published',
+            field=models.BooleanField(db_index=True, default=False, verbose_name='Publicly Available'),
+        ),
+        migrations.AlterField(
+            model_name='challenge',
+            name='start_date',
+            field=models.DateTimeField(blank=True, db_index=True, null=True, verbose_name='Start Date (UTC)'),
+        ),
+        migrations.AlterField(
+            model_name='challenge',
+            name='title',
+            field=models.CharField(db_index=True, max_length=100),
+        ),
+        migrations.AlterField(
+            model_name='challengeconfiguration',
+            name='is_created',
+            field=models.BooleanField(db_index=True, default=False),
+        ),
+        migrations.AlterField(
+            model_name='challengephase',
+            name='end_date',
+            field=models.DateTimeField(blank=True, db_index=True, null=True, verbose_name='End Date (UTC)'),
+        ),
+        migrations.AlterField(
+            model_name='challengephase',
+            name='max_submissions',
+            field=models.PositiveIntegerField(db_index=True, default=100000),
+        ),
+        migrations.AlterField(
+            model_name='challengephase',
+            name='max_submissions_per_day',
+            field=models.PositiveIntegerField(db_index=True, default=100000),
+        ),
+        migrations.AlterField(
+            model_name='challengephase',
+            name='name',
+            field=models.CharField(db_index=True, max_length=100),
+        ),
+        migrations.AlterField(
+            model_name='challengephase',
+            name='start_date',
+            field=models.DateTimeField(blank=True, db_index=True, null=True, verbose_name='Start Date (UTC)'),
+        ),
+        migrations.AlterField(
+            model_name='starchallenge',
+            name='is_starred',
+            field=models.BooleanField(db_index=True, default=False),
+        ),
+    ]
diff --git a/apps/challenges/models.py b/apps/challenges/models.py
--- a/apps/challenges/models.py
+++ b/apps/challenges/models.py
@@ -19,7 +19,7 @@ def __init__(self, *args, **kwargs):
         super(Challenge, self).__init__(*args, **kwargs)
         self._original_evaluation_script = self.evaluation_script
 
-    title = models.CharField(max_length=100)
+    title = models.CharField(max_length=100, db_index=True)
     short_description = models.TextField(null=True, blank=True)
     description = models.TextField(null=True, blank=True)
     terms_and_conditions = models.TextField(null=True, blank=True)
@@ -28,21 +28,21 @@ def __init__(self, *args, **kwargs):
     image = models.ImageField(
         upload_to='logos', null=True, blank=True, verbose_name="Logo")
     start_date = models.DateTimeField(
-        null=True, blank=True, verbose_name="Start Date (UTC)")
+        null=True, blank=True, verbose_name="Start Date (UTC)", db_index=True)
     end_date = models.DateTimeField(
-        null=True, blank=True, verbose_name="End Date (UTC)")
+        null=True, blank=True, verbose_name="End Date (UTC)", db_index=True)
     creator = models.ForeignKey(
         'hosts.ChallengeHostTeam', related_name='challenge_creator')
     published = models.BooleanField(
-        default=False, verbose_name="Publicly Available")
+        default=False, verbose_name="Publicly Available", db_index=True)
     enable_forum = models.BooleanField(default=True)
     anonymous_leaderboard = models.BooleanField(default=False)
     participant_teams = models.ManyToManyField(ParticipantTeam, blank=True)
-    is_disabled = models.BooleanField(default=False)
+    is_disabled = models.BooleanField(default=False, db_index=True)
     evaluation_script = models.FileField(
         default=False, upload_to=RandomFileName("evaluation_scripts"))  # should be zip format
     approved_by_admin = models.BooleanField(
-        default=False, verbose_name="Approved By Admin")
+        default=False, verbose_name="Approved By Admin", db_index=True)
 
     class Meta:
         app_label = 'challenges'
@@ -103,19 +103,19 @@ def __init__(self, *args, **kwargs):
         super(ChallengePhase, self).__init__(*args, **kwargs)
         self._original_test_annotation = self.test_annotation
 
-    name = models.CharField(max_length=100)
+    name = models.CharField(max_length=100, db_index=True)
     description = models.TextField()
     leaderboard_public = models.BooleanField(default=False)
     start_date = models.DateTimeField(
-        null=True, blank=True, verbose_name="Start Date (UTC)")
+        null=True, blank=True, verbose_name="Start Date (UTC)", db_index=True)
     end_date = models.DateTimeField(
-        null=True, blank=True, verbose_name="End Date (UTC)")
+        null=True, blank=True, verbose_name="End Date (UTC)", db_index=True)
     challenge = models.ForeignKey('Challenge')
     is_public = models.BooleanField(default=False)
     is_submission_public = models.BooleanField(default=False)
     test_annotation = models.FileField(upload_to=RandomFileName("test_annotations"), default=False)
-    max_submissions_per_day = models.PositiveIntegerField(default=100000)
-    max_submissions = models.PositiveIntegerField(default=100000)
+    max_submissions_per_day = models.PositiveIntegerField(default=100000, db_index=True)
+    max_submissions = models.PositiveIntegerField(default=100000, db_index=True)
     codename = models.CharField(max_length=100, default="Phase Code Name")
     dataset_split = models.ManyToManyField(DatasetSplit, blank=True, through='ChallengePhaseSplit')
 
@@ -211,7 +211,7 @@ class ChallengeConfiguration(TimeStampedModel):
     user = models.ForeignKey(User)
     challenge = models.OneToOneField(Challenge, null=True, blank=True)
     zip_configuration = models.FileField(upload_to=RandomFileName('zip_configuration_files/challenge_zip'))
-    is_created = models.BooleanField(default=False)
+    is_created = models.BooleanField(default=False, db_index=True)
     stdout_file = models.FileField(upload_to=RandomFileName('zip_configuration_files/challenge_zip'),
                                    null=True, blank=True)
     stderr_file = models.FileField(upload_to=RandomFileName('zip_configuration_files/challenge_zip'),
@@ -228,7 +228,7 @@ class StarChallenge(TimeStampedModel):
     """
     user = models.ForeignKey(User)
     challenge = models.ForeignKey(Challenge)
-    is_starred = models.BooleanField(default=False)
+    is_starred = models.BooleanField(default=False, db_index=True)
 
     class Meta:
         app_label = 'challenges'


Test patch: