mirror of
https://github.com/qurator-spk/modstool.git
synced 2025-06-09 19:59:57 +02:00
⚡ Make get_sets_file faster by using a lookup table
This commit is contained in:
parent
912e5d2b4a
commit
8fc4eeeb3b
1 changed files with 10 additions and 2 deletions
|
@ -279,10 +279,18 @@ def pages_to_dict(mets, raise_errors=True) -> List[Dict]:
|
|||
div_physSequence = structMap_PHYSICAL[0]
|
||||
assert div_physSequence.attrib.get("TYPE") == "physSequence"
|
||||
|
||||
|
||||
# Build a look-up table to get mets:file by @ID
|
||||
# This cuts retrieving the mets:file down to half the time.
|
||||
mets_file_by_ID = {}
|
||||
def _init_mets_file_by_ID():
|
||||
for f in fileSec.iterfind('./mets:fileGrp/mets:file', ns):
|
||||
mets_file_by_ID[f.attrib.get("ID")] = f
|
||||
_init_mets_file_by_ID()
|
||||
|
||||
def get_mets_file(*, ID):
|
||||
if ID:
|
||||
file_ = fileSec.find(f'./mets:fileGrp/mets:file[@ID="{ID}"]', ns)
|
||||
return file_
|
||||
return mets_file_by_ID[ID]
|
||||
|
||||
def get_mets_div(*, ID):
|
||||
if ID:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue