mirror of
https://github.com/Horizontal42/netsleuth.git
synced 2026-11-10 23:52:04 +03:00
perf: add lru_cache to hot path ASN parsing functions
This commit is contained in:
parent
f9f9b37b18
commit
e4778f6298
2 changed files with 5 additions and 0 deletions
|
|
@ -2,6 +2,7 @@ from __future__ import annotations
|
|||
|
||||
import ipaddress
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from functools import lru_cache
|
||||
|
||||
import httpx
|
||||
|
||||
|
|
@ -15,6 +16,7 @@ BULK_CALLS = {"bgp-updates", "routing-history", "bgplay", "announced-prefixes"}
|
|||
_UNSTABLE_WITHDRAWALS_PER_DAY = 3.0
|
||||
|
||||
|
||||
@lru_cache(maxsize=256)
|
||||
def _as_label(asn: object) -> str:
|
||||
text = str(asn).upper()
|
||||
return text if text.startswith("AS") else f"AS{text}"
|
||||
|
|
|
|||
|
|
@ -2,12 +2,14 @@ from __future__ import annotations
|
|||
|
||||
import ipaddress
|
||||
import re
|
||||
from functools import lru_cache
|
||||
|
||||
from netsleuth.models import CfTrace, IpGeo
|
||||
|
||||
_AS_PREFIX_RE = re.compile(r"^AS(\d+)\s*(?P<name>.*)$", re.IGNORECASE)
|
||||
|
||||
|
||||
@lru_cache(maxsize=256)
|
||||
def _as_number(value: object) -> str | None:
|
||||
if value is None or value == "":
|
||||
return None
|
||||
|
|
@ -20,6 +22,7 @@ def _as_number(value: object) -> str | None:
|
|||
return None
|
||||
|
||||
|
||||
@lru_cache(maxsize=256)
|
||||
def _as_label(value: object) -> str | None:
|
||||
match = _AS_PREFIX_RE.match(str(value or ""))
|
||||
name = (match.group("name") if match else "").strip()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue