perf: batch acceptance backfill for deployed source volume
Some checks failed
Mostovik Backend CI/CD / Tests and lint (push) Successful in 2m43s
Mostovik Backend CI/CD / Build linux/amd64 release images (push) Failing after 1m17s
Mostovik Backend CI/CD / Deploy dev (push) Has been skipped
Mostovik Backend CI/CD / Deploy and verify internal main (push) Has been skipped

This commit is contained in:
Aleksandr Meshchryakov
2026-10-12 09:52:06 +02:00
parent 9b3da5b505
commit 1ffdcd0aaf
3 changed files with 96 additions and 20 deletions

View File

@@ -385,3 +385,48 @@ def test_amount_ordering_remains_decimal_null_last(
response = client.get(LIST_URL, {"source_group": group, "ordering": ordering})
assert response.status_code == 200, response.data
assert [int(item["external_id"]) for item in response.data["data"]] == expected
def test_backfill_batches_repeated_organizations_without_per_record_queries(client):
from django.db import connection
from django.test.utils import CaptureQueriesContext
first = record(
"government_procurements",
"procurements_44fz",
1,
payload={"is_branch": False},
is_branch=False,
)
OrganizationSourceRecord.objects.bulk_create(
[
OrganizationSourceRecord(
extension=first.extension,
source=first.source,
record_type=first.record_type,
external_id=str(index),
title="Existing",
payload={"is_branch": True},
)
for index in range(2, 1002)
]
)
before = list(
OrganizationSourceRecord.objects.order_by("uid").values_list(
"uid", "updated_at"
)
)
with CaptureQueriesContext(connection) as queries:
output = StringIO()
call_command("normalize_testing_amendments", apply=True, stdout=output)
assert len(queries) < 30
assert json.loads(output.getvalue())["scanned"] == 1001
assert not OrganizationSourceRecord.objects.filter(payload__is_branch=True).exists()
assert (
list(
OrganizationSourceRecord.objects.order_by("uid").values_list(
"uid", "updated_at"
)
)
== before
)