Skip to content

Commit

Permalink
Do the MSS check last
Browse files Browse the repository at this point in the history
It makes sense to check locally (to the data portal infrastructure) before we check the MSS.
  • Loading branch information
jrdh committed Dec 8, 2021
1 parent 63319b0 commit 7f51659
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions iiif/profiles/mss.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,20 +260,15 @@ async def get_mss_doc(self, name: str, refresh: bool = False) -> Optional[dict]:
"""

async def get_doc() -> Optional[dict]:
# first, check with mss that the irn is valid
async with self.mss_session.get(f'{self.mss_url}/{name}') as response:
if not response.ok:
return None

# next, check that we have a document in the mss index
# first, check that we have a document in the mss index
doc_url = f'{next(self.es_hosts)}/{self.mss_index}/_doc/{name}'
async with self.es_session.get(doc_url) as response:
text = await response.text(encoding='utf-8')
info = orjson.loads(text)
if not info['found']:
return None

# finally, check that the irn is associated with a record in the collection datasets
# next, check that the irn is associated with a record in the collection datasets
count_url = f'{next(self.es_hosts)}/{self.collection_indices}/_count'
search = Search() \
.filter('term', **{'data.associatedMedia._id': name}) \
Expand All @@ -283,6 +278,11 @@ async def get_doc() -> Optional[dict]:
if orjson.loads(text)['count'] == 0:
return None

# finally, check with mss that the irn is valid
async with self.mss_session.get(f'{self.mss_url}/{name}') as response:
if not response.ok:
return None

# if we get here then all 3 checks have passed
return info['_source']

Expand Down

0 comments on commit 7f51659

Please sign in to comment.