From 81b9be807b4a6b83cfa2a0c258554347ece97c35 Mon Sep 17 00:00:00 2001 From: ThomasV Date: Mon, 25 Jun 2012 18:46:13 +0400 Subject: [PATCH] avoid unnecessary sql request --- backends/abe/__init__.py | 16 +++++++++++----- 1 files changed, 11 insertions(+), 5 deletions(-) diff --git a/backends/abe/__init__.py b/backends/abe/__init__.py index 3ba9b23..7584fd5 100644 --- a/backends/abe/__init__.py +++ b/backends/abe/__init__.py @@ -34,6 +34,14 @@ class AbeStore(Datastore_class): self.address_queue = Queue() self.dblock = thread.allocate_lock() + self.last_tx_id = 0 + + + def import_tx(self, tx, is_coinbase): + tx_id = super(AbeStore, self).import_tx(tx, is_coinbase) + self.last_tx_id = tx_id + return tx_id + @@ -268,9 +276,6 @@ class AbeStore(Datastore_class): rows += self.get_address_out_rows_memorypool( dbhash ) address_has_mempool = False - current_id = self.safe_sql("""SELECT last_value FROM tx_seq""") - current_id = current_id[0][0] - for row in rows: is_in, tx_hash, tx_id, pos, value = row tx_hash = self.hashout_hex(tx_hash) @@ -280,8 +285,9 @@ class AbeStore(Datastore_class): # this means that pending transactions were added to the db, even if they are not returned by getmemorypool address_has_mempool = True - # fixme: we need to detect transactions that became invalid - if current_id - tx_id > 10000: + # discard transactions that are too old + if self.last_tx_id - tx_id > 10000: + print "discarding tx id", tx_id continue -- 1.7.1