diff --git a/openpype/modules/shotgrid/lib/settings.py b/openpype/modules/shotgrid/lib/settings.py index 4c21501b99..4a772de5b7 100644 --- a/openpype/modules/shotgrid/lib/settings.py +++ b/openpype/modules/shotgrid/lib/settings.py @@ -1,9 +1,9 @@ import os -# from functools import lru_cache from pymongo import MongoClient from openpype.api import get_system_settings, get_project_settings from openpype.modules.shotgrid.lib.const import MODULE_NAME +from openpype.modules.shotgrid.lib.tools import memoize def get_project_list(): @@ -13,12 +13,12 @@ def get_project_list(): return db.list_collection_names() -# @lru_cache(maxsize=64) +@memoize def get_shotgrid_project_settings(project): return get_project_settings(project).get(MODULE_NAME, {}) -# @lru_cache(maxsize=64) +@memoize def get_shotgrid_settings(): return get_system_settings().get("modules", {}).get(MODULE_NAME, {}) diff --git a/openpype/modules/shotgrid/lib/tools.py b/openpype/modules/shotgrid/lib/tools.py new file mode 100644 index 0000000000..6305e9ca50 --- /dev/null +++ b/openpype/modules/shotgrid/lib/tools.py @@ -0,0 +1,16 @@ +from functools import wraps + + +def memoize(function): + memo = {} + + @wraps(function) + def wrapper(*args): + try: + return memo[args] + except KeyError: + rv = function(*args) + memo[args] = rv + return rv + + return wrapper