From c8553abb4146e2b290109753608d71bd5074f0ee Mon Sep 17 00:00:00 2001 From: Ryan Henderson Date: Mon, 14 Nov 2016 10:03:59 +0100 Subject: [PATCH] add backlog count (#806) --- bigchaindb/db/backends/rethinkdb.py | 11 +++++++++++ tests/db/test_bigchain_api.py | 9 +++++++++ 2 files changed, 20 insertions(+) diff --git a/bigchaindb/db/backends/rethinkdb.py b/bigchaindb/db/backends/rethinkdb.py index 5b73cce6ce..aeb6857207 100644 --- a/bigchaindb/db/backends/rethinkdb.py +++ b/bigchaindb/db/backends/rethinkdb.py @@ -293,6 +293,17 @@ def count_blocks(self): r.table('bigchain', read_mode=self.read_mode) .count()) + def count_backlog(self): + """Count the number of transactions in the backlog table. + + Returns: + The number of transactions in the backlog. + """ + + return self.connection.run( + r.table('backlog', read_mode=self.read_mode) + .count()) + def write_vote(self, vote): """Write a vote to the votes table. diff --git a/tests/db/test_bigchain_api.py b/tests/db/test_bigchain_api.py index 314286c63c..6a7880e959 100644 --- a/tests/db/test_bigchain_api.py +++ b/tests/db/test_bigchain_api.py @@ -592,6 +592,15 @@ def test_non_create_input_not_found(self, b, user_vk): with pytest.raises(TransactionDoesNotExist) as excinfo: tx.validate(Bigchain()) + def test_count_backlog(self, b, user_vk): + from bigchaindb.models import Transaction + + for _ in range(4): + tx = Transaction.create([b.me], [user_vk]).sign([b.me_private]) + b.write_transaction(tx) + + assert b.backend.count_backlog() == 4 + class TestTransactionValidation(object): def test_create_operation_with_inputs(self, b, user_vk, create_tx):