Browse Source

Add opcode cache to common DB retrievals.

scossu 9 months ago
parent
commit
b4bbe80522
3 changed files with 7 additions and 2 deletions
  1. 4 0
      scriptshifter/tables/__init__.py
  2. 2 1
      tests/__init__.py
  3. 1 1
      tests/test01_cfg.py

+ 4 - 0
scriptshifter/tables/__init__.py

@@ -3,6 +3,7 @@ import re
 import sqlite3
 
 from collections import defaultdict
+from functools import cache
 from importlib import import_module
 from json import dumps as jdumps, loads as jloads
 from os import R_OK, access, environ, makedirs, path, unlink
@@ -282,6 +283,7 @@ def populate_table(conn, tid, tname):
                     opt["default"]))
 
 
+@cache
 def list_tables():
     """
     List all the indexed tables.
@@ -480,6 +482,7 @@ def load_hook_fn(cname, sec):
     return hook_fn
 
 
+@cache
 def get_language(lang):
     """ Get all language options from the DB. """
 
@@ -580,6 +583,7 @@ def get_lang_ignore(conn, lang_id):
     return tuple(row[0] for row in qry)
 
 
+@cache
 def get_lang_map(conn, lang_id, t_dir):
     """
     S2R or R2S map.

+ 2 - 1
tests/__init__.py

@@ -20,7 +20,8 @@ def reload_tables():
     reload(scriptshifter.tables)  # Reload new config dir.
     from scriptshifter import tables
     tables.list_tables.cache_clear()
-    tables.load_table.cache_clear()
+    tables.get_language.cache_clear()
+    tables.get_lang_map.cache_clear()
 
     return tables
 

+ 1 - 1
tests/test01_cfg.py

@@ -113,7 +113,7 @@ class TestHooks(TestCase):
                 tbl["script_to_roman"]["hooks"],
                 {
                     "begin_input_token": [
-                        (scriptshifter.hooks.test.rotate, {"n": -3})
+                        ("test", scriptshifter.hooks.test.rotate, {"n": -3})
                     ]
                 })