@@ -24,26 +24,18 @@ def load_json_processing_file():
2424
2525@app .route ("/baseline11" , method = ["GET" , "POST" ])
2626def baseline_test (req , resp ):
27- if req .method == "GET" :
28- result = 0
29- for q_val in req .query .values ():
30- try :
31- result += int (q_val )
32- except ValueError :
33- pass
34- return resp .plain (str (result ))
35- else :
36- result = 0
37- for q_val in req .query .values ():
38- try :
39- result += int (q_val )
40- except ValueError :
41- pass
27+ result = 0
28+ for q_val in req .query .values ():
29+ try :
30+ result += int (q_val )
31+ except ValueError :
32+ pass
33+ if req .method == "POST" :
4234 try :
4335 result += int (req .text )
4436 except ValueError :
4537 pass
46- return resp .plain (str (result ))
38+ return resp .plain (str (result ))
4739
4840
4941@app .route ("/pipeline" , method = "GET" )
@@ -66,29 +58,28 @@ def json_test(req, resp):
6658 global JSON_DATASET
6759 count = int (req .params ["count" ])
6860 multiplier = int (req .query ["m" ])
69- result = []
70- for data in JSON_DATASET [: count ]:
71- result . append (
72- {
73- "id " : data ["id " ],
74- "name " : data ["name " ],
75- "category " : data ["category " ],
76- "price " : data ["price " ],
77- "quantity " : data ["quantity " ],
78- "active " : data [ "active" ],
79- "tags " : data ["tags " ],
80- "rating " : {
81- "score" : data [ "rating" ][ "score" ] ,
82- "count " : data ["rating" ][ "count" ] ,
83- },
84- "total" : data [ "price" ] * data [ "quantity" ] * multiplier ,
85- }
86- )
61+ result = [
62+ {
63+ "id" : data [ "id" ],
64+ "name" : data [ "name" ],
65+ "category " : data ["category " ],
66+ "price " : data ["price " ],
67+ "quantity " : data ["quantity " ],
68+ "active " : data ["active " ],
69+ "tags " : data ["tags " ],
70+ "rating " : {
71+ "score " : data ["rating" ][ "score " ],
72+ "count " : data [ "rating" ][ "count" ],
73+ } ,
74+ "total " : data ["price" ] * data [ "quantity" ] * multiplier ,
75+ }
76+ for data in JSON_DATASET [: count ]
77+ ]
78+
8779 return resp .json ({"items" : result , "count" : count })
8880
8981
9082# Websocket in slime are event driven
91- # echo back based on the message type
9283@app .websocket ("/ws" )
9384def websocket_test (req , resp ):
9485 def echo_me (msg ):
@@ -110,27 +101,33 @@ async def async_db_test(req, resp):
110101 limit = int (req .query ["limit" ])
111102 result = []
112103 data_result = None
113- async with DB_POOL .acquire () as conn :
114- data_result = await conn .fetch (QUERY_STMT , min , max , limit )
115- for data in data_result :
116- result .append (
117- {
118- "id" : data ["id" ],
119- "name" : data ["name" ],
120- "category" : data ["category" ],
121- "price" : data ["price" ],
122- "quantity" : data ["quantity" ],
123- "active" : data ["active" ],
124- "tags" : json .loads (data ["tags" ]),
125- "rating" : {
126- "score" : data ["rating_score" ],
127- "count" : data ["rating_count" ],
128- },
129- }
130- )
104+ data_result = await DB_POOL .fetch (QUERY_STMT , min , max , limit )
105+ result = [
106+ {
107+ "id" : data ["id" ],
108+ "name" : data ["name" ],
109+ "category" : data ["category" ],
110+ "price" : data ["price" ],
111+ "quantity" : data ["quantity" ],
112+ "active" : data ["active" ],
113+ "tags" : json .loads (data ["tags" ]),
114+ "rating" : {
115+ "score" : data ["rating_score" ],
116+ "count" : data ["rating_count" ],
117+ },
118+ }
119+ for data in data_result
120+ ]
131121 return resp .json ({"items" : result , "count" : len (result )})
132122
133123
124+ class NoResetConnection (pg .Connection ):
125+ __slots__ = ()
126+
127+ def get_reset_query (self ):
128+ return ""
129+
130+
134131@app .start ()
135132async def init ():
136133 global DB_POOL
@@ -139,6 +136,7 @@ async def init():
139136 dsn = os .environ ["DATABASE_URL" ],
140137 min_size = 5 ,
141138 max_size = int (os .environ .get ("DATABASE_MAX_CONN" , 256 )),
139+ connection_class = NoResetConnection ,
142140 )
143141 print ("Pool is created successfully" )
144142 except Exception as e :
0 commit comments