Skip to content

Commit 29c8782

Browse files
committed
refactor: move storing of download info to core
1 parent 746bd6e commit 29c8782

File tree

4 files changed

+18
-24
lines changed

4 files changed

+18
-24
lines changed

eodag/api/core.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ def __init__(
194194
os.path.join(self.conf_dir, "shp"),
195195
)
196196
self.set_locations_conf(locations_conf_path)
197+
self.download_info = {}
197198

198199
def get_version(self) -> str:
199200
"""Get eodag package version"""
@@ -1741,6 +1742,17 @@ def _do_search(
17411742
)
17421743
eo_product.register_downloader(download_plugin, auth_plugin)
17431744

1745+
product_key = f"{eo_product.product_type}_{search_plugin.provider}_{eo_product.properties['id']}"
1746+
self.download_info[product_key] = {}
1747+
if "orderLink" in eo_product.properties:
1748+
self.download_info[product_key][
1749+
"orderLink"
1750+
] = eo_product.properties["orderLink"]
1751+
if "downloadLink" in eo_product.properties:
1752+
self.download_info[product_key][
1753+
"downloadLink"
1754+
] = eo_product.properties["downloadLink"]
1755+
17441756
results.extend(res)
17451757
total_results = None if nb_res is None else total_results + nb_res
17461758
if count:

eodag/plugins/search/data_request_search.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ def _create_data_request(
260260
request_job.raise_for_status()
261261
except requests.RequestException as e:
262262
raise RequestError(
263-
f"search job for product_type {product_type} could not be created: {str(e)}, {request_job.text}"
263+
f"search job for product_type {product_type} could not be created: {str(e)}"
264264
)
265265
else:
266266
logger.info("search job for product_type %s created", product_type)
@@ -363,13 +363,7 @@ def _convert_result_data(
363363
p.properties["orderLink"] = p.properties["orderLink"].replace(
364364
"requestJobId", str(data_request_id)
365365
)
366-
# store download information to retrieve it later to avoid search_by_id
367-
self.download_info[p.properties["id"]] = {
368-
"requestJobId": data_request_id,
369-
"orderLink": p.properties["orderLink"],
370-
"downloadLink": p.properties["downloadLink"],
371-
"provider": self.provider,
372-
}
366+
373367
return products, total_items_nb
374368

375369
def _check_uses_custom_filters(self, product_type: str) -> bool:

eodag/plugins/search/qssearch.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -732,17 +732,6 @@ def normalize_results(
732732
getattr(self.config, "product_type_config", {}), **product.properties
733733
)
734734
products.append(product)
735-
self.download_info[product.properties["id"]] = {
736-
"provider": self.provider,
737-
}
738-
if "downloadLink" in product.properties:
739-
self.download_info[product.properties["id"]][
740-
"downloadLink"
741-
] = product.properties["downloadLink"]
742-
if "orderLink" in product.properties:
743-
self.download_info[product.properties["id"]][
744-
"orderLink"
745-
] = product.properties["orderLink"]
746735

747736
return products
748737

eodag/rest/utils.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -712,15 +712,14 @@ def download_stac_item_by_id_stream(
712712
provider_product_type_config = search_plugin.config.products.get(
713713
product_type, {}
714714
) or search_plugin.config.products.get(GENERIC_PRODUCT_TYPE, {})
715+
715716
if "." in item_id:
716717
id_without_ext = item_id.split(".")[0]
717718
else:
718719
id_without_ext = item_id
719-
if (
720-
getattr(search_plugin, "download_info", None)
721-
and id_without_ext in search_plugin.download_info
722-
):
723-
product_data = search_plugin.download_info[id_without_ext]
720+
product_key = f"{product_type}_{provider}_{id_without_ext}"
721+
if product_key in eodag_api.download_info:
722+
product_data = eodag_api.download_info[product_key]
724723
properties = {
725724
"id": id_without_ext,
726725
"geometry": "-180 -90 180 90",

0 commit comments

Comments
 (0)