Commit e1ab3fc7 by Erik Hetzner

Merge branch 'better-perf' into 'master'

cache bibdata as well as citations

I am not entirely sure this is safe, but at least it works fine for me, and prevents a duplicate HTTP request for each RST page.

See merge request !4
parents 9a8ef7db 209953e2
...@@ -37,21 +37,27 @@ class CiteprocWrapper(object): ...@@ -37,21 +37,27 @@ class CiteprocWrapper(object):
def __init__(self): def __init__(self):
self.citations = None self.citations = None
self.bibdata = None
def generate_rest_bibliography(self): def generate_rest_bibliography(self):
"""Generate a bibliography of reST nodes.""" """Generate a bibliography of reST nodes."""
clusters = xciterst.cluster_tracker.get() self.cache_citations()
bibdata = self.citeproc_process(clusters)[1] bibdata = self.bibdata
if not(bibdata): if not(bibdata):
return html2rst("") return html2rst("")
else: else:
return html2rst("%s%s%s"%(bibdata[0]["bibstart"], "".join(bibdata[1]), bibdata[0]["bibend"])) return html2rst("".join((
def cache_citations(self): def cache_citations(self):
if (self.citations is None): if (self.citations is None):
clusters = xciterst.cluster_tracker.get() clusters = xciterst.cluster_tracker.get()
html = self.citeproc_process(clusters)[0] citdata, bibdata = self.citeproc_process(clusters)
self.citations = [ html2rst(n) for n in html ] self.citations = [ html2rst(n) for n in citdata ]
self.bibdata = bibdata
def get_citation(self, cluster): def get_citation(self, cluster):
self.cache_citations() self.cache_citations()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment