Skip to content

Commit

Permalink
Optimize brain instantiation, by creating underlying record items in …
Browse files Browse the repository at this point in the history
…a single step, instead of creation and three update calls.
  • Loading branch information
hannosch committed Aug 12, 2012
1 parent 00bab42 commit 8beb201
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
2 changes: 2 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Changelog
3.0b2 (unreleased)
------------------

- Optimize brain instantiation, by creating underlying record items in a
single step, instead of creation and three update calls.

3.0b1 (2012-07-19)
------------------
Expand Down
38 changes: 25 additions & 13 deletions src/Products/ZCatalog/Catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,22 @@ def __getitem__(self, index):
if isinstance(index, tuple):
# then it contains a score...
normalized_score, score, key = index
r = self._v_result_class(self.data[key]).__of__(aq_parent(self))
else:
# otherwise no score, set all scores to 1
normalized_score, score, key = (1, 1, index)

data = self.data[key]
klass = self._v_result_class
schema_len = len(klass.__record_schema__)
if schema_len == len(data) + 3:
# if we have complete data, create in a single pass
r = klass(tuple(data) + (key, score, normalized_score))
else:
r = klass(data)
r.data_record_id_ = key
r.data_record_score_ = score
r.data_record_normalized_score_ = normalized_score
else:
# otherwise no score, set all scores to 1
r = self._v_result_class(self.data[index]).__of__(aq_parent(self))
r.data_record_id_ = index
r.data_record_score_ = 1
r.data_record_normalized_score_ = 1
r = r.__of__(aq_parent(self))
return r

def __setstate__(self, state):
Expand Down Expand Up @@ -638,12 +644,18 @@ def getScoredResult(item, max=max, self=self):
passed into self.useBrains.
"""
score, key = item
r = self._v_result_class(
self.data[key]).__of__(aq_parent(self))
r.data_record_id_ = key
r.data_record_score_ = score
r.data_record_normalized_score_ = \
int(100.0 * score / max)
data = self.data[key]
klass = self._v_result_class
schema_len = len(klass.__record_schema__)
norm_score = int(100.0 * score / max)
if schema_len == len(data) + 3:
r = klass(tuple(data) + (key, score, norm_score))
else:
r = klass(data)
r.data_record_id_ = key
r.data_record_score_ = score
r.data_record_normalized_score_ = norm_score
r = r.__of__(aq_parent(self))
return r

sequence, slen = self._limit_sequence(rs, rlen, b_start,
Expand Down

0 comments on commit 8beb201

Please sign in to comment.