Skip to content

Commit a98ef4c

Browse files
committed
Don't recreate cursor obj
1 parent 1ccc34c commit a98ef4c

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

async_substrate_interface/utils/cache.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ def _get_table_name(func):
1818
return func.__qualname__.replace(".", "_")
1919

2020

21-
def _create_table(conn, table_name):
22-
c = conn.cursor()
21+
def _create_table(c, conn, table_name):
2322
c.execute(
2423
f"CREATE TABLE IF NOT EXISTS {table_name} (key BLOB PRIMARY KEY, value BLOB, chain TEXT)"
2524
)
@@ -53,9 +52,9 @@ def _insert_into_cache(c, conn, table_name, key, result, chain):
5352

5453
def sql_lru_cache(func, max_size=None):
5554
conn = sqlite3.connect(CACHE_LOCATION)
56-
55+
c = conn.cursor()
5756
table_name = _get_table_name(func)
58-
_create_table(conn, table_name)
57+
_create_table(c, conn, table_name)
5958

6059
@functools.lru_cache(maxsize=max_size)
6160
def inner(self, *args, **kwargs):
@@ -78,8 +77,9 @@ def inner(self, *args, **kwargs):
7877

7978
def async_sql_lru_cache(func, max_size=None):
8079
conn = sqlite3.connect(CACHE_LOCATION)
80+
c = conn.cursor()
8181
table_name = _get_table_name(func)
82-
_create_table(conn, table_name)
82+
_create_table(c, conn, table_name)
8383

8484
@a.lru_cache(maxsize=max_size)
8585
async def inner(self, *args, **kwargs):

0 commit comments

Comments
 (0)