This commit is contained in:
2026-10-21 15:07:19 +08:00
parent 89a1da304f
commit 4b1df8c13b
77 changed files with 83 additions and 3421 deletions
+3 -27
View File
@@ -9,7 +9,6 @@ import redis
from api.core.Gzip import gzip_zip
from api.utils.skill_detail import SKILL_DETAIL_NORMALIZE_VERSION, normalize_skill_detail
from api.utils.openapi_data import (
OPENAPI_CUSTOM_CN_PATH,
OPENAPI_DATA_DIR,
OPENAPI_SKILLS_PATH,
logical_skill_detail_prefix,
@@ -37,11 +36,6 @@ def _load_skills():
return json.load(file)
def _load_custom_cn():
with OPENAPI_CUSTOM_CN_PATH.open(encoding='utf-8') as file:
return json.load(file)
def _iter_open_alters() -> list[str]:
alters: list[str] = []
for parent in adv:
@@ -104,22 +98,7 @@ def _skill_data_value(skill_data: dict, index: int) -> list:
return [0 if item is None or item == '-' else item for item in data]
def _custom_value(custom_cn: list[dict], prefix: str):
parts = prefix.split('/')
job = parts[0]
job_grow = parts[1]
skill_id = parts[-1]
return next(
(
item.get('custom', 1.0)
for item in custom_cn
if item.get('job') == job and item.get('jobGrow') == job_grow and item.get('skillId') == skill_id
),
1.0,
)
def _build_skill_data_preheat_tasks(custom_cn: list[dict]) -> list[PreheatTask]:
def _build_skill_data_preheat_tasks() -> list[PreheatTask]:
tasks: list[PreheatTask] = []
for path in _iter_skill_detail_files():
prefix = _skill_prefix_from_path(path)
@@ -131,7 +110,6 @@ def _build_skill_data_preheat_tasks(custom_cn: list[dict]) -> list[PreheatTask]:
lambda skill_data=skill_data: normalize_skill_detail(skill_data),
)
)
tasks.append((f'dcalc:skill:{prefix}:custom', lambda prefix=prefix: _custom_value(custom_cn, prefix)))
if skill_data.get('evolution'):
tasks.append(
@@ -254,22 +232,20 @@ def preheat_redis_cache() -> list[str]:
delete_keys_with_prefix(redis_conn, 'dcalc:')
delete_keys_with_prefix(redis_conn, 'openapi:')
custom_cn = _load_custom_cn()
base_preheat_tasks: list[PreheatTask] = [
('dcalc:adventure', get_adv_list),
('dcalc:custom_cn', lambda: custom_cn),
('openapi:skills', _load_skills),
]
shared_preheat_tasks = [
*_build_skill_tree_preheat_tasks(),
*_build_skill_data_preheat_tasks(custom_cn),
*_build_skill_data_preheat_tasks(),
*_build_oath_preheat_tasks(),
]
character_preheat_tasks = _build_character_preheat_tasks()
for key, loader in base_preheat_tasks:
try:
_write_preheated_value(redis_conn, key, loader(), without_gzip=key == 'dcalc:custom_cn')
_write_preheated_value(redis_conn, key, loader())
warmed_keys.append(key)
except Exception as exc:
print(f'Redis preheat failed for {key}: {exc}')
-1
View File
@@ -8,7 +8,6 @@ OPENAPI_STATIC_DIR = OPENAPI_DIR / 'static'
OPENAPI_DATA_DIR = OPENAPI_STATIC_DIR / 'data'
OPENAPI_SUMMARY_DIR = OPENAPI_STATIC_DIR / 'summary'
OPENAPI_SKILLS_PATH = OPENAPI_DATA_DIR / 'skills.json'
OPENAPI_CUSTOM_CN_PATH = OPENAPI_STATIC_DIR / 'custom_cn.json'
OPENAPI_RES_DIR = OPENAPI_STATIC_DIR / 'res'
LOCALES = {'cn', 'kr'}