Skip to content

Commit

Permalink
DB indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptobench committed Dec 23, 2024
1 parent 200d681 commit acda293
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -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'),
),
]
12 changes: 8 additions & 4 deletions stats-backend/api2/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"
Expand All @@ -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")

Expand Down

0 comments on commit acda293

Please sign in to comment.