diff --git a/lib/pending_transaction_repo.rb b/lib/pending_transaction_repo.rb index 82c24995a4ddb6ec7ef7c9c3d00db5561d5032b1..71e8fdc28d8fd2dc7f66c7579a4d739e8cb117bf 100644 --- a/lib/pending_transaction_repo.rb +++ b/lib/pending_transaction_repo.rb @@ -136,7 +136,7 @@ class PendingTransactionRepo end end - def filter(txids_and_customer_ids) + def run_filters(txids_and_customer_ids) @filters ||= [ IgnoredTransactionFilter.new(redis, @ignored_key), WrongCustomerFilter.new(redis, @customer_address_template), @@ -150,6 +150,23 @@ class PendingTransactionRepo end end + # run_filters removes the ones we don't care about from the list, but that + # list is just in memory. The rest of this removes it from the redis queue + # so we're not just skipping over these things every time in the list but + # otherwise leaving them there. + def filter(txids_and_customer_ids) + passed = run_filters(txids_and_customer_ids) + + unless txids_and_customer_ids.length == passed.length + redis.hdel( + @key, + (txids_and_customer_ids - passed).map(&:first) + ) + end + + passed + end + def build_transaction(txid) tx_hash, address = txid.split("/", 2) txn = electrum.gettransaction(tx_hash) diff --git a/test/test_pending_transaction_repo.rb b/test/test_pending_transaction_repo.rb index c15bb80d904ce455a2ce72c956706e2d7ff00210..908dc515fa9a366a75907972ed8190286fe9da51 100644 --- a/test/test_pending_transaction_repo.rb +++ b/test/test_pending_transaction_repo.rb @@ -398,6 +398,11 @@ class TestPendingTransactionRepo < Minitest::Test [["one/a", "1234"], ["two/a", "1234"], ["three/a", "1234"]], ["key"] ) + repo.redis.expect( + :hdel, + 2, + ["key", ["two/a", "three/a"]] + ) repo.electrum.expect( :gettransaction, FakeElectrumTransaction.new("one", 6, 0.5), @@ -437,6 +442,11 @@ class TestPendingTransactionRepo < Minitest::Test [["one/a", "1234"], ["two/a", "1234"], ["three/a", "1234"]], ["key"] ) + repo.redis.expect( + :hdel, + 3, + ["key", ["one/a", "two/a", "three/a"]] + ) v = repo.map { |pending, _customer_id| pending.tx_hash