feat: implement 60-second analysis cache TTL for high-frequency airport cities

This commit is contained in:
2569718930@qq.com
2026-05-17 13:41:44 +08:00
parent 07bb8e1d15
commit a83d9e7649
2 changed files with 36 additions and 0 deletions
+12
View File
@@ -0,0 +1,12 @@
from web.analysis_service import _analysis_ttl_for_city
from web.core import CACHE_TTL
def test_high_frequency_airport_cities_use_one_minute_analysis_cache():
assert _analysis_ttl_for_city("chongqing") == 60
assert _analysis_ttl_for_city("shanghai") == 60
assert _analysis_ttl_for_city("singapore") == 60
def test_non_high_frequency_city_keeps_default_analysis_cache_ttl():
assert _analysis_ttl_for_city("new york") == CACHE_TTL
+24
View File
@@ -45,6 +45,28 @@ from web.services.city_payloads import (
)
TURKISH_MGM_CITIES = {"ankara", "istanbul"}
HIGH_FREQ_AIRPORT_ANALYSIS_CITIES = {
"seoul",
"singapore",
"busan",
"tokyo",
"ankara",
"helsinki",
"amsterdam",
"istanbul",
"paris",
"hong kong",
"lau fau shan",
"taipei",
"beijing",
"shanghai",
"guangzhou",
"shenzhen",
"qingdao",
"chengdu",
"chongqing",
"wuhan",
}
_ANALYSIS_CACHE_STATS_LOCK = threading.Lock()
_ANALYSIS_CACHE_STATS: Dict[str, Any] = {
"total_requests": 0,
@@ -374,6 +396,8 @@ def _analysis_ttl_for_city(city: str) -> int:
return CACHE_TTL_ANKARA
if city_lower in KOREAN_AMOS_CITIES:
return CACHE_TTL_KOREAN_AMOS
if city_lower in HIGH_FREQ_AIRPORT_ANALYSIS_CITIES:
return 60
return CACHE_TTL