Skip to content

Commit

Permalink
[Metrics] Fix countTransactions()
Browse files Browse the repository at this point in the history
Signed-off-by: kuvaldini <[email protected]>
  • Loading branch information
kuvaldini committed Jun 10, 2021
1 parent fce0c1d commit 5f48eeb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
11 changes: 7 additions & 4 deletions irohad/ametsuchi/impl/postgres_wsv_query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,13 @@ namespace iroha {
}

iroha::expected::Result<size_t, std::string> PostgresWsvQuery::count(
std::string_view what) try {
std::string_view table, std::string_view column /* ="*" */) try {
int count;
sql_ << "SELECT count(*) FROM " << what, soci::into(count);
sql_ << "SELECT count(" << column << ") FROM " << table,
soci::into(count);
return count;
} catch (const std::exception &e) {
auto msg = fmt::format("Failed to count {}, query: {}", what, e.what());
auto msg = fmt::format("Failed to count {}, query: {}", table, e.what());
log_->error(msg);
return iroha::expected::makeError(msg);
}
Expand All @@ -103,7 +104,9 @@ namespace iroha {

iroha::expected::Result<size_t, std::string>
PostgresWsvQuery::countTransactions() {
return count("tx_positions");
return count("tx_positions", "DISTINCT hash");
// OR return count("tx_status_from_hash", "*", "WHERE status=true");
// //select count(*) from tx_status_by_hash where status=true
}

boost::optional<std::shared_ptr<shared_model::interface::Peer>>
Expand Down
3 changes: 2 additions & 1 deletion irohad/ametsuchi/impl/postgres_wsv_query.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ namespace iroha {
template <typename T, typename F>
auto execute(F &&f) -> boost::optional<soci::rowset<T>>;

iroha::expected::Result<size_t, std::string> count(std::string_view);
iroha::expected::Result<size_t, std::string> count(
std::string_view, std::string_view column = "*");

// TODO andrei 24.09.2018: IR-1718 Consistent soci::session fields in
// storage classes
Expand Down

0 comments on commit 5f48eeb

Please sign in to comment.