Skip to content

Commit

Permalink
Avoid loading keywords from a protobuf.
Browse files Browse the repository at this point in the history
  • Loading branch information
fatlotus committed Mar 7, 2016
1 parent f56f545 commit 5c37b95
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion caravel/model/full_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,17 @@ def grouper(iterable, n, fillvalue=None):
return itertools.izip_longest(fillvalue=fillvalue, *args)


class AvoidRereadingFromPBProperty(ndb.ComputedProperty):
"""
Since ComputedPropertys are overwritten on writes anyway, we might as well
avoid the expensive desearlization process for reads.
"""

def _deserialize(self, ent, property, depth=1): pass


class FullTextMixin(ndb.Model):
keywords = ndb.ComputedProperty(
keywords = AvoidRereadingFromPBProperty(
lambda self: list(set(self._keywords())), repeated=True)

@classmethod
Expand Down

0 comments on commit 5c37b95

Please sign in to comment.