From 7f51659c2baff85f483a65d04eae6db4380c7ee1 Mon Sep 17 00:00:00 2001 From: Josh Humphries Date: Wed, 8 Dec 2021 12:44:32 +0000 Subject: [PATCH] Do the MSS check last It makes sense to check locally (to the data portal infrastructure) before we check the MSS. --- iiif/profiles/mss.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/iiif/profiles/mss.py b/iiif/profiles/mss.py index b7a5b6a..b9c0bc6 100644 --- a/iiif/profiles/mss.py +++ b/iiif/profiles/mss.py @@ -260,12 +260,7 @@ 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') @@ -273,7 +268,7 @@ async def get_doc() -> Optional[dict]: 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}) \ @@ -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']