Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/news/describe-perfromance.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**Performance:**

* Improved speed to return the echemdb description by caching the bibliography data.
32 changes: 16 additions & 16 deletions unitpackage/database/echemdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,24 +149,24 @@ def bibliography(self):
''

"""
from pybtex.database import BibliographyData

bib_data = BibliographyData(
{
entry.bibliography.key: entry.bibliography
for entry in self
if entry.bibliography
}
)
from pybtex.database import BibliographyData, parse_string

if isinstance(bib_data, str):
return bib_data
# Parse each unique bibdata string only once; many entries share a publication.
seen_citations = {}
for entry in self:
try:
citation = entry.source.bibdata
except AttributeError:
citation = ""
if citation and citation not in seen_citations:
seen_citations[citation] = parse_string(citation, "bibtex")

# Remove duplicates from the bibliography
bib_data_ = BibliographyData()
if not seen_citations:
return ""

for key, entry in bib_data.entries.items():
if key not in bib_data_.entries:
bib_data_.add_entry(key, entry)
bib_data_ = BibliographyData()
for parsed in seen_citations.values():
for key, bib_entry in parsed.entries.items():
bib_data_.add_entry(key, bib_entry)

return bib_data_
3 changes: 2 additions & 1 deletion unitpackage/database/echemdb_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
# along with unitpackage. If not, see <https://www.gnu.org/licenses/>.
# ********************************************************************
import logging
from functools import cached_property

from unitpackage.entry import Entry

Expand Down Expand Up @@ -174,7 +175,7 @@ def from_mpt(cls, csvname, encoding=None):

return entry

@property
@cached_property
def bibliography(self):
r"""
Return a pybtex bibliography object associated with this entry.
Expand Down