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
This commit is contained in:
Cédric Krier committed 2017-05-30 22:03:32 +02:00
1 parent b37dd9706b
commit 677f2c213c
1 file changed
+7 -4
+7 -4
View File
@@ -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]