@@ -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)
@@ -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