diff --git a/stats-backend/api2/migrations/0039_nodestatushistory_api2_nodest_node_id_ff6427_idx_and_more.py b/stats-backend/api2/migrations/0039_nodestatushistory_api2_nodest_node_id_ff6427_idx_and_more.py new file mode 100644 index 0000000..7343874 --- /dev/null +++ b/stats-backend/api2/migrations/0039_nodestatushistory_api2_nodest_node_id_ff6427_idx_and_more.py @@ -0,0 +1,21 @@ +# Generated by Django 4.1.7 on 2024-12-23 12:44 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('api2', '0038_node_type'), + ] + + operations = [ + migrations.AddIndex( + model_name='nodestatushistory', + index=models.Index(fields=['node_id', 'is_online', 'timestamp'], name='api2_nodest_node_id_ff6427_idx'), + ), + migrations.AddIndex( + model_name='nodestatushistory', + index=models.Index(fields=['timestamp', 'is_online'], name='api2_nodest_timesta_f6216b_idx'), + ), + ] diff --git a/stats-backend/api2/models.py b/stats-backend/api2/models.py index 22f630c..e7af33e 100644 --- a/stats-backend/api2/models.py +++ b/stats-backend/api2/models.py @@ -8,11 +8,13 @@ class Node(models.Model): node_id = models.CharField(max_length=42, unique=True, db_index=True) - wallet = models.CharField(max_length=42, null=True, blank=True, db_index=True) + wallet = models.CharField(max_length=42, null=True, + blank=True, db_index=True) online = models.BooleanField(default=False, db_index=True) earnings_total = models.FloatField(null=True, blank=True) computing_now = models.BooleanField(default=False, db_index=True) - version = models.CharField(max_length=7, db_index=True, null=True, blank=True) + version = models.CharField( + max_length=7, db_index=True, null=True, blank=True) updated_at = models.DateTimeField(auto_now=True, db_index=True) created_at = models.DateTimeField(auto_now_add=True, db_index=True) uptime_created_at = models.DateTimeField(auto_now_add=True, db_index=True) @@ -94,10 +96,11 @@ def __str__(self): class Meta: indexes = [ models.Index(fields=["node_id", "timestamp"]), + models.Index(fields=["node_id", "is_online", "timestamp"]), + models.Index(fields=["timestamp", "is_online"]), ] - class ProviderWithTask(models.Model): instance = models.ForeignKey( Node, on_delete=models.CASCADE, related_name="tasks_received" @@ -109,7 +112,8 @@ class ProviderWithTask(models.Model): env_per_hour = models.FloatField( null=True, blank=True ) # Pricing per second for duration/env/h - start_price = models.FloatField(null=True, blank=True) # Static start price + start_price = models.FloatField( + null=True, blank=True) # Static start price created_at = models.DateTimeField(auto_now_add=True) network = models.CharField(max_length=42, default="mainnet")