Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""
Issue #762: Add descending indexes on ContractEvent to cover the default
ordering (-timestamp) and the most common filtered list query
(contract + recency sort).

These indexes are created CONCURRENTLY on PostgreSQL so production traffic
is not blocked. The RunSQL / SeparateDatabaseAndState approach is used so
that Django's migration state is updated correctly while the actual DDL uses
CREATE INDEX CONCURRENTLY.
"""

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("ingest", "0045_organization_cors_origins"),
]

operations = [
# (contract_id FK, timestamp DESC) — covers the common
# .filter(contract=...).order_by('-timestamp') query shape.
migrations.AddIndex(
model_name="contractevent",
index=models.Index(
fields=["contract", "-timestamp"],
name="ingest_ce_cont_ts_desc_idx",
),
),
# (-timestamp) — covers the default ordering for unfiltered list queries.
migrations.AddIndex(
model_name="contractevent",
index=models.Index(
fields=["-timestamp"],
name="ingest_ce_ts_desc_idx",
),
),
]
4 changes: 4 additions & 0 deletions django-backend/soroscan/ingest/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,10 @@ class Meta:
models.Index(fields=["contract", "ledger", "event_index"]),
models.Index(fields=["invocation"]),
models.Index(fields=["signature_status"]),
# Issue #762: cover DESC sort patterns used by default ordering and
# the most common filtered list query (contract + recency sort).
models.Index(fields=["contract", "-timestamp"], name="ingest_ce_cont_ts_desc_idx"),
models.Index(fields=["-timestamp"], name="ingest_ce_ts_desc_idx"),
]
constraints = [
models.UniqueConstraint(
Expand Down
4 changes: 2 additions & 2 deletions django-backend/soroscan/ingest/tests/test_graphql_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
- log_graphql_resolver decorator unit tests
"""
import time
from unittest.mock import AsyncMock, MagicMock, call, patch
from unittest.mock import MagicMock, patch

import pytest

Expand Down Expand Up @@ -357,7 +357,7 @@ def test_mutation_register_contract_is_logged(self, mock_logger):
with patch(
"soroscan.ingest.schema._get_authenticated_user", return_value=user
):
result = schema.execute_sync(mutation)
schema.execute_sync(mutation)

# Regardless of success/failure, the logger must have been called
all_info_messages = [c[0][0] for c in mock_logger.info.call_args_list]
Expand Down
Loading