From 677f2c213caaba58e49e4a58544c901606269b91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 30 May 2017 22:03:32 +0200 Subject: [PATCH] Remove duplicate ids when searching parent menu This prevents to generate a too big SQL query and also avoid to fail in the SQLite bug: https://www.sqlite.org/src/tktview?name=61fe97454c issue6514 review34131002 --- trytond/ir/ui/menu.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/trytond/ir/ui/menu.py b/trytond/ir/ui/menu.py index 5a5a0e55fe..5a5e6454ef 100644 --- a/trytond/ir/ui/menu.py +++ b/trytond/ir/ui/menu.py @@ -4,6 +4,7 @@ from itertools import groupby from trytond.model import ModelView, ModelSQL, fields, sequence_ordered from trytond.transaction import Transaction +from trytond.tools import grouped_slice from trytond.pool import Pool from trytond.rpc import RPC @@ -178,10 +179,12 @@ class UIMenu(sequence_ordered(), ModelSQL, ModelView): return menus if menus: - parent_ids = [x.parent.id for x in menus if x.parent] - parents = cls.search([ - ('id', 'in', parent_ids), - ]) + parent_ids = {x.parent.id for x in menus if x.parent} + parents = set() + for sub_parent_ids in grouped_slice(parent_ids): + parents.update(cls.search([ + ('id', 'in', list(sub_parent_ids)), + ])) menus = [x for x in menus if (x.parent and x.parent in parents) or not x.parent]