From 45914073bfe4e315b3a733aadce7fcc23ed427e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Wed, 26 Aug 2009 15:39:53 +0200 Subject: [PATCH] Use faster join implementation: - use generator when possible - use tuple __mul__ --- trytond/backend/sqlite/table.py | 2 +- trytond/ir/model.py | 2 +- trytond/ir/module/module.py | 6 +++--- trytond/ir/translation.py | 6 +++--- trytond/ir/ui/view.py | 2 +- trytond/model/fields/property.py | 2 +- trytond/model/model.py | 2 +- trytond/model/modelsql.py | 24 ++++++++++++------------ trytond/modules/__init__.py | 2 +- 9 files changed, 24 insertions(+), 24 deletions(-) diff --git a/trytond/backend/sqlite/table.py b/trytond/backend/sqlite/table.py index 089ad1de37..662b0598f2 100644 --- a/trytond/backend/sqlite/table.py +++ b/trytond/backend/sqlite/table.py @@ -194,7 +194,7 @@ class TableHandler(TableHandlerInterface): return self.cursor.execute('CREATE INDEX "' + index_name + '" ' \ 'ON "' + self.table_name + '" ( ' + \ - ','.join(['"' + x + '"' for x in column_name]) + \ + ','.join('"' + x + '"' for x in column_name) + \ ')') self._update_definitions() elif action == 'remove': diff --git a/trytond/ir/model.py b/trytond/ir/model.py index 992ca7c27d..f882ef5945 100644 --- a/trytond/ir/model.py +++ b/trytond/ir/model.py @@ -95,7 +95,7 @@ class ModelField(ModelSQL, ModelView): model_ids.add(rec['model']) model_ids = list(model_ids) cursor.execute('SELECT id, model FROM ir_model WHERE id IN ' \ - '(' + ','.join(['%s' for x in model_ids]) + ')', model_ids) + '(' + ','.join(('%s',) * len(model_ids)) + ')', model_ids) id2model = dict(cursor.fetchall()) trans_args = [] diff --git a/trytond/ir/module/module.py b/trytond/ir/module/module.py index 9326ed29ad..07b597cf97 100644 --- a/trytond/ir/module/module.py +++ b/trytond/ir/module/module.py @@ -319,7 +319,7 @@ class Module(ModelSQL, ModelView): if res: self.raise_user_error(cursor, 'uninstall_dep', error_description='\n'.join( - ['\t%s: %s' % (x[0], x[1]) for x in res]), + '\t%s: %s' % (x[0], x[1]) for x in res), context=context) self.write(cursor, user, ids, {'state': 'to remove'}) return True @@ -647,8 +647,8 @@ class ModuleInstallUpgrade(Wizard): ], context=context) modules = module_obj.browse(cursor, user, module_ids, context=context) return { - 'module_info': '\n'.join([x.name + ': ' + x.state \ - for x in modules]), + 'module_info': '\n'.join(x.name + ': ' + x.state \ + for x in modules), } def _upgrade_module(self, cursor, user, data, context): diff --git a/trytond/ir/translation.py b/trytond/ir/translation.py index b0eb4293df..ad2c3e8a07 100644 --- a/trytond/ir/translation.py +++ b/trytond/ir/translation.py @@ -153,7 +153,7 @@ class Translation(ModelSQL, ModelView, Cacheable): 'AND value IS NOT NULL ' \ 'AND fuzzy = %s ' \ 'AND res_id in (' + \ - ','.join([str(x) for x in sub_to_fetch]) + ')', + ','.join(map(str, sub_to_fetch)) + ')', (lang, ttype, name, False)) for res_id, value in cursor.fetchall(): self.add(cursor, (lang, ttype, name, res_id), value) @@ -319,7 +319,7 @@ class Translation(ModelSQL, ModelView, Cacheable): sub_clause = clause[i:i + cursor.IN_MAX] cursor.execute('SELECT lang, type, name, src, value ' \ 'FROM ir_translation ' \ - 'WHERE ' + ' OR '.join([x[0] for x in sub_clause]), + 'WHERE ' + ' OR '.join(x[0] for x in sub_clause), reduce(lambda x, y: x + y, [x[1] for x in sub_clause])) for lang, ttype, name, source, value in cursor.fetchall(): if (name, ttype, lang, source) not in args: @@ -694,7 +694,7 @@ class ReportTranslationSet(Wizard): 'AND type = %s ' \ 'AND module = %s ' \ 'AND src NOT IN ' \ - '(' + ','.join(['%s' for x in strings]) + ')', + '(' + ','.join(('%s',) * len(strings)) + ')', (report.report_name, 'odt', report.module) + \ tuple(strings)) return {} diff --git a/trytond/ir/ui/view.py b/trytond/ir/ui/view.py index 5e26c110ac..3d6de4df52 100644 --- a/trytond/ir/ui/view.py +++ b/trytond/ir/ui/view.py @@ -140,7 +140,7 @@ class View(ModelSQL, ModelView): 'AND type = %s ' \ 'AND module = %s ' \ 'AND src NOT IN ' \ - '(' + ','.join(['%s' for x in strings]) + ')', + '(' + ','.join(('%s',) * len(strings)) + ')', (view.model, 'view', view.module) + tuple(strings)) return True diff --git a/trytond/model/fields/property.py b/trytond/model/fields/property.py index 282841e88b..2338511d94 100644 --- a/trytond/model/fields/property.py +++ b/trytond/model/fields/property.py @@ -161,7 +161,7 @@ class Property(Function): def get_condition(sql_type, arg): if arg[1] in ('in', 'not in'): return ("(cast(split_part(value,',',2) as %s) %s ("+ \ - ",".join('%%s' for x in arg[2]) + ")) ") % (sql_type, arg[1]) + ",".join(('%%s',) * len(arg[2])) + ")) ") % (sql_type, arg[1]) else: return "(cast(split_part(value,',',2) as %s) %s %%s) " % \ (sql_type, arg[1]) diff --git a/trytond/model/model.py b/trytond/model/model.py index 1bd019d9db..8f872f6e63 100644 --- a/trytond/model/model.py +++ b/trytond/model/model.py @@ -224,7 +224,7 @@ class Model(object): 'WHERE lang = %s ' \ 'AND type IN (%s, %s, %s) ' \ 'AND name IN ' \ - '(' + ','.join(['%s' for x in self._columns]) + ')', + '(' + ','.join(('%s',) * len(self._columns)) + ')', ('en_US', 'field', 'help', 'selection') + \ tuple([self._name + ',' + x \ for x in self._columns])) diff --git a/trytond/model/modelsql.py b/trytond/model/modelsql.py index 0905cfa9fc..b8972be9b0 100644 --- a/trytond/model/modelsql.py +++ b/trytond/model/modelsql.py @@ -726,7 +726,7 @@ class ModelSQL(ModelStorage): cursor.execute("SELECT id " \ 'FROM "' + self._table + '" ' \ 'WHERE ' + ' OR '.join( - [clause for x in range(len(args)/2)]), args) + (clause,) * (len(args)/2)), args) if cursor.fetchone(): raise Exception('ConcurrencyException', 'Records were modified in the meanwhile') @@ -969,7 +969,7 @@ class ModelSQL(ModelStorage): cursor.execute("SELECT id " \ 'FROM "' + self._table + '" ' \ 'WHERE ' + ' OR '.join( - [clause for x in range(len(args)/2)]), args) + (clause,) * (len(args)/2)), args) if cursor.fetchone(): raise Exception('ConcurrencyException', 'Records were modified in the meanwhile') @@ -985,7 +985,7 @@ class ModelSQL(ModelStorage): and field.left and field.right: cursor.execute('SELECT id FROM "' + self._table + '" '\ 'WHERE "' + k + '" IN (' \ - + ','.join(['%s' for x in ids]) + ')', + + ','.join(('%s',) * len(ids)) + ')', ids) tree_ids[k] = [x[0] for x in cursor.fetchall()] @@ -1363,7 +1363,7 @@ class ModelSQL(ModelStorage): query1 = 'SELECT "' + field.field + '" ' \ 'FROM ' + table_query + '"' + field_obj._table + '" ' \ 'WHERE id IN (' + \ - ','.join(['%s' for x in ids2]) + ')' + ','.join(('%s',) * len(ids2)) + ')' query2 = table_args + ids2 domain[i] = ('id', 'inselect', (query1, query2)) else: @@ -1417,7 +1417,7 @@ class ModelSQL(ModelStorage): query1 = 'SELECT "' + field.origin + '" ' \ 'FROM "' + relation_obj._table + '" ' \ 'WHERE "' + field.target + '" IN (' + \ - ','.join(['%s' for x in ids2]) + ') ' \ + ','.join(('%s',) * len(ids2)) + ') ' \ 'AND "' + field.origin + '" IS NOT NULL' query2 = [str(x) for x in ids2] if domain[i][1] == 'child_of': @@ -1459,7 +1459,7 @@ class ModelSQL(ModelStorage): query1 = 'SELECT "' + field.origin + '" ' \ 'FROM "' + relation_obj._table + '" ' \ 'WHERE "' + field.target + '" IN (' + \ - ','.join(['%s' for x in res_ids]) + ')' + ','.join(('%s',) * len(res_ids)) + ')' query2 = [str(x) for x in res_ids] domain[i] = ('id', 'inselect', (query1, query2)) i += 1 @@ -1503,7 +1503,7 @@ class ModelSQL(ModelStorage): '"' + field.right + '" ' + \ 'FROM "' + self._table + '" ' + \ 'WHERE id IN ' + \ - '(' + ','.join(['%s' for x in ids2]) + ')', + '(' + ','.join(('%s',) * len(ids2)) + ')', ids2) clause = FIELDS['boolean'].sql_format(False) + ' ' for left, right in cursor.fetchall(): @@ -1625,7 +1625,7 @@ class ModelSQL(ModelStorage): if len(arg2): qu1.append(('("%s"."%s" ' + arg[1] + ' (%s))') % \ (table._table, arg[0], ','.join( - ['%s'] * len(arg2)))) + ('%s',) * len(arg2)))) if todel: if table._columns[arg[0]]._type == 'boolean': if arg[1] == 'in': @@ -1997,14 +1997,14 @@ class ModelSQL(ModelStorage): # ids for left update cursor.execute('SELECT id FROM "' + self._table + '" ' \ 'WHERE "' + left + '" >= %s ' \ - 'AND id NOT IN (' + ','.join(['%s' for x in child_ids]) + ')', + 'AND id NOT IN (' + ','.join(('%s',) * len(child_ids)) + ')', [parent_right] + child_ids) left_ids = [x[0] for x in cursor.fetchall()] # ids for right update cursor.execute('SELECT id FROM "' + self._table + '" ' \ 'WHERE "' + right + '" >= %s ' \ - 'AND id NOT IN (' + ','.join(['%s' for x in child_ids]) + ')', + 'AND id NOT IN (' + ','.join(('%s',) * len(child_ids)) + ')', [parent_right] + child_ids) right_ids = [x[0] for x in cursor.fetchall()] @@ -2030,7 +2030,7 @@ class ModelSQL(ModelStorage): + str(parent_right - old_left) + ', ' \ '"' + right + '" = "' + right + '" + ' \ + str(parent_right - old_left) + ' ' \ - 'WHERE id IN (' + ','.join(['%s' for x in child_ids]) + ')', + 'WHERE id IN (' + ','.join(('%s',) * len(child_ids)) + ')', child_ids) # Use root user to by-pass rules @@ -2062,7 +2062,7 @@ class ModelSQL(ModelStorage): + str(current_left - next_left) + ', ' \ '"' + right + '" = "' + right + '" - ' \ + str(current_left - next_left) + ' ' \ - 'WHERE id in (' + ','.join(['%s' for x in child_ids]) + ')', + 'WHERE id in (' + ','.join(('%s',) * len(child_ids)) + ')', child_ids) def _validate(self, cursor, user, ids, context=None): diff --git a/trytond/modules/__init__.py b/trytond/modules/__init__.py index 6764a201dd..739859d626 100644 --- a/trytond/modules/__init__.py +++ b/trytond/modules/__init__.py @@ -194,7 +194,7 @@ def load_module_graph(cursor, graph, pool, lang=None): modules = [x.name for x in graph] cursor.execute('SELECT name, state FROM ir_module_module ' \ - 'WHERE name in (' + ','.join(['%s' for x in modules]) + ')', + 'WHERE name in (' + ','.join(('%s',) * len(modules)) + ')', modules) module2state = {} for name, state in cursor.fetchall():