Skip to content

Commit

Permalink
Update query to get latest bandwidth txns with limit
Browse files Browse the repository at this point in the history
  • Loading branch information
xoriole committed Dec 1, 2020
1 parent 02c1e82 commit 7ce99c4
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,17 @@ def get_latest_transaction(self, public_key_a: bytes, public_key_b: bytes) -> Ba
return BandwidthTransactionData.from_db(db_obj) if db_obj else None

@db_session
def get_latest_transactions(self, public_key: bytes) -> List[BandwidthTransactionData]:
def get_latest_transactions(self, public_key: bytes, limit: Optional[int] = 100) -> List[BandwidthTransactionData]:
"""
Return the latest transactions of a given public key, or an empty list if no transactions exist.
:param public_key: The public key of the party transferring the bandwidth.
:param limit: The number of transactions to return. (Default: 100)
:return The latest transactions of the specified public key, or an empty list if no transactions exist.
"""
db_objs = self.BandwidthTransaction.select(lambda bt: public_key in (bt.public_key_a, bt.public_key_b))[:]
return [BandwidthTransactionData.from_db(db_obj) for db_obj in db_objs]
db_txs = select(tx for tx in self.BandwidthTransaction
if public_key in (tx.public_key_a, tx.public_key_b))\
.limit(limit)
return [BandwidthTransactionData.from_db(db_txn) for db_txn in db_txs]

@db_session
def get_total_taken(self, public_key: bytes) -> int:
Expand Down

0 comments on commit 7ce99c4

Please sign in to comment.