perf(organizations): speed up filtered API lists
This commit is contained in:
@@ -23,6 +23,7 @@ from django.utils import timezone
|
||||
from registers.models import Organization as RegisterOrganization
|
||||
|
||||
from organizations.api_enrichment import OrganizationApiEnrichmentService
|
||||
from organizations.data_sources import data_source_summary
|
||||
from organizations.models import Organization, OrganizationDataSnapshot
|
||||
|
||||
_QUOTE_CHARS = "\"'«»„“”"
|
||||
@@ -132,6 +133,7 @@ class OrganizationDataSnapshotRefreshService:
|
||||
processed += 1
|
||||
item = enrichment[str(organization.uid)]
|
||||
data = item.data_presence
|
||||
data_source_counts = data_source_summary(data)
|
||||
registries = [
|
||||
{
|
||||
"id": registry.id,
|
||||
@@ -146,12 +148,14 @@ class OrganizationDataSnapshotRefreshService:
|
||||
OrganizationDataSnapshot(
|
||||
organization=organization,
|
||||
data=data,
|
||||
data_source_counts=data_source_counts,
|
||||
registries=registries,
|
||||
)
|
||||
)
|
||||
continue
|
||||
|
||||
snapshot.data = data
|
||||
snapshot.data_source_counts = data_source_counts
|
||||
snapshot.registries = registries
|
||||
snapshot.updated_at = timezone.now()
|
||||
update_instances.append(snapshot)
|
||||
@@ -165,7 +169,7 @@ class OrganizationDataSnapshotRefreshService:
|
||||
if update_instances:
|
||||
OrganizationDataSnapshot.objects.bulk_update(
|
||||
update_instances,
|
||||
fields=["data", "registries", "updated_at"],
|
||||
fields=["data", "data_source_counts", "registries", "updated_at"],
|
||||
batch_size=batch_size,
|
||||
)
|
||||
updated += len(update_instances)
|
||||
|
||||
Reference in New Issue
Block a user