This commit is contained in:
Kovid Goyal 2013-07-23 09:48:26 +05:30
parent 9b57e80e28
commit ef48091c23
2 changed files with 8 additions and 3 deletions

View File

@ -163,12 +163,13 @@ class CompositeField(OneToOneField):
self._render_cache = {}
self._lock = Lock()
self._composite_name = '#' + self.metadata['label']
def render_composite(self, book_id, mi):
with self._lock:
ans = self._render_cache.get(book_id, None)
if ans is None:
ans = mi.get('#'+self.metadata['label'])
ans = mi.get(self._composite_name)
with self._lock:
self._render_cache[book_id] = ans
return ans
@ -186,7 +187,7 @@ class CompositeField(OneToOneField):
ans = self._render_cache.get(book_id, None)
if ans is None:
mi = get_metadata(book_id)
ans = mi.get('#'+self.metadata['label'])
ans = mi.get(self._composite_name)
with self._lock:
self._render_cache[book_id] = ans
return ans

View File

@ -25,8 +25,12 @@ def show_stats(path):
def main():
stats = os.path.join(gettempdir(), 'read_db.stats')
pr = cProfile.Profile()
initdb('~/test library')
all_ids = db.new_api.all_book_ids() # noqa
pr.enable()
initdb('~/documents/largelib')
for book_id in all_ids:
db.new_api._composite_for('#isbn', book_id)
db.new_api._composite_for('#formats', book_id)
pr.disable()
pr.dump_stats(stats)
show_stats(stats)