def cache(cls): """ Return the global LRU ormcache. Its keys are tuples with the following structure: (db_name, model_name, method, args...). """ with cls.lock(): if cls._cache is None: # we allocate 8192 cache entries per registry size = 8192 * cls.registries.count cls._cache = LRU(size) return cls._cache
def registries(cls): """ A mapping from database names to registries. """ size = config.get('registry_lru_size', None) if not size: # Size the LRU depending of the memory limits if os.name != 'posix': # cannot specify the memory limit soft on windows... size = 42 else: # A registry takes 10MB of memory on average, so we reserve # 10Mb (registry) + 5Mb (working memory) per registry avgsz = 15 * 1024 * 1024 size = int(config['limit_memory_soft'] / avgsz) return LRU(size)
def registries(cls): if cls._registries is None: size = config.get('registry_lru_size', None) if not size: # Size the LRU depending of the memory limits if os.name != 'posix': # cannot specify the memory limit soft on windows... size = 42 else: # On average, a clean registry take 25MB of memory + cache avgsz = 30 * 1024 * 1024 size = int(config['limit_memory_soft'] / avgsz) cls._registries = LRU(size) return cls._registries
def __init__(self, db_name): super(Registry, self).__init__() self.models = {} # model name/model instance mapping self._sql_error = {} self._store_function = {} self._pure_function_fields = {} # {model: [field, ...], ...} self._init = True self._init_parent = {} self._assertion_report = assertion_report.assertion_report() self._fields_by_model = None # modules fully loaded (maintained during init phase by `loading` module) self._init_modules = set() self.db_name = db_name self._db = openerp.sql_db.db_connect(db_name) # special cursor for test mode; None means "normal" mode self.test_cr = None # Indicates that the registry is self.ready = False # Inter-process signaling (used only when openerp.multi_process is True): # The `base_registry_signaling` sequence indicates the whole registry # must be reloaded. # The `base_cache_signaling sequence` indicates all caches must be # invalidated (i.e. cleared). self.base_registry_signaling_sequence = None self.base_cache_signaling_sequence = None self.cache = LRU(8192) # Flag indicating if at least one model cache has been cleared. # Useful only in a multi-process context. self._any_cache_cleared = False cr = self.cursor() has_unaccent = openerp.modules.db.has_unaccent(cr) if openerp.tools.config['unaccent'] and not has_unaccent: _logger.warning( "The option --unaccent was given but no unaccent() function was found in database." ) self.has_unaccent = openerp.tools.config['unaccent'] and has_unaccent #OpenUpgrade: ir_model must be in 9.0 format before continuing openupgrade_loading_90.migrate_model_tables(cr) cr.close()
def model_cache(cls): """ A cache for model classes, indexed by their base classes. """ if cls._model_cache is None: # we cache 256 classes per registry on average cls._model_cache = LRU(cls.registries.count * 256) return cls._model_cache
def model_cache(cls): """ A cache for model classes, indexed by their base classes. """ # we cache 256 classes per registry on average return LRU(cls.registries.count * 256)