Skip to content

Commit

Permalink
Merge pull request #4 from mamico/patch-1
Browse files Browse the repository at this point in the history
[BACKPORT] Avoid potentially expensive `len()` call in value index estimation
  • Loading branch information
tseaver committed Oct 9, 2014
2 parents 91bba1a + 7bd631e commit e8a1e19
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Products/ZCatalog/plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,15 @@ def valueindexes(self):
for name, index in indexes.items():
if IUniqueValueIndex.providedBy(index):
values = index.uniqueValues()
if values and len(list(values)) < MAX_DISTINCT_VALUES:
i = 0
for value in values:
# the total number of unique values might be large and
# expensive to load, so we only check if we can get
# more than MAX_DISTINCT_VALUES
if i >= MAX_DISTINCT_VALUES:
break
i += 1
if i > 0 and i < MAX_DISTINCT_VALUES:
# Only consider indexes which actually return a number
# greater than zero
value_indexes.add(name)
Expand Down

0 comments on commit e8a1e19

Please sign in to comment.