Allow skipping index creation

Closes #12596
This commit is contained in:
Nicolas Évrard
2023-09-27 17:15:44 +02:00
parent f26aa8863a
commit 9ef3a0aafa
6 changed files with 24 additions and 12 deletions
+1
View File
@@ -1,3 +1,4 @@
* Allow skipping index creation
* Add assert methods to test tools
* Set ELLIPSIS option flag on doctest
* Set IGNORE_EXCEPTION_DETAIL option flag on doctest
+2
View File
@@ -22,6 +22,8 @@ parser = commandline.get_parser_admin()
if argcomplete:
argcomplete.autocomplete(parser)
options = parser.parse_args()
if options.indexes is None:
options.indexes = bool(options.update)
config.update_etc(options.configfile)
commandline.config_log(options)
+2 -1
View File
@@ -55,7 +55,8 @@ def run(options):
lang |= set(options.languages)
pool = Pool(db_name)
pool.init(update=options.update, lang=list(lang),
activatedeps=options.activatedeps)
activatedeps=options.activatedeps,
indexes=options.indexes)
if options.update_modules_list:
with Transaction().start(db_name, 0) as transaction:
+3
View File
@@ -107,6 +107,9 @@ def get_parser_admin():
"-u", "--update", dest="update", nargs='+', default=[],
metavar='MODULE',
help="activate or update a module").completer = module_completer
parser.add_argument(
"--indexes", dest="indexes", action=argparse.BooleanOptionalAction,
default=None, help="update indexes")
parser.add_argument("--all", dest="update", action="append_const",
const="ir", help="update all activated modules")
parser.add_argument("--activate-dependencies", dest="activatedeps",
+13 -9
View File
@@ -132,7 +132,7 @@ def load_translations(pool, node, languages):
Translation.translation_import(language, module, files)
def load_module_graph(graph, pool, update=None, lang=None):
def load_module_graph(graph, pool, update=None, lang=None, indexes=True):
# Prevent to import backend when importing module
from trytond.cache import Cache
from trytond.ir.lang import get_parent_language
@@ -247,12 +247,15 @@ def load_module_graph(graph, pool, update=None, lang=None):
pool.setup_mixin()
if update:
for model_name in models_with_indexes:
model = pool.get(model_name)
if model._sql_indexes:
logger.info('index:create %s', model_name)
model._update_sql_indexes()
transaction.commit()
if indexes:
for model_name in models_with_indexes:
model = pool.get(model_name)
if model._sql_indexes:
logger.info('index:create %s', model_name)
model._update_sql_indexes()
transaction.commit()
else:
logger.info('index:skipping indexes creation')
for model_name in models_to_update_history:
model = pool.get(model_name)
if model._history:
@@ -310,7 +313,8 @@ def register_classes(with_test=False):
def load_modules(
database_name, pool, update=None, lang=None, activatedeps=False):
database_name, pool, update=None, lang=None, indexes=True,
activatedeps=False):
# Do not import backend when importing module
res = True
if update:
@@ -343,7 +347,7 @@ def load_modules(
raise
update += e.missings
load_module_graph(graph, pool, update, lang)
load_module_graph(graph, pool, update, lang, indexes)
Configuration = pool.get('ir.configuration')
Configuration(1).check()
+3 -2
View File
@@ -144,11 +144,12 @@ class Pool(object):
'''
return self._locks[self.database_name]
def init(self, update=None, lang=None, activatedeps=False):
def init(self, update=None, lang=None, activatedeps=False, indexes=True):
'''
Init pool
Set update to proceed to update
lang is a list of language code to be updated
indexes is a boolean specifying if the indexes should be created
'''
with self._lock:
if not self._started:
@@ -166,7 +167,7 @@ class Pool(object):
try:
restart = not load_modules(
self.database_name, self, update=update, lang=lang,
activatedeps=activatedeps)
indexes=indexes)
except Exception:
del self._pool[self.database_name]
self._modules = None