cache dataclass_fields lookup in merge_geo

This commit is contained in:
Andrew Pimenov 2026-08-09 16:10:29 +03:00
parent 329ff15e74
commit ab39922bf6

View file

@ -176,8 +176,9 @@ _MERGE_SKIP = {"sources", "ip_type"}
def merge_geo(candidates: list[tuple[str, IpGeo]]) -> IpGeo: def merge_geo(candidates: list[tuple[str, IpGeo]]) -> IpGeo:
merged = IpGeo() merged = IpGeo()
sources: dict[str, str] = {} sources: dict[str, str] = {}
fields = dataclass_fields(IpGeo)
for name, geo in candidates: for name, geo in candidates:
for f in dataclass_fields(IpGeo): for f in fields:
if f.name in _MERGE_SKIP: if f.name in _MERGE_SKIP:
continue continue
if getattr(merged, f.name) is not None: if getattr(merged, f.name) is not None: