limit database usage
This commit is contained in:
parent
d445963429
commit
dc9454be63
|
@ -21,6 +21,7 @@
|
||||||
from .error import PropertiesOptionError, ConfigError, SlaveError
|
from .error import PropertiesOptionError, ConfigError, SlaveError
|
||||||
from .i18n import _
|
from .i18n import _
|
||||||
from .setting import undefined
|
from .setting import undefined
|
||||||
|
from .storage import get_default_values_storages, get_default_settings_storages
|
||||||
# ____________________________________________________________
|
# ____________________________________________________________
|
||||||
|
|
||||||
|
|
||||||
|
@ -149,7 +150,9 @@ def carry_out_calculation(option, context, callback, callback_params,
|
||||||
return undefined
|
return undefined
|
||||||
if callbk[0] is None: # pragma: optional cover
|
if callbk[0] is None: # pragma: optional cover
|
||||||
#Not an option, set full context
|
#Not an option, set full context
|
||||||
tcparams.setdefault(key, []).append((context.duplicate(), False))
|
tcparams.setdefault(key, []).append((context.duplicate(
|
||||||
|
force_values=get_default_values_storages(),
|
||||||
|
force_settings=get_default_settings_storages()), False))
|
||||||
elif callbk[0] == 'index':
|
elif callbk[0] == 'index':
|
||||||
tcparams.setdefault(key, []).append((index, False))
|
tcparams.setdefault(key, []).append((index, False))
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -30,7 +30,7 @@ from .option import OptionDescription, Option, SymLinkOption, \
|
||||||
from .option.baseoption import valid_name
|
from .option.baseoption import valid_name
|
||||||
from .setting import groups, Settings, default_encoding, undefined
|
from .setting import groups, Settings, default_encoding, undefined
|
||||||
from .storage import get_storages, get_storage, set_storage, \
|
from .storage import get_storages, get_storage, set_storage, \
|
||||||
_impl_getstate_setting, get_storages_validation
|
_impl_getstate_setting, get_default_values_storages
|
||||||
from .value import Values, Multi
|
from .value import Values, Multi
|
||||||
from .i18n import _
|
from .i18n import _
|
||||||
|
|
||||||
|
@ -754,13 +754,14 @@ class _CommonConfig(SubConfig):
|
||||||
|
|
||||||
def _gen_fake_values(self, session):
|
def _gen_fake_values(self, session):
|
||||||
fake_config = Config(self._impl_descr, persistent=False,
|
fake_config = Config(self._impl_descr, persistent=False,
|
||||||
force_values=get_storages_validation(),
|
force_values=get_default_values_storages(),
|
||||||
force_settings=self.cfgimpl_get_settings())
|
force_settings=self.cfgimpl_get_settings())
|
||||||
fake_config.cfgimpl_get_values()._p_.importation(self.cfgimpl_get_values()._p_.exportation(session, fake=True))
|
fake_config.cfgimpl_get_values()._p_.importation(self.cfgimpl_get_values()._p_.exportation(session, fake=True))
|
||||||
return fake_config
|
return fake_config
|
||||||
|
|
||||||
def duplicate(self):
|
def duplicate(self, force_values=None, force_settings=None):
|
||||||
config = Config(self._impl_descr, _duplicate=True)
|
config = Config(self._impl_descr, _duplicate=True, force_values=force_values,
|
||||||
|
force_settings=force_settings)
|
||||||
session = self.cfgimpl_get_values()._p_.getsession()
|
session = self.cfgimpl_get_values()._p_.getsession()
|
||||||
config.cfgimpl_get_values()._p_.importation(self.cfgimpl_get_values()._p_.exportation(
|
config.cfgimpl_get_values()._p_.importation(self.cfgimpl_get_values()._p_.exportation(
|
||||||
session))
|
session))
|
||||||
|
@ -792,6 +793,9 @@ class Config(_CommonConfig):
|
||||||
:type persistent: `boolean`
|
:type persistent: `boolean`
|
||||||
"""
|
"""
|
||||||
if force_settings is not None and force_values is not None:
|
if force_settings is not None and force_values is not None:
|
||||||
|
if isinstance(force_settings, tuple):
|
||||||
|
self._impl_settings = Settings(self, force_settings[0], force_settings[1])
|
||||||
|
else:
|
||||||
self._impl_settings = force_settings
|
self._impl_settings = force_settings
|
||||||
self._impl_values = Values(self, force_values)
|
self._impl_values = Values(self, force_values)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -942,7 +942,7 @@ class Option(OnlyOption):
|
||||||
:param load: `True` if we are at the init of the option description
|
:param load: `True` if we are at the init of the option description
|
||||||
:type load: bool
|
:type load: bool
|
||||||
"""
|
"""
|
||||||
if not load and self._get_consistencies() == ():
|
if not load and not self._has_consistencies():
|
||||||
self._state_consistencies = None
|
self._state_consistencies = None
|
||||||
elif load and self._state_consistencies is None:
|
elif load and self._state_consistencies is None:
|
||||||
del(self._state_consistencies)
|
del(self._state_consistencies)
|
||||||
|
@ -1195,6 +1195,9 @@ class SymLinkOption(OnlyOption):
|
||||||
def _get_consistencies(self):
|
def _get_consistencies(self):
|
||||||
return ()
|
return ()
|
||||||
|
|
||||||
|
def _has_consistencies(self):
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
class DynSymLinkOption(object):
|
class DynSymLinkOption(object):
|
||||||
__slots__ = ('_dyn', '_opt', '_name')
|
__slots__ = ('_dyn', '_opt', '_name')
|
||||||
|
|
|
@ -77,8 +77,8 @@ class StorageType(object):
|
||||||
storage_type = StorageType()
|
storage_type = StorageType()
|
||||||
storage_option_type = StorageType()
|
storage_option_type = StorageType()
|
||||||
storage_option_type.set(DEFAULT_STORAGE)
|
storage_option_type.set(DEFAULT_STORAGE)
|
||||||
storage_validation = StorageType()
|
default_validation = StorageType()
|
||||||
storage_validation.set(DEFAULT_STORAGE)
|
default_validation.set(DEFAULT_STORAGE)
|
||||||
|
|
||||||
|
|
||||||
def set_storage(type_, name, **kwargs): # pragma: optional cover
|
def set_storage(type_, name, **kwargs): # pragma: optional cover
|
||||||
|
@ -122,7 +122,7 @@ def get_storage(type_, session_id, persistent, test): # pragma: optional cover
|
||||||
elif type_ == 'config':
|
elif type_ == 'config':
|
||||||
return storage_type.get().Storage(session_id, persistent, test)
|
return storage_type.get().Storage(session_id, persistent, test)
|
||||||
else:
|
else:
|
||||||
return storage_validation.get().Storage(session_id, persistent, test)
|
return default_validation.get().Storage(session_id, persistent, test)
|
||||||
|
|
||||||
|
|
||||||
def get_storages(context, session_id, persistent):
|
def get_storages(context, session_id, persistent):
|
||||||
|
@ -149,12 +149,20 @@ def get_storages_option(type_):
|
||||||
return imp.StorageOptionDescription
|
return imp.StorageOptionDescription
|
||||||
|
|
||||||
|
|
||||||
def get_storages_validation():
|
def get_default_values_storages():
|
||||||
imp = storage_validation.get()
|
imp = default_validation.get()
|
||||||
storage = imp.Storage('__validator_storage', persistent=False, test=True)
|
storage = imp.Storage('__validator_storage', persistent=False, test=True)
|
||||||
return imp.Values(storage)
|
return imp.Values(storage)
|
||||||
|
|
||||||
|
|
||||||
|
def get_default_settings_storages():
|
||||||
|
imp = default_validation.get()
|
||||||
|
storage = imp.Storage('__validator_storage', persistent=False, test=True)
|
||||||
|
properties = imp.Properties(storage)
|
||||||
|
permissives = imp.Permissives(storage)
|
||||||
|
return properties, permissives
|
||||||
|
|
||||||
|
|
||||||
def list_sessions(type_): # pragma: optional cover
|
def list_sessions(type_): # pragma: optional cover
|
||||||
"""List all available session (persistent or not persistent)
|
"""List all available session (persistent or not persistent)
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -166,6 +166,9 @@ class StorageBase(object):
|
||||||
def _get_consistencies(self):
|
def _get_consistencies(self):
|
||||||
return getattr(self, '_consistencies', static_tuple)
|
return getattr(self, '_consistencies', static_tuple)
|
||||||
|
|
||||||
|
def _has_consistencies(self):
|
||||||
|
return hasattr(self, '_consistencies')
|
||||||
|
|
||||||
def _set_callback(self, callback, callback_params):
|
def _set_callback(self, callback, callback_params):
|
||||||
val = getattr(self, '_val_call', (None,))[0]
|
val = getattr(self, '_val_call', (None,))[0]
|
||||||
if callback_params is None or callback_params == {}:
|
if callback_params is None or callback_params == {}:
|
||||||
|
|
|
@ -21,6 +21,8 @@ from os.path import basename, splitext, join, isfile
|
||||||
import sqlite3
|
import sqlite3
|
||||||
from glob import glob
|
from glob import glob
|
||||||
from ..util import SerializeObject
|
from ..util import SerializeObject
|
||||||
|
global idx
|
||||||
|
idx = 0
|
||||||
|
|
||||||
|
|
||||||
class Setting(SerializeObject):
|
class Setting(SerializeObject):
|
||||||
|
@ -93,6 +95,9 @@ class Storage(object):
|
||||||
self.execute(permissives_table)
|
self.execute(permissives_table)
|
||||||
|
|
||||||
def execute(self, sql, params=None, commit=True):
|
def execute(self, sql, params=None, commit=True):
|
||||||
|
global idx
|
||||||
|
idx += 1
|
||||||
|
print(idx, sql, params)
|
||||||
if params is None:
|
if params is None:
|
||||||
params = tuple()
|
params = tuple()
|
||||||
self._cursor.execute(sql, params)
|
self._cursor.execute(sql, params)
|
||||||
|
|
|
@ -152,7 +152,7 @@ class Values(Sqlite3DB):
|
||||||
try:
|
try:
|
||||||
nowner = getattr(owners, owner[0])
|
nowner = getattr(owners, owner[0])
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
owners.addowner(towner)
|
owners.addowner(owner[0])
|
||||||
nowner = getattr(owners, owner[0])
|
nowner = getattr(owners, owner[0])
|
||||||
if not with_value:
|
if not with_value:
|
||||||
return nowner
|
return nowner
|
||||||
|
|
|
@ -409,9 +409,13 @@ class Values(object):
|
||||||
_setting_properties = context.cfgimpl_get_settings()._getproperties(read_write=False)
|
_setting_properties = context.cfgimpl_get_settings()._getproperties(read_write=False)
|
||||||
if 'validator' in _setting_properties:
|
if 'validator' in _setting_properties:
|
||||||
session = context.cfgimpl_get_values()._p_.getsession()
|
session = context.cfgimpl_get_values()._p_.getsession()
|
||||||
|
if opt._has_consistencies():
|
||||||
fake_context = context._gen_fake_values(session)
|
fake_context = context._gen_fake_values(session)
|
||||||
fake_values = fake_context.cfgimpl_get_values()
|
fake_values = fake_context.cfgimpl_get_values()
|
||||||
fake_values._setvalue(opt, path, value, index=index)
|
fake_values._setvalue(opt, path, value, index=index)
|
||||||
|
else:
|
||||||
|
fake_context = context
|
||||||
|
fake_values = self
|
||||||
props = fake_values.validate(opt, value, path,
|
props = fake_values.validate(opt, value, path,
|
||||||
check_frozen=check_frozen,
|
check_frozen=check_frozen,
|
||||||
force_permissive=force_permissive,
|
force_permissive=force_permissive,
|
||||||
|
|
Loading…
Reference in New Issue