@@ -329,20 +329,6 @@ async def all_collections(
329329            if  parsed_sort :
330330                sort  =  parsed_sort 
331331
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- 
346332        # Convert q to a list if it's a string 
347333        q_list  =  None 
348334        if  q  is  not None :
@@ -441,21 +427,71 @@ async def all_collections(
441427            },
442428        ]
443429
444-         if  redis_enable  and  redis :
445-             if  next_token :
446-                 await  save_self_link (redis , next_token , current_url )
430+         async  def  handle_pagination_links (
431+                 current_url : str ,
432+                 token : str ,
433+                 next_token : str , 
434+                 links : list 
435+             ) ->  None :
447436
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+             redis_enable  =  get_bool_env ("REDIS_ENABLE" , default = False )
438+ 
439+             redis  =  None 
440+             if  redis_enable :
441+                 try :
442+                     redis  =  await  connect_redis ()
443+                     logger .info ("Redis connection established successfully" )
444+                 except  Exception  as  e :
445+                     redis  =  None 
446+                     logger .warning (f"Redis connection failed, continuing without Redis: { e }  )
447+ 
448+             if  redis_enable  and  redis :
449+                 if  next_token :
450+                     await  save_self_link (redis , next_token , current_url )
451+                 
452+                 prev_link  =  await  get_prev_link (redis , token )
453+                 if  prev_link :
454+                     links .insert (
455+                         0 ,
456+                         {
457+                             "rel" : "prev" ,
458+                             "type" : "application/json" ,
459+                             "method" : "GET" , 
460+                             "href" : prev_link ,
461+                         },
462+                     )
463+ 
464+         current_url  =  str (request .url )
465+ 
466+         handle_pagination_links (current_url , token , next_token , links )
467+ 
468+         # redis_enable = get_bool_env("REDIS_ENABLE", default=False) 
469+ 
470+         # redis = None 
471+         # if redis_enable: 
472+         #     try: 
473+         #         redis = await connect_redis() 
474+         #         logger.info("Redis connection established successfully") 
475+         #     except Exception as e: 
476+         #         redis = None 
477+         #         logger.warning( 
478+         #             f"Redis connection failed, continuing without Redis: {e}" 
479+         #         ) 
480+         # if redis_enable and redis: 
481+         #     if next_token: 
482+         #         await save_self_link(redis, next_token, current_url) 
483+ 
484+         #     prev_link = await get_prev_link(redis, token) 
485+         #     if prev_link: 
486+         #         links.insert( 
487+         #             0, 
488+         #             { 
489+         #                 "rel": "prev", 
490+         #                 "type": "application/json", 
491+         #                 "method": "GET", 
492+         #                 "href": prev_link, 
493+         #             }, 
494+         #         ) 
459495
460496        if  next_token :
461497            next_link  =  PagingLinks (next = next_token , request = request ).link_next ()
0 commit comments