Speed up pool setup
We split the operations into two steps, so we can do the setup calls at the end if there is no installation or update. issue5302 review17041002
This commit is contained in:
1 parent
39bcde5357
commit
a650e8469f
3 files changed
+32
-11
No files matched your search
+8
-3
@@ -39,10 +39,15 @@ Instance methods:
|
||||
|
||||
Return an interator over instances names.
|
||||
|
||||
.. method:: Pool.setup(module)
|
||||
.. method:: Pool.fill(module)
|
||||
|
||||
Setup classes for module and return a list of classes for each type in a
|
||||
dictionary.
|
||||
Fill the pool with the registered class from the module and return a list
|
||||
of classes for each type in a dictionary.
|
||||
|
||||
.. method:: Pool.setup([classes])
|
||||
|
||||
Call all setup methods of the classes provided or for all the registered
|
||||
classes.
|
||||
|
||||
========
|
||||
PoolMeta
|
||||
|
||||
@@ -217,10 +217,13 @@ def load_module_graph(graph, pool, update=None, lang=None):
|
||||
if module not in MODULES:
|
||||
continue
|
||||
logger.info(module)
|
||||
classes = pool.setup(module)
|
||||
classes = pool.fill(module)
|
||||
if update:
|
||||
pool.setup(classes)
|
||||
package_state = module2state.get(module, 'uninstalled')
|
||||
if (is_module_to_install(module, update)
|
||||
or package_state in ('to install', 'to upgrade')):
|
||||
or (update
|
||||
and package_state in ('to install', 'to upgrade'))):
|
||||
if package_state not in ('to install', 'to upgrade'):
|
||||
if package_state == 'installed':
|
||||
package_state = 'to upgrade'
|
||||
@@ -281,6 +284,9 @@ def load_module_graph(graph, pool, update=None, lang=None):
|
||||
|
||||
Transaction().connection.commit()
|
||||
|
||||
if not update:
|
||||
pool.setup()
|
||||
|
||||
for model_name in models_to_update_history:
|
||||
model = pool.get(model_name)
|
||||
if model._history:
|
||||
@@ -291,6 +297,7 @@ def load_module_graph(graph, pool, update=None, lang=None):
|
||||
while modules_todo:
|
||||
(module, to_delete) = modules_todo.pop()
|
||||
convert.post_import(pool, module, to_delete)
|
||||
logger.info('all modules loaded')
|
||||
|
||||
|
||||
def get_module_list():
|
||||
|
||||
+15
-6
@@ -196,10 +196,10 @@ class Pool(object):
|
||||
'''
|
||||
return self._pool[self.database_name][type].iteritems()
|
||||
|
||||
def setup(self, module):
|
||||
def fill(self, module):
|
||||
'''
|
||||
Setup classes for module and return a list of classes for each type in
|
||||
a dictionary.
|
||||
Fill the pool with the registered class from the module.
|
||||
Return a list of classes for each type in a dictionary.
|
||||
'''
|
||||
classes = {}
|
||||
for type_ in self.classes.keys():
|
||||
@@ -212,13 +212,22 @@ class Pool(object):
|
||||
pass
|
||||
if not issubclass(cls, PoolBase):
|
||||
continue
|
||||
cls.__setup__()
|
||||
self.add(cls, type=type_)
|
||||
classes[type_].append(cls)
|
||||
for cls in classes[type_]:
|
||||
cls.__post_setup__()
|
||||
return classes
|
||||
|
||||
def setup(self, classes=None):
|
||||
logger.info('setup pool for "%s"', self.database_name)
|
||||
if classes is None:
|
||||
classes = {}
|
||||
for type_ in self._pool[self.database_name]:
|
||||
classes[type_] = self._pool[self.database_name][type_].values()
|
||||
for type_, lst in classes.iteritems():
|
||||
for cls in lst:
|
||||
cls.__setup__()
|
||||
for cls in lst:
|
||||
cls.__post_setup__()
|
||||
|
||||
|
||||
def isregisteredby(obj, module, type_='model'):
|
||||
pool = Pool()
|
||||
|
||||
Reference in new issue
Block a user