perf(organizations): speed up filtered API lists
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user