Browse Source

Cache xap specs

zvecr 4 years ago
parent
commit
f9f0d84eb0
2 changed files with 13 additions and 10 deletions
  1. 1 1
      lib/python/qmk/cli/xap/xap.py
  2. 12 9
      lib/python/qmk/xap/common.py

+ 1 - 1
lib/python/qmk/cli/xap/xap.py

@@ -10,7 +10,7 @@ from milc import cli
 
 from qmk.xap.common import get_xap_keycodes
 
-KEYCODE_MAP = get_xap_keycodes('0.2.0')
+KEYCODE_MAP = get_xap_keycodes('latest')
 
 
 def _is_xap_usage(x):

+ 12 - 9
lib/python/qmk/xap/common.py

@@ -8,6 +8,7 @@ from jinja2 import Environment, FileSystemLoader, select_autoescape
 
 from qmk.constants import QMK_FIRMWARE
 from qmk.json_schema import json_load
+from qmk.decorators import lru_cache
 
 
 def _get_jinja2_env(data_templates_xap_subdir: str):
@@ -74,26 +75,28 @@ def update_xap_definitions(original, new):
     return _merge_ordered_dicts([original, new])
 
 
-def latest_xap_defs():
-    """Gets the latest version of the XAP definitions.
-    """
-    definitions = [hjson.load(file.open(encoding='utf-8')) for file in get_xap_definition_files()]
-    return _merge_ordered_dicts(definitions)
-
-
+@lru_cache(timeout=5)
 def get_xap_defs(version):
     """Gets the required version of the XAP definitions.
     """
     files = get_xap_definition_files()
 
     # Slice off anything newer than specified version
-    index = [idx for idx, s in enumerate(files) if version in str(s)][0]
-    files = files[:(index + 1)]
+    if version != 'latest':
+        index = [idx for idx, s in enumerate(files) if version in str(s)][0]
+        files = files[:(index + 1)]
 
     definitions = [hjson.load(file.open(encoding='utf-8')) for file in files]
     return _merge_ordered_dicts(definitions)
 
 
+def latest_xap_defs():
+    """Gets the latest version of the XAP definitions.
+    """
+    return get_xap_defs('latest')
+
+
+@lru_cache(timeout=5)
 def get_xap_keycodes(xap_version):
     """Gets keycode data for the required version of the XAP definitions.
     """