@@ -81,23 +81,25 @@ def get_list(*args, convert_to_dict=None, **kwargs):
8181 return fastapi .Response (content = str (q_count ), media_type = "application/json" )
8282 else :
8383 debug_print (f'Getting results for query: { q } ' )
84- if not hasattr (q , '__q_limit' ) or not q .__q_limit or q .__q_limit > QUERY_PAGE_SIZE :
85- debug_print (f'adding yield_per({ QUERY_PAGE_SIZE } ) to query' )
86- q = q .yield_per (QUERY_PAGE_SIZE )
87- q_iterator = (obj for obj in q )
88- first_items = list (itertools .islice (q_iterator , QUERY_PAGE_SIZE + 1 ))
89- if len (first_items ) <= QUERY_PAGE_SIZE :
90- debug_print (f'got { len (first_items )} items - returning without streaming' )
91- data = [post_process_response_obj (obj , convert_to_dict ) for obj in first_items ]
92- session .close ()
93- return data
94- else :
95- raise Exception ("streaming responses disabled due to abuse, if you need this feature please contact us" )
96- debug_print (f'got { len (first_items )} items - returning using streaming' )
97- return fastapi .responses .StreamingResponse (
98- streaming_response_iterator (session , first_items , q_iterator , convert_to_dict ),
99- media_type = "application/json"
100- )
84+ data = [post_process_response_obj (obj , convert_to_dict ) for obj in q ]
85+ session .close ()
86+ return data
87+ # if not hasattr(q, '__q_limit') or not q.__q_limit or q.__q_limit > QUERY_PAGE_SIZE:
88+ # debug_print(f'adding yield_per({QUERY_PAGE_SIZE}) to query')
89+ # q = q.yield_per(QUERY_PAGE_SIZE)
90+ # q_iterator = (obj for obj in q)
91+ # first_items = list(itertools.islice(q_iterator, QUERY_PAGE_SIZE + 1))
92+ # if len(first_items) <= QUERY_PAGE_SIZE:
93+ # debug_print(f'got {len(first_items)} items - returning without streaming')
94+ # data = [post_process_response_obj(obj, convert_to_dict) for obj in first_items]
95+ # session.close()
96+ # return data
97+ # else:
98+ # debug_print(f'got {len(first_items)} items - returning using streaming')
99+ # return fastapi.responses.StreamingResponse(
100+ # streaming_response_iterator(session, first_items, q_iterator, convert_to_dict),
101+ # media_type="application/json"
102+ # )
101103 except :
102104 session .close ()
103105 raise
@@ -166,6 +168,7 @@ def get_list_query(session, db_model, limit, offset, filters=None, default_limit
166168 limit = default_limit
167169 if limit :
168170 limit = int (limit )
171+ assert 0 < limit <= 1000 , "due to abuse, maximum limit per request is 1000 items, contact us if you need more"
169172 if filters is None :
170173 filters = []
171174 if get_base_session_query_callback is None :
0 commit comments