Verified Commit 35cb72f5 authored by Fabio Manganiello's avatar Fabio Manganiello
Browse files

Do a lazy plugin initialization in the Variable class

This is useful for two reason:

1. Slightly faster variable initialization times.
2. The cached variable object won't fail on the next `.get()`/`.set()`
   if the `db` or `redis` plugins have failed for some reason.
parent 115bed7d
Pipeline #254 passed with stages
in 5 minutes and 23 seconds
......@@ -171,15 +171,17 @@ class Variable:
def __init__(self, name: str, persisted: bool = True): = name
plugin = get_plugin('variable')
self._get_action = getattr(plugin, 'get' if persisted else 'mget')
self._set_action = getattr(plugin, 'set' if persisted else 'mset')
self._persisted = persisted
def get(self) -> Optional[Any]:
return self._get_action(
plugin = get_plugin('variable')
getter = getattr(plugin, 'get' if self._persisted else 'mget')
return getter(
def set(self, value: Any):
self._set_action(**{ value})
plugin = get_plugin('variable')
setter = getattr(plugin, 'set' if self._persisted else 'mset')
setter(**{ value})
# vim:sw=4:ts=4:et:
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment