Skip to content

Commit

Permalink
Add index on nodestatushistory
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptobench committed Mar 28, 2024
1 parent 4f9248f commit 8f81c62
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -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'),
),
]
14 changes: 9 additions & 5 deletions stats-backend/api2/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand All @@ -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)

0 comments on commit 8f81c62

Please sign in to comment.