Mercurial > p > roundup > code
diff roundup/backends/rdbms_common.py @ 6413:7b1b6dffc7ed
Fix searching+sorting for Link properties
Note that this turns off recursive pre-populating the cache in
filter_iter, we only pre-populate the top-level element. Otherwise this
interacts with searching producing duplicates.
| author | Ralf Schlatterbeck <rsc@runtux.com> |
|---|---|
| date | Mon, 17 May 2021 20:52:27 +0200 |
| parents | 9957d8d10783 |
| children | dbacf6bf2a2f |
line wrap: on
line diff
--- a/roundup/backends/rdbms_common.py Mon May 17 17:35:50 2021 +0200 +++ b/roundup/backends/rdbms_common.py Mon May 17 20:52:27 2021 +0200 @@ -2545,7 +2545,7 @@ a = self.db.arg # figure the WHERE clause from the filterspec - mlfilt = 0 # are we joining with Multilink tables? + use_distinct = False # Do we need a distinct clause? sortattr = self._sortattr (group = grp, sort = srt) proptree = self._proptree(filterspec, exact_match_spec, sortattr, retr) mlseen = 0 @@ -2581,7 +2581,8 @@ rc = oc = ac = '_%s._%s'%(pln, k) if isinstance(propclass, Multilink): if 'search' in p.need_for: - mlfilt = 1 + # if we joining with Multilink tables we need distinct + use_distinct = True tn = propclass.table_name nid = propclass.nodeid_name lid = propclass.linkid_name @@ -2672,7 +2673,9 @@ if p.children: if 'sort' not in p.need_for: frum.append('_%s as _%s' % (cn, ln)) - where.append('_%s._%s=_%s.id'%(pln, k, ln)) + c = [x for x in p.children if 'search' in x.need_for] + if c: + where.append('_%s._%s=_%s.id'%(pln, k, ln)) if p.has_values: if isinstance(v, type([])): d = {} @@ -2835,9 +2838,8 @@ where = ' where ' + (' and '.join(where)) else: where = '' - if mlfilt: - # we're joining tables on the id, so we will get dupes if we - # don't distinct() + if use_distinct: + # Avoid dupes cols[0] = 'distinct(_%s.id)'%icn order = []
