From 1328cd3bc5c3d6db5228002e1b58702d01059b16 Mon Sep 17 00:00:00 2001 From: Patrick Huck Date: Wed, 5 Mar 2025 11:37:09 -0800 Subject: [PATCH] exclude gnome for full downloads if needed --- mp_api/client/core/client.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/mp_api/client/core/client.py b/mp_api/client/core/client.py index e04215e1..593eec6c 100644 --- a/mp_api/client/core/client.py +++ b/mp_api/client/core/client.py @@ -485,6 +485,23 @@ def _query_resource( suffix = infix if suffix == "core" else suffix suffix = suffix.replace("_", "-") + # Check if user has access to GNoMe + has_gnome_access = bool( + self._submit_requests( + url=urljoin(self.endpoint, "materials/summary/"), + criteria={ + "batch_id": "gnome_r2scan_statics", + "_fields": "material_id", + }, + use_document_model=False, + num_chunks=1, + chunk_size=1, + timeout=timeout, + ) + .get("meta", {}) + .get("total_doc", 0) + ) + # Paginate over all entries in the bucket. # TODO: change when a subset of entries needed from DB if "tasks" in suffix: @@ -493,6 +510,11 @@ def _query_resource( bucket_suffix = "build" prefix = f"collections/{db_version}/{suffix}" + # only include prefixes accessible to user + # i.e. append `batch_id=others/core` to `prefix` + if not has_gnome_access: + prefix += "/batch_id=others" + bucket = f"materialsproject-{bucket_suffix}" paginator = self.s3_client.get_paginator("list_objects_v2") pages = paginator.paginate(Bucket=bucket, Prefix=prefix)