diff options
author | Erik Johnston <erik@matrix.org> | 2017-03-23 17:53:49 +0000 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2017-03-23 17:53:49 +0000 |
commit | 00957d1aa4b01a199ab2c3abf30032a0ca0b1e12 (patch) | |
tree | 79f6e968f784c6d4e05cda9c298d5a32fbc88291 /synapse/storage/_base.py | |
parent | Merge pull request #2005 from kfatehi/docs/readme (diff) | |
download | synapse-00957d1aa4b01a199ab2c3abf30032a0ca0b1e12.tar.xz |
User Cursor.__iter__ instead of fetchall
This prevents unnecessary construction of lists
Diffstat (limited to 'synapse/storage/_base.py')
-rw-r--r-- | synapse/storage/_base.py | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/synapse/storage/_base.py b/synapse/storage/_base.py index 13b106bba1..93d9ed5d62 100644 --- a/synapse/storage/_base.py +++ b/synapse/storage/_base.py @@ -73,6 +73,9 @@ class LoggingTransaction(object): def __setattr__(self, name, value): setattr(self.txn, name, value) + def __iter__(self): + return self.txn.__iter__() + def execute(self, sql, *args): self._do_execute(self.txn.execute, sql, *args) @@ -357,7 +360,7 @@ class SQLBaseStore(object): """ col_headers = list(intern(column[0]) for column in cursor.description) results = list( - dict(zip(col_headers, row)) for row in cursor.fetchall() + dict(zip(col_headers, row)) for row in cursor ) return results @@ -579,7 +582,7 @@ class SQLBaseStore(object): txn.execute(sql, keyvalues.values()) - return [r[0] for r in txn.fetchall()] + return [r[0] for r in txn] def _simple_select_onecol(self, table, keyvalues, retcol, desc="_simple_select_onecol"): @@ -901,14 +904,14 @@ class SQLBaseStore(object): txn = db_conn.cursor() txn.execute(sql, (int(max_value),)) - rows = txn.fetchall() - txn.close() cache = { row[0]: int(row[1]) - for row in rows + for row in txn } + txn.close() + if cache: min_val = min(cache.values()) else: |