aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2017-01-14 15:36:49 +0100
committerElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2017-01-14 15:36:49 +0100
commit5d61ea607d314cbc99e858ce4aa5a6b56e815296 (patch)
tree182c466d412aab698b1844ad9d19eeb452e9cbbe
parente5d30f21c99bec9a8eccd881e5e83088b9378454 (diff)
More efficient retrieval of entries by id
-rw-r--r--lesana/collection.py21
1 files changed, 10 insertions, 11 deletions
diff --git a/lesana/collection.py b/lesana/collection.py
index 2a80072..92ffcbb 100644
--- a/lesana/collection.py
+++ b/lesana/collection.py
@@ -242,12 +242,15 @@ class Collection(object):
offset += pagesize
def _match_to_entry(self, match):
- fname = match.document.get_value(0).decode('utf-8')
+ return self._doc_to_entry(match.document)
+
+ def _doc_to_entry(self, doc):
+ fname = doc.get_value(0).decode('utf-8')
if self.safe:
- data = ruamel.yaml.safe_load(match.document.get_data())
+ data = ruamel.yaml.safe_load(doc.get_data())
else:
data = ruamel.yaml.load(
- match.document.get_data(),
+ doc.get_data(),
ruamel.yaml.RoundTripLoader
)
entry = Entry(
@@ -259,14 +262,10 @@ class Collection(object):
def entry_from_uid(self, uid):
cache = self._get_cache()
- query = xapian.Query('Q'+uid)
- enquire = xapian.Enquire(cache)
- enquire.set_query(query)
- # FIXME: if more items are returned, something is wrong?
- try:
- return self._match_to_entry(enquire.get_mset(0, 1)[0])
- except IndexError:
- return None
+ postlist = cache.postlist('Q'+uid)
+ for pitem in postlist:
+ return self._doc_to_entry(cache.get_document(pitem.docid))
+ return None
def remove_entries(self, uids):
cache = xapian.WritableDatabase(