|  | 
| 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 handle_pagination_links | 
| 28 | 28 | from stac_fastapi.core.serializers import CollectionSerializer, ItemSerializer | 
| 29 | 29 | from stac_fastapi.core.session import Session | 
| 30 |  | -from stac_fastapi.core.utilities import filter_fields, get_bool_env | 
|  | 30 | +from stac_fastapi.core.utilities import filter_fields | 
| 31 | 31 | from stac_fastapi.extensions.core.transaction import AsyncBaseTransactionsClient | 
| 32 | 32 | from stac_fastapi.extensions.core.transaction.request import ( | 
| 33 | 33 |     PartialCollection, | 
| @@ -329,20 +329,6 @@ async def all_collections( | 
| 329 | 329 |             if parsed_sort: | 
| 330 | 330 |                 sort = parsed_sort | 
| 331 | 331 | 
 | 
| 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 | 332 |         # Convert q to a list if it's a string | 
| 347 | 333 |         q_list = None | 
| 348 | 334 |         if q is not None: | 
| @@ -441,21 +427,37 @@ async def all_collections( | 
| 441 | 427 |             }, | 
| 442 | 428 |         ] | 
| 443 | 429 | 
 | 
| 444 |  | -        if redis_enable and redis: | 
| 445 |  | -            if next_token: | 
| 446 |  | -                await save_self_link(redis, next_token, current_url) | 
|  | 430 | +        current_url = str(request.url) | 
| 447 | 431 | 
 | 
| 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 |  | -                ) | 
|  | 432 | +        await handle_pagination_links(current_url, token, next_token, links) | 
|  | 433 | + | 
|  | 434 | +        # redis_enable = get_bool_env("REDIS_ENABLE", default=False) | 
|  | 435 | + | 
|  | 436 | +        # redis = None | 
|  | 437 | +        # if redis_enable: | 
|  | 438 | +        #     try: | 
|  | 439 | +        #         redis = await connect_redis() | 
|  | 440 | +        #         logger.info("Redis connection established successfully") | 
|  | 441 | +        #     except Exception as e: | 
|  | 442 | +        #         redis = None | 
|  | 443 | +        #         logger.warning( | 
|  | 444 | +        #             f"Redis connection failed, continuing without Redis: {e}" | 
|  | 445 | +        #         ) | 
|  | 446 | +        # if redis_enable and redis: | 
|  | 447 | +        #     if next_token: | 
|  | 448 | +        #         await save_self_link(redis, next_token, current_url) | 
|  | 449 | + | 
|  | 450 | +        #     prev_link = await get_prev_link(redis, token) | 
|  | 451 | +        #     if prev_link: | 
|  | 452 | +        #         links.insert( | 
|  | 453 | +        #             0, | 
|  | 454 | +        #             { | 
|  | 455 | +        #                 "rel": "prev", | 
|  | 456 | +        #                 "type": "application/json", | 
|  | 457 | +        #                 "method": "GET", | 
|  | 458 | +        #                 "href": prev_link, | 
|  | 459 | +        #             }, | 
|  | 460 | +        #         ) | 
| 459 | 461 | 
 | 
| 460 | 462 |         if next_token: | 
| 461 | 463 |             next_link = PagingLinks(next=next_token, request=request).link_next() | 
| @@ -775,7 +777,7 @@ async def post_search( | 
| 775 | 777 |             HTTPException: If there is an error with the cql2_json filter. | 
| 776 | 778 |         """ | 
| 777 | 779 |         base_url = str(request.base_url) | 
| 778 |  | -        redis_enable = get_bool_env("REDIS_ENABLE", default=False) | 
|  | 780 | +        # redis_enable = get_bool_env("REDIS_ENABLE", default=False) | 
| 779 | 781 | 
 | 
| 780 | 782 |         search = self.database.make_search() | 
| 781 | 783 | 
 | 
| @@ -901,29 +903,33 @@ async def post_search( | 
| 901 | 903 |                 ) | 
| 902 | 904 |         links.extend(collection_links) | 
| 903 | 905 | 
 | 
| 904 |  | -        if redis_enable: | 
| 905 |  | -            redis = None | 
| 906 |  | -            try: | 
| 907 |  | -                redis = await connect_redis() | 
| 908 |  | -                logger.info("Redis connection established successfully") | 
| 909 |  | -                self_link = str(request.url) | 
| 910 |  | -                await save_self_link(redis, next_token, self_link) | 
| 911 |  | - | 
| 912 |  | -                prev_link = await get_prev_link(redis, token_param) | 
| 913 |  | -                if prev_link: | 
| 914 |  | -                    links.insert( | 
| 915 |  | -                        0, | 
| 916 |  | -                        { | 
| 917 |  | -                            "rel": "prev", | 
| 918 |  | -                            "type": "application/json", | 
| 919 |  | -                            "method": "GET", | 
| 920 |  | -                            "href": prev_link, | 
| 921 |  | -                        }, | 
| 922 |  | -                    ) | 
| 923 |  | -            except Exception as e: | 
| 924 |  | -                logger.warning( | 
| 925 |  | -                    f"Redis connection failed, continuing without Redis: {e}" | 
| 926 |  | -                ) | 
|  | 906 | +        current_url = str(request.url) | 
|  | 907 | + | 
|  | 908 | +        await handle_pagination_links(current_url, token_param, next_token, links) | 
|  | 909 | + | 
|  | 910 | +        # if redis_enable: | 
|  | 911 | +        #     redis = None | 
|  | 912 | +        #     try: | 
|  | 913 | +        #         redis = await connect_redis() | 
|  | 914 | +        #         logger.info("Redis connection established successfully") | 
|  | 915 | +        #         self_link = str(request.url) | 
|  | 916 | +        #         await save_self_link(redis, next_token, self_link) | 
|  | 917 | + | 
|  | 918 | +        #         prev_link = await get_prev_link(redis, token_param) | 
|  | 919 | +        #         if prev_link: | 
|  | 920 | +        #             links.insert( | 
|  | 921 | +        #                 0, | 
|  | 922 | +        #                 { | 
|  | 923 | +        #                     "rel": "prev", | 
|  | 924 | +        #                     "type": "application/json", | 
|  | 925 | +        #                     "method": "GET", | 
|  | 926 | +        #                     "href": prev_link, | 
|  | 927 | +        #                 }, | 
|  | 928 | +        #             ) | 
|  | 929 | +        #     except Exception as e: | 
|  | 930 | +        #         logger.warning( | 
|  | 931 | +        #             f"Redis connection failed, continuing without Redis: {e}" | 
|  | 932 | +        #         ) | 
| 927 | 933 | 
 | 
| 928 | 934 |         return stac_types.ItemCollection( | 
| 929 | 935 |             type="FeatureCollection", | 
|  | 
0 commit comments