|
24 | 24 | from stac_fastapi.core.base_settings import ApiBaseSettings |
25 | 25 | from stac_fastapi.core.datetime_utils import format_datetime_range |
26 | 26 | from stac_fastapi.core.models.links import PagingLinks |
27 | | -from stac_fastapi.core.redis_utils import connect_redis, get_prev_link, save_self_link |
| 27 | +from stac_fastapi.core.redis_utils import ( |
| 28 | + connect_redis, |
| 29 | + get_prev_link, |
| 30 | + handle_pagination_links, |
| 31 | + save_self_link, |
| 32 | +) |
28 | 33 | from stac_fastapi.core.serializers import CollectionSerializer, ItemSerializer |
29 | 34 | from stac_fastapi.core.session import Session |
30 | 35 | from stac_fastapi.core.utilities import filter_fields, get_bool_env |
@@ -329,20 +334,6 @@ async def all_collections( |
329 | 334 | if parsed_sort: |
330 | 335 | sort = parsed_sort |
331 | 336 |
|
332 | | - current_url = str(request.url) |
333 | | - redis_enable = get_bool_env("REDIS_ENABLE", default=False) |
334 | | - |
335 | | - redis = None |
336 | | - if redis_enable: |
337 | | - try: |
338 | | - redis = await connect_redis() |
339 | | - logger.info("Redis connection established successfully") |
340 | | - except Exception as e: |
341 | | - redis = None |
342 | | - logger.warning( |
343 | | - f"Redis connection failed, continuing without Redis: {e}" |
344 | | - ) |
345 | | - |
346 | 337 | # Convert q to a list if it's a string |
347 | 338 | q_list = None |
348 | 339 | if q is not None: |
@@ -441,21 +432,37 @@ async def all_collections( |
441 | 432 | }, |
442 | 433 | ] |
443 | 434 |
|
444 | | - if redis_enable and redis: |
445 | | - if next_token: |
446 | | - await save_self_link(redis, next_token, current_url) |
| 435 | + current_url = str(request.url) |
447 | 436 |
|
448 | | - prev_link = await get_prev_link(redis, token) |
449 | | - if prev_link: |
450 | | - links.insert( |
451 | | - 0, |
452 | | - { |
453 | | - "rel": "prev", |
454 | | - "type": "application/json", |
455 | | - "method": "GET", |
456 | | - "href": prev_link, |
457 | | - }, |
458 | | - ) |
| 437 | + await handle_pagination_links(current_url, token, next_token, links) |
| 438 | + |
| 439 | + # redis_enable = get_bool_env("REDIS_ENABLE", default=False) |
| 440 | + |
| 441 | + # redis = None |
| 442 | + # if redis_enable: |
| 443 | + # try: |
| 444 | + # redis = await connect_redis() |
| 445 | + # logger.info("Redis connection established successfully") |
| 446 | + # except Exception as e: |
| 447 | + # redis = None |
| 448 | + # logger.warning( |
| 449 | + # f"Redis connection failed, continuing without Redis: {e}" |
| 450 | + # ) |
| 451 | + # if redis_enable and redis: |
| 452 | + # if next_token: |
| 453 | + # await save_self_link(redis, next_token, current_url) |
| 454 | + |
| 455 | + # prev_link = await get_prev_link(redis, token) |
| 456 | + # if prev_link: |
| 457 | + # links.insert( |
| 458 | + # 0, |
| 459 | + # { |
| 460 | + # "rel": "prev", |
| 461 | + # "type": "application/json", |
| 462 | + # "method": "GET", |
| 463 | + # "href": prev_link, |
| 464 | + # }, |
| 465 | + # ) |
459 | 466 |
|
460 | 467 | if next_token: |
461 | 468 | next_link = PagingLinks(next=next_token, request=request).link_next() |
|
0 commit comments