diff --git a/stats-backend/api2/migrations/0026_alter_nodestatushistory_is_online_and_more.py b/stats-backend/api2/migrations/0026_alter_nodestatushistory_is_online_and_more.py new file mode 100644 index 0000000..b909846 --- /dev/null +++ b/stats-backend/api2/migrations/0026_alter_nodestatushistory_is_online_and_more.py @@ -0,0 +1,27 @@ +# Generated by Django 4.1.7 on 2024-03-28 14:49 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('api2', '0025_alter_golemtransactions_receiver_and_more'), + ] + + operations = [ + migrations.AlterField( + model_name='nodestatushistory', + name='is_online', + field=models.BooleanField(db_index=True), + ), + migrations.AlterField( + model_name='nodestatushistory', + name='timestamp', + field=models.DateTimeField(auto_now_add=True, db_index=True), + ), + migrations.AddIndex( + model_name='nodestatushistory', + index=models.Index(fields=['provider', 'timestamp'], name='api2_nodest_provide_64b3a2_idx'), + ), + ] diff --git a/stats-backend/api2/models.py b/stats-backend/api2/models.py index 85a594a..2201f9b 100644 --- a/stats-backend/api2/models.py +++ b/stats-backend/api2/models.py @@ -76,13 +76,19 @@ class GLM(models.Model): class NodeStatusHistory(models.Model): - provider = models.ForeignKey(Node, on_delete=models.CASCADE) - is_online = models.BooleanField() - timestamp = models.DateTimeField(auto_now_add=True) + provider = models.ForeignKey(Node, on_delete=models.CASCADE, db_index=True) + is_online = models.BooleanField(db_index=True) + timestamp = models.DateTimeField(auto_now_add=True, db_index=True) def __str__(self): return f"{self.provider.node_id} - {'Online' if self.is_online else 'Offline'} at {self.timestamp}" + class Meta: + indexes = [ + models.Index(fields=["provider", "timestamp"]), + # This compound index might be useful for queries that filter by provider and sort by timestamp + ] + class ProviderWithTask(models.Model): instance = models.ForeignKey( @@ -116,7 +122,6 @@ class RelayNodes(models.Model): node_id = models.CharField(max_length=42, unique=True) - class GolemTransactions(models.Model): scanner_id = models.IntegerField(primary_key=True) txhash = models.CharField(max_length=66, db_index=True) @@ -142,4 +147,3 @@ class Meta: class TransactionScraperIndex(models.Model): indexed_before = models.BooleanField(default=False) latest_timestamp_indexed = models.DateTimeField(null=True, blank=True) -