perf(organizations): speed up filtered API lists
All checks were successful
CI/CD Pipeline / Quality Gate (push) Successful in 28s
CI/CD Pipeline / Build and Push Images (push) Successful in 10s
CI/CD Pipeline / Internal Notify (push) Successful in 0s
CI/CD Pipeline / Deploy Dev in Dokploy (push) Successful in 1s

This commit is contained in:
2026-05-14 17:08:03 +02:00
parent df89e498cc
commit 19a7d5a91c
10 changed files with 360 additions and 62 deletions

View File

@@ -21,6 +21,7 @@ from apps.parsers.models import (
from django.db.models import Count, Prefetch, Q
from registers.models import RegistryMembershipPeriod
from organizations.data_sources import to_api_data_source, to_internal_data_source
from organizations.models import Organization
GENERIC_SOURCES = (
@@ -45,12 +46,7 @@ DATA_PRESENCE_KEYS = (
ParserLoadLog.Source.FNS_REPORTS,
)
DATA_PRESENCE_KEY_SET = {str(source) for source in DATA_PRESENCE_KEYS}
API_DATA_SOURCE_ALIASES = {
ParserLoadLog.Source.TRUDVSEM: "vacancies",
}
API_DATA_SOURCE_KEY_SET = {
API_DATA_SOURCE_ALIASES.get(source, str(source)) for source in DATA_PRESENCE_KEYS
}
API_DATA_SOURCE_KEY_SET = {to_api_data_source(source) for source in DATA_PRESENCE_KEYS}
@dataclass(frozen=True)
@@ -98,19 +94,6 @@ def data_presence_identity_values(source: str) -> tuple[set[str], set[str]]:
return matches["inn"], matches["ogrn"]
def to_api_data_source(source: str) -> str:
"""Return v2 public data source key for an internal parser source."""
return API_DATA_SOURCE_ALIASES.get(source, str(source))
def to_internal_data_source(source: str) -> str:
"""Return internal parser source key from a v2 public key."""
for internal_source, api_source in API_DATA_SOURCE_ALIASES.items():
if source == api_source:
return str(internal_source)
return source
def _source_matches(source: str) -> dict[str, set[str]]:
if source == ParserLoadLog.Source.INDUSTRIAL:
return OrganizationApiEnrichmentService._matching_identifiers_for_all(