mirror of
https://github.com/XRPLF/clio.git
synced 2025-12-06 17:27:58 +00:00
add cursor and limit to book offers
This commit is contained in:
@@ -51,11 +51,11 @@ public:
|
||||
std::uint32_t ledgerSequence,
|
||||
std::uint32_t limit) const = 0;
|
||||
|
||||
// TODO needs to take in a limit, and return a cursor
|
||||
virtual std::vector<LedgerObject>
|
||||
virtual std::pair<std::vector<LedgerObject>, std::optional<ripple::uint256>>
|
||||
fetchBookOffers(
|
||||
ripple::uint256 const& book,
|
||||
uint32_t ledgerSequence,
|
||||
std::uint32_t limit,
|
||||
std::optional<ripple::uint256> const& cursor = {}) const = 0;
|
||||
|
||||
virtual std::vector<TransactionAndMetadata>
|
||||
@@ -66,12 +66,12 @@ public:
|
||||
std::vector<ripple::uint256> const& keys,
|
||||
uint32_t sequence) const = 0;
|
||||
|
||||
// TODO needs to take in a limit
|
||||
virtual std::pair<
|
||||
std::vector<TransactionAndMetadata>,
|
||||
std::optional<AccountTransactionsCursor>>
|
||||
fetchAccountTransactions(
|
||||
ripple::AccountID const& account,
|
||||
std::uint32_t limit,
|
||||
std::optional<AccountTransactionsCursor> const& cursor = {}) const = 0;
|
||||
|
||||
// write methods
|
||||
|
||||
@@ -279,10 +279,11 @@ PostgresBackend::fetchLedgerPage(
|
||||
return {};
|
||||
}
|
||||
|
||||
std::vector<LedgerObject>
|
||||
std::pair<std::vector<LedgerObject>, std::optional<ripple::uint256>>
|
||||
PostgresBackend::fetchBookOffers(
|
||||
ripple::uint256 const& book,
|
||||
uint32_t ledgerSequence,
|
||||
std::uint32_t limit,
|
||||
std::optional<ripple::uint256> const& cursor) const
|
||||
{
|
||||
PgQuery pgQuery(pgPool_);
|
||||
@@ -294,7 +295,8 @@ PostgresBackend::fetchBookOffers(
|
||||
if (cursor)
|
||||
sql << " AND key > \'" << ripple::strHex(*cursor) << "\'";
|
||||
sql << " ORDER BY key DESC, sequence DESC)"
|
||||
<< " sub WHERE NOT deleted";
|
||||
<< " sub WHERE NOT deleted"
|
||||
<< " LIMIT " << std::to_string(limit);
|
||||
auto res = pgQuery(sql.str().data());
|
||||
if (size_t numRows = checkResult(res, 1))
|
||||
{
|
||||
@@ -316,9 +318,9 @@ PostgresBackend::fetchBookOffers(
|
||||
[](auto& blob, auto& key) {
|
||||
return LedgerObject{std::move(key), std::move(blob)};
|
||||
});
|
||||
return results;
|
||||
return {results, results[results.size() - 1].key};
|
||||
}
|
||||
return {};
|
||||
return {{}, {}};
|
||||
}
|
||||
|
||||
std::vector<TransactionAndMetadata>
|
||||
@@ -405,6 +407,7 @@ std::pair<
|
||||
std::optional<AccountTransactionsCursor>>
|
||||
PostgresBackend::fetchAccountTransactions(
|
||||
ripple::AccountID const& account,
|
||||
std::uint32_t limit,
|
||||
std::optional<AccountTransactionsCursor> const& cursor) const
|
||||
{
|
||||
PgQuery pgQuery(pgPool_);
|
||||
@@ -415,7 +418,6 @@ PostgresBackend::fetchAccountTransactions(
|
||||
if (cursor)
|
||||
sql << " AND ledger_sequence < " << cursor->ledgerSequence
|
||||
<< " AND transaction_index < " << cursor->transactionIndex;
|
||||
uint32_t limit = 300;
|
||||
sql << " LIMIT " << std::to_string(limit);
|
||||
auto res = pgQuery(sql.str().data());
|
||||
if (size_t numRows = checkResult(res, 3))
|
||||
|
||||
@@ -37,10 +37,11 @@ public:
|
||||
std::uint32_t ledgerSequence,
|
||||
std::uint32_t limit) const override;
|
||||
|
||||
std::vector<LedgerObject>
|
||||
std::pair<std::vector<LedgerObject>, std::optional<ripple::uint256>>
|
||||
fetchBookOffers(
|
||||
ripple::uint256 const& book,
|
||||
uint32_t ledgerSequence,
|
||||
std::uint32_t limit,
|
||||
std::optional<ripple::uint256> const& cursor) const override;
|
||||
|
||||
std::vector<TransactionAndMetadata>
|
||||
@@ -57,6 +58,7 @@ public:
|
||||
std::optional<AccountTransactionsCursor>>
|
||||
fetchAccountTransactions(
|
||||
ripple::AccountID const& account,
|
||||
std::uint32_t limit,
|
||||
std::optional<AccountTransactionsCursor> const& cursor) const override;
|
||||
|
||||
void
|
||||
|
||||
@@ -1331,7 +1331,7 @@ CassandraFlatMapBackend::open()
|
||||
query << "SELECT key FROM " << tableName << "books "
|
||||
<< " WHERE book = ? AND sequence <= ? AND deleted_at > ? AND"
|
||||
" key > ? "
|
||||
" ORDER BY key ASC LIMIT 300 ALLOW FILTERING";
|
||||
" ORDER BY key ASC LIMIT ? ALLOW FILTERING";
|
||||
|
||||
prepare_future =
|
||||
cass_session_prepare(session_.get(), query.str().c_str());
|
||||
@@ -1380,7 +1380,7 @@ CassandraFlatMapBackend::open()
|
||||
query = {};
|
||||
query << " SELECT hash,seq_idx FROM " << tableName << "account_tx"
|
||||
<< " WHERE account = ? "
|
||||
<< " AND seq_idx < ? LIMIT 300";
|
||||
<< " AND seq_idx < ? LIMIT ?";
|
||||
|
||||
prepare_future =
|
||||
cass_session_prepare(session_.get(), query.str().c_str());
|
||||
|
||||
@@ -268,6 +268,7 @@ public:
|
||||
std::optional<AccountTransactionsCursor>>
|
||||
fetchAccountTransactions(
|
||||
ripple::AccountID const& account,
|
||||
std::uint32_t limit,
|
||||
std::optional<AccountTransactionsCursor> const& cursor) const override
|
||||
{
|
||||
BOOST_LOG_TRIVIAL(debug) << "Starting doAccountTx";
|
||||
@@ -304,6 +305,15 @@ public:
|
||||
<< cass_error_desc(rc);
|
||||
return {};
|
||||
}
|
||||
rc = cass_statement_bind_int64(statement, 2, limit);
|
||||
if (rc != CASS_OK)
|
||||
{
|
||||
cass_statement_free(statement);
|
||||
BOOST_LOG_TRIVIAL(error)
|
||||
<< "Binding limit to account_tx query: " << rc << ", "
|
||||
<< cass_error_desc(rc);
|
||||
return {};
|
||||
}
|
||||
|
||||
CassFuture* fut;
|
||||
do
|
||||
@@ -1038,10 +1048,11 @@ public:
|
||||
return {{}, {}};
|
||||
}
|
||||
|
||||
std::vector<LedgerObject>
|
||||
std::pair<std::vector<LedgerObject>, std::optional<ripple::uint256>>
|
||||
fetchBookOffers(
|
||||
ripple::uint256 const& book,
|
||||
uint32_t sequence,
|
||||
std::uint32_t limit,
|
||||
std::optional<ripple::uint256> const& cursor) const override
|
||||
{
|
||||
BOOST_LOG_TRIVIAL(debug) << "Starting doBookOffers";
|
||||
@@ -1098,6 +1109,15 @@ public:
|
||||
<< ", " << cass_error_desc(rc);
|
||||
return {};
|
||||
}
|
||||
rc = cass_statement_bind_int64(statement, 4, limit);
|
||||
if (rc != CASS_OK)
|
||||
{
|
||||
cass_statement_free(statement);
|
||||
BOOST_LOG_TRIVIAL(error)
|
||||
<< "Binding Cassandra limit to doBookOffers query: " << rc
|
||||
<< ", " << cass_error_desc(rc);
|
||||
return {};
|
||||
}
|
||||
CassFuture* fut;
|
||||
do
|
||||
{
|
||||
@@ -1152,10 +1172,10 @@ public:
|
||||
{
|
||||
results.push_back({keys[i], objs[i]});
|
||||
}
|
||||
return results;
|
||||
return {results, results[results.size() - 1].key};
|
||||
}
|
||||
|
||||
return {};
|
||||
return {{}, {}};
|
||||
}
|
||||
bool
|
||||
canFetchBatch()
|
||||
|
||||
Reference in New Issue
Block a user