Skip to content

Commit bcd81f1

Browse files
authored
fix(collections): make pagination optional (#35)
if offset-pagination is disabled: - do not limit the list of collections returned - do not generate the pagination links
1 parent 4a126b9 commit bcd81f1

2 files changed

Lines changed: 18 additions & 15 deletions

File tree

stac_fastapi/eodag/app.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ async def lifespan(app: FastAPI) -> AsyncGenerator[None, None]:
190190
search_post_model = create_post_request_model(search_extensions)
191191
search_get_model = create_get_request_model(search_extensions)
192192

193-
194193
collections_model = create_request_model(
195194
"CollectionsRequest",
196195
base_model=EmptyRequest,

stac_fastapi/eodag/core.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ async def all_collections(
244244

245245
next_link: Optional[dict[str, Any]] = None
246246
prev_link: Optional[dict[str, Any]] = None
247-
first_link: dict[str, Any] = {"body": {"limit": limit, "offset": 0}}
247+
first_link: Optional[dict[str, Any]] = None
248248

249249
# get provider filter
250250
provider = None
@@ -285,19 +285,8 @@ async def all_collections(
285285
).intersection(bbox_geom)
286286
]
287287

288-
limit = limit if limit is not None else 10
289-
offset = offset if offset is not None else 0
290-
291-
paged_collections = collections[offset : offset + limit]
292-
293288
total = len(collections)
294289

295-
if offset + limit < total:
296-
next_link = {"body": {"limit": limit, "offset": offset + limit}}
297-
298-
if offset > 0:
299-
prev_link = {"body": {"limit": limit, "offset": max(0, offset - limit)}}
300-
301290
links = [
302291
{
303292
"rel": Relations.root,
@@ -306,6 +295,21 @@ async def all_collections(
306295
"title": get_settings().stac_fastapi_title,
307296
},
308297
]
298+
299+
if self.extension_is_enabled("OffsetPaginationExtension"):
300+
limit = limit if limit is not None else 10
301+
offset = offset if offset is not None else 0
302+
303+
collections = collections[offset : offset + limit]
304+
305+
if offset + limit < total:
306+
next_link = {"body": {"limit": limit, "offset": offset + limit}}
307+
308+
if offset > 0:
309+
prev_link = {"body": {"limit": limit, "offset": max(0, offset - limit)}}
310+
311+
first_link = {"body": {"limit": limit, "offset": 0}}
312+
309313
extension_names = [type(ext).__name__ for ext in self.extensions]
310314

311315
paging_links = CollectionSearchPagingLinks(
@@ -315,10 +319,10 @@ async def all_collections(
315319
links.extend(paging_links)
316320

317321
return Collections(
318-
collections=paged_collections or [],
322+
collections=collections,
319323
links=links,
320324
numberMatched=total,
321-
numberReturned=len(paged_collections),
325+
numberReturned=len(collections),
322326
)
323327

324328
async def get_collection(self, collection_id: str, request: Request, **kwargs: Any) -> Collection:

0 commit comments

Comments
 (0)