diff --git a/compute_horde/compute_horde/receipts/migrations/0003_remove_jobstartedreceipt_time_accepted_and_more.py b/compute_horde/compute_horde/receipts/migrations/0003_jobacceptedreceipt_and_more.py similarity index 71% rename from compute_horde/compute_horde/receipts/migrations/0003_remove_jobstartedreceipt_time_accepted_and_more.py rename to compute_horde/compute_horde/receipts/migrations/0003_jobacceptedreceipt_and_more.py index 903d6ebbf..1ec5d3df6 100644 --- a/compute_horde/compute_horde/receipts/migrations/0003_remove_jobstartedreceipt_time_accepted_and_more.py +++ b/compute_horde/compute_horde/receipts/migrations/0003_jobacceptedreceipt_and_more.py @@ -1,4 +1,4 @@ -# Generated by Django 5.1.1 on 2024-10-23 14:11 +# Generated by Django 5.1.1 on 2024-10-28 12:53 import datetime @@ -11,6 +11,28 @@ class Migration(migrations.Migration): ] operations = [ + migrations.CreateModel( + name="JobAcceptedReceipt", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, primary_key=True, serialize=False, verbose_name="ID" + ), + ), + ("job_uuid", models.UUIDField()), + ("validator_hotkey", models.CharField(max_length=256)), + ("miner_hotkey", models.CharField(max_length=256)), + ("validator_signature", models.CharField(max_length=256)), + ("miner_signature", models.CharField(blank=True, max_length=256, null=True)), + ("timestamp", models.DateTimeField()), + ("time_accepted", models.DateTimeField()), + ("ttl", models.IntegerField()), + ], + options={ + "abstract": False, + }, + ), migrations.RemoveField( model_name="jobstartedreceipt", name="time_accepted", @@ -37,31 +59,22 @@ class Migration(migrations.Migration): field=models.IntegerField(default=0), preserve_default=False, ), - migrations.CreateModel( - name="JobAcceptedReceipt", - fields=[ - ( - "id", - models.BigAutoField( - auto_created=True, primary_key=True, serialize=False, verbose_name="ID" - ), - ), - ("job_uuid", models.UUIDField()), - ("validator_hotkey", models.CharField(max_length=256)), - ("miner_hotkey", models.CharField(max_length=256)), - ("validator_signature", models.CharField(max_length=256)), - ("miner_signature", models.CharField(blank=True, max_length=256, null=True)), - ("timestamp", models.DateTimeField()), - ("time_accepted", models.DateTimeField()), - ("ttl", models.IntegerField()), - ], - options={ - "abstract": False, - "constraints": [ - models.UniqueConstraint( - fields=("job_uuid",), name="receipts_unique_jobacceptedreceipt_job_uuid" - ) - ], - }, + migrations.AddIndex( + model_name="jobfinishedreceipt", + index=models.Index(fields=["timestamp"], name="jobfinishedreceipt_ts_idx"), + ), + migrations.AddIndex( + model_name="jobstartedreceipt", + index=models.Index(fields=["timestamp"], name="jobstartedreceipt_ts_idx"), + ), + migrations.AddIndex( + model_name="jobacceptedreceipt", + index=models.Index(fields=["timestamp"], name="jobacceptedreceipt_ts_idx"), + ), + migrations.AddConstraint( + model_name="jobacceptedreceipt", + constraint=models.UniqueConstraint( + fields=("job_uuid",), name="receipts_unique_jobacceptedreceipt_job_uuid" + ), ), ] diff --git a/compute_horde/compute_horde/receipts/models.py b/compute_horde/compute_horde/receipts/models.py index 56a3a27e5..04c45f662 100644 --- a/compute_horde/compute_horde/receipts/models.py +++ b/compute_horde/compute_horde/receipts/models.py @@ -28,6 +28,9 @@ class Meta: constraints = [ models.UniqueConstraint(fields=["job_uuid"], name="receipts_unique_%(class)s_job_uuid"), ] + indexes = [ + models.Index(fields=["timestamp"], name="%(class)s_ts_idx"), + ] def __str__(self): return f"job_uuid: {self.job_uuid}"