From 854651d00faec0fcdd2cc68194c3716da55b6a1e Mon Sep 17 00:00:00 2001 From: oxarbitrage Date: Mon, 17 Jul 2017 12:19:07 -0700 Subject: [PATCH 1/2] for issue 328 --- libraries/app/database_api.cpp | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/libraries/app/database_api.cpp b/libraries/app/database_api.cpp index 65499e861c..d7dfd7c04a 100644 --- a/libraries/app/database_api.cpp +++ b/libraries/app/database_api.cpp @@ -1031,9 +1031,15 @@ vector database_api_impl::get_call_orders(asset_id_type a, ui const auto& call_index = _db.get_index_type().indices().get(); const asset_object& mia = _db.get(a); price index_price = price::min(mia.bitasset_data(_db).options.short_backing_asset, mia.get_id()); - - return vector(call_index.lower_bound(index_price.min()), - call_index.lower_bound(index_price.max())); + + vector< call_order_object> result; + auto itr_min = call_index.lower_bound(index_price.min()); + while( itr_min != call_index.lower_bound(index_price.max()) && result.size() < limit ) + { + result.emplace_back(*itr_min); + ++itr_min; + } + return result; } vector database_api::get_settle_orders(asset_id_type a, uint32_t limit)const @@ -1045,8 +1051,15 @@ vector database_api_impl::get_settle_orders(asset_id_ty { const auto& settle_index = _db.get_index_type().indices().get(); const asset_object& mia = _db.get(a); - return vector(settle_index.lower_bound(mia.get_id()), - settle_index.upper_bound(mia.get_id())); + + vector result; + auto itr_min = settle_index.lower_bound(mia.get_id()); + while( itr_min != settle_index.upper_bound(mia.get_id()) && result.size() < limit ) + { + result.emplace_back(*itr_min); + ++itr_min; + } + return result; } vector database_api::get_margin_positions( const account_id_type& id )const From 50e535ecbd147406cb67109e90dc511a99ce9628 Mon Sep 17 00:00:00 2001 From: oxarbitrage Date: Mon, 17 Jul 2017 15:33:08 -0700 Subject: [PATCH 2/2] improve performance --- libraries/app/database_api.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libraries/app/database_api.cpp b/libraries/app/database_api.cpp index d7dfd7c04a..94956efd0f 100644 --- a/libraries/app/database_api.cpp +++ b/libraries/app/database_api.cpp @@ -1034,7 +1034,8 @@ vector database_api_impl::get_call_orders(asset_id_type a, ui vector< call_order_object> result; auto itr_min = call_index.lower_bound(index_price.min()); - while( itr_min != call_index.lower_bound(index_price.max()) && result.size() < limit ) + auto itr_max = call_index.lower_bound(index_price.max()); + while( itr_min != itr_max && result.size() < limit ) { result.emplace_back(*itr_min); ++itr_min; @@ -1054,7 +1055,8 @@ vector database_api_impl::get_settle_orders(asset_id_ty vector result; auto itr_min = settle_index.lower_bound(mia.get_id()); - while( itr_min != settle_index.upper_bound(mia.get_id()) && result.size() < limit ) + auto itr_max = settle_index.upper_bound(mia.get_id()); + while( itr_min != itr_max && result.size() < limit ) { result.emplace_back(*itr_min); ++itr_min;