mirror of
https://github.com/XRPLF/clio.git
synced 2025-11-20 03:35:55 +00:00
add a limit
This commit is contained in:
@@ -502,11 +502,14 @@ CassandraBackend::fetchBookOffers(
|
|||||||
std::optional<ripple::uint256> const& cursor) const
|
std::optional<ripple::uint256> const& cursor) const
|
||||||
{
|
{
|
||||||
auto rng = fetchLedgerRange();
|
auto rng = fetchLedgerRange();
|
||||||
|
auto limitTuningFactor = 50;
|
||||||
|
|
||||||
if(!rng)
|
if(!rng)
|
||||||
return {{},{}};
|
return {{},{}};
|
||||||
|
|
||||||
auto readBooks = [this, &book](std::uint32_t sequence)
|
auto readBooks =
|
||||||
|
[this, &book, &limit, &limitTuningFactor]
|
||||||
|
(std::uint32_t sequence)
|
||||||
-> std::pair<bool, std::vector<std::pair<std::uint64_t, ripple::uint256>>>
|
-> std::pair<bool, std::vector<std::pair<std::uint64_t, ripple::uint256>>>
|
||||||
{
|
{
|
||||||
CassandraStatement completeQuery{completeBook_};
|
CassandraStatement completeQuery{completeBook_};
|
||||||
@@ -527,6 +530,8 @@ CassandraBackend::fetchBookOffers(
|
|||||||
statement.bindBytes(zero.data(), 8);
|
statement.bindBytes(zero.data(), 8);
|
||||||
statement.bindBytes(zero);
|
statement.bindBytes(zero);
|
||||||
|
|
||||||
|
statement.bindUInt(limit * limitTuningFactor);
|
||||||
|
|
||||||
auto start = std::chrono::system_clock::now();
|
auto start = std::chrono::system_clock::now();
|
||||||
|
|
||||||
CassandraResult result = executeSyncRead(statement);
|
CassandraResult result = executeSyncRead(statement);
|
||||||
@@ -1550,7 +1555,8 @@ CassandraBackend::open(bool readOnly)
|
|||||||
query << "SELECT quality_key FROM " << tablePrefix << "books "
|
query << "SELECT quality_key FROM " << tablePrefix << "books "
|
||||||
<< " WHERE book = ? AND sequence = ?"
|
<< " WHERE book = ? AND sequence = ?"
|
||||||
<< " AND quality_key >= (?, ?)"
|
<< " AND quality_key >= (?, ?)"
|
||||||
" ORDER BY quality_key ASC";
|
" ORDER BY quality_key ASC "
|
||||||
|
" LIMIT ?";
|
||||||
if (!selectBook_.prepareStatement(query, session_.get()))
|
if (!selectBook_.prepareStatement(query, session_.get()))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|||||||
@@ -379,6 +379,7 @@ PostgresBackend::fetchBookOffers(
|
|||||||
std::optional<ripple::uint256> const& cursor) const
|
std::optional<ripple::uint256> const& cursor) const
|
||||||
{
|
{
|
||||||
auto rng = fetchLedgerRange();
|
auto rng = fetchLedgerRange();
|
||||||
|
auto limitTuningFactor = 50;
|
||||||
|
|
||||||
if(!rng)
|
if(!rng)
|
||||||
return {{},{}};
|
return {{},{}};
|
||||||
@@ -388,7 +389,9 @@ PostgresBackend::fetchBookOffers(
|
|||||||
ripple::uint256 bookEnd = ripple::getQualityNext(bookBase);
|
ripple::uint256 bookEnd = ripple::getQualityNext(bookBase);
|
||||||
|
|
||||||
using bookKeyPair = std::pair<ripple::uint256, ripple::uint256>;
|
using bookKeyPair = std::pair<ripple::uint256, ripple::uint256>;
|
||||||
auto getBooks = [this, &bookBase, &bookEnd, &limit](std::uint32_t sequence)
|
auto getBooks =
|
||||||
|
[this, &bookBase, &bookEnd, &limit, &limitTuningFactor]
|
||||||
|
(std::uint32_t sequence)
|
||||||
-> std::pair<bool, std::vector<bookKeyPair>>
|
-> std::pair<bool, std::vector<bookKeyPair>>
|
||||||
{
|
{
|
||||||
BOOST_LOG_TRIVIAL(info) << __func__ << ": Fetching books between "
|
BOOST_LOG_TRIVIAL(info) << __func__ << ": Fetching books between "
|
||||||
@@ -418,7 +421,8 @@ PostgresBackend::fetchBookOffers(
|
|||||||
<< "\'\\x" << ripple::strHex(bookBase) << "\' "
|
<< "\'\\x" << ripple::strHex(bookBase) << "\' "
|
||||||
<< "AND book < "
|
<< "AND book < "
|
||||||
<< "\'\\x" << ripple::strHex(bookEnd) << "\' "
|
<< "\'\\x" << ripple::strHex(bookEnd) << "\' "
|
||||||
<< "ORDER BY book ASC";
|
<< "ORDER BY book ASC "
|
||||||
|
<< "LIMIT " << std::to_string(limit * limitTuningFactor);
|
||||||
|
|
||||||
BOOST_LOG_TRIVIAL(debug) << sql.str();
|
BOOST_LOG_TRIVIAL(debug) << sql.str();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user