forked from LBRYCommunity/lbry-sdk
fix looping over same things in _transaction_io
This commit is contained in:
parent
2a7911c7d6
commit
37d46ecdb2
1 changed files with 10 additions and 8 deletions
|
@ -416,7 +416,7 @@ class Database(SQLiteMixin):
|
||||||
'height': tx.height, 'position': tx.position, 'is_verified': tx.is_verified
|
'height': tx.height, 'position': tx.position, 'is_verified': tx.is_verified
|
||||||
}, 'txid = ?', (tx.id,)))
|
}, 'txid = ?', (tx.id,)))
|
||||||
|
|
||||||
def _transaction_io(self, conn: sqlite3.Connection, tx: Transaction, address, txhash, history):
|
def _transaction_io(self, conn: sqlite3.Connection, tx: Transaction, address, txhash):
|
||||||
conn.execute(*self._insert_sql('tx', self.tx_to_row(tx), replace=True))
|
conn.execute(*self._insert_sql('tx', self.tx_to_row(tx), replace=True))
|
||||||
|
|
||||||
for txo in tx.outputs:
|
for txo in tx.outputs:
|
||||||
|
@ -438,18 +438,20 @@ class Database(SQLiteMixin):
|
||||||
'address': address,
|
'address': address,
|
||||||
}, ignore_duplicate=True)).fetchall()
|
}, ignore_duplicate=True)).fetchall()
|
||||||
|
|
||||||
conn.execute(
|
|
||||||
"UPDATE pubkey_address SET history = ?, used_times = ? WHERE address = ?",
|
|
||||||
(history, history.count(':') // 2, address)
|
|
||||||
)
|
|
||||||
|
|
||||||
def save_transaction_io(self, tx: Transaction, address, txhash, history):
|
def save_transaction_io(self, tx: Transaction, address, txhash, history):
|
||||||
return self.db.run(self._transaction_io, tx, address, txhash, history)
|
return self.save_transaction_io_batch([tx], address, txhash, history)
|
||||||
|
|
||||||
def save_transaction_io_batch(self, txs: Iterable[Transaction], address, txhash, history):
|
def save_transaction_io_batch(self, txs: Iterable[Transaction], address, txhash, history):
|
||||||
|
history_count = history.count(':') // 2
|
||||||
|
|
||||||
def __many(conn):
|
def __many(conn):
|
||||||
for tx in txs:
|
for tx in txs:
|
||||||
self._transaction_io(conn, tx, address, txhash, history)
|
self._transaction_io(conn, tx, address, txhash)
|
||||||
|
conn.execute(
|
||||||
|
"UPDATE pubkey_address SET history = ?, used_times = ? WHERE address = ?",
|
||||||
|
(history, history_count, address)
|
||||||
|
).fetchall()
|
||||||
|
|
||||||
return self.db.run(__many)
|
return self.db.run(__many)
|
||||||
|
|
||||||
async def reserve_outputs(self, txos, is_reserved=True):
|
async def reserve_outputs(self, txos, is_reserved=True):
|
||||||
|
|
Loading…
Reference in a new issue