Skip to content

Commit 3c18f02

Browse files
authored
[Python] Review Granian db pools (#9989)
1 parent c92de00 commit 3c18f02

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

frameworks/Python/granian/app_asgi.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import jinja2
1010
import orjson
1111

12-
PG_POOL_SIZE = 2
12+
PG_POOL_SIZE = 4
1313

1414

1515
class NoResetConnection(asyncpg.Connection):
@@ -109,8 +109,7 @@ async def route_queries(scope, receive, send):
109109
worlds = []
110110

111111
async with pool.acquire() as connection:
112-
statement = await connection.prepare(SQL_SELECT)
113-
rows = await statement.fetchmany([(v,) for v in row_ids])
112+
rows = await connection.fetchmany(SQL_SELECT, [(v,) for v in row_ids])
114113

115114
worlds = [{'id': row_id, 'randomNumber': number[0]} for row_id, number in zip(row_ids, rows)]
116115
await send(JSON_RESPONSE)
@@ -145,8 +144,7 @@ async def route_updates(scope, receive, send):
145144
worlds = [{'id': row_id, 'randomNumber': number} for row_id, number in updates]
146145

147146
async with pool.acquire() as connection:
148-
statement = await connection.prepare(SQL_SELECT)
149-
await statement.executemany([(i[0],) for i in updates])
147+
await connection.executemany(SQL_SELECT, [(i[0],) for i in updates])
150148
await connection.executemany(SQL_UPDATE, updates)
151149

152150
await send(JSON_RESPONSE)

frameworks/Python/granian/app_rsgi.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import jinja2
1010
import orjson
1111

12-
PG_POOL_SIZE = 2
12+
PG_POOL_SIZE = 4
1313

1414

1515
class NoResetConnection(asyncpg.Connection):
@@ -88,8 +88,7 @@ async def route_queries(scope, proto):
8888
worlds = []
8989

9090
async with pool.acquire() as connection:
91-
statement = await connection.prepare(SQL_SELECT)
92-
rows = await statement.fetchmany([(v,) for v in row_ids])
91+
rows = await connection.fetchmany(SQL_SELECT, [(v,) for v in row_ids])
9392

9493
worlds = [{'id': row_id, 'randomNumber': number[0]} for row_id, number in zip(row_ids, rows)]
9594
proto.response_bytes(
@@ -122,8 +121,7 @@ async def route_updates(scope, proto):
122121
worlds = [{'id': row_id, 'randomNumber': number} for row_id, number in updates]
123122

124123
async with pool.acquire() as connection:
125-
statement = await connection.prepare(SQL_SELECT)
126-
await statement.executemany([(i[0],) for i in updates])
124+
await connection.executemany(SQL_SELECT, [(i[0],) for i in updates])
127125
await connection.executemany(SQL_UPDATE, updates)
128126

129127
proto.response_bytes(

0 commit comments

Comments
 (0)