diff --git a/model/include/model/file.h b/model/include/model/file.h index f03c88571..1c308bd85 100644 --- a/model/include/model/file.h +++ b/model/include/model/file.h @@ -87,6 +87,16 @@ struct FileIdView { FileId id; }; + +#pragma db view object(File) +struct FilePathView +{ + #pragma db column(File::id) + FileId id; + + #pragma db column(File::path) + std::string path; +}; #pragma db view object(File) query((?) + " GROUP BY " + File::type) struct FileTypeView diff --git a/plugins/cpp_metrics/service/src/cppmetricsservice.cpp b/plugins/cpp_metrics/service/src/cppmetricsservice.cpp index 21bf7a21c..31921625b 100644 --- a/plugins/cpp_metrics/service/src/cppmetricsservice.cpp +++ b/plugins/cpp_metrics/service/src/cppmetricsservice.cpp @@ -2,6 +2,8 @@ #include #include +#include +#include namespace cc { @@ -121,22 +123,24 @@ void CppMetricsServiceHandler::getCppAstNodeMetricsForPath( std::vector& _return, const std::string& path_) { - _transaction([&, this]() - { + _transaction([&, this](){ typedef odb::query CppAstNodeMetricsQuery; typedef odb::result CppAstNodeMetricsResult; typedef odb::query CppAstNodeFilePathQuery; typedef odb::result CppAstNodeFilePathResult; + auto nodesRes = _db->query(); + std::set nodesWithMetrics; + for (const auto& node : nodesRes) + nodesWithMetrics.insert(node.astNodeId); + CppAstNodeFilePathResult nodes = _db->query( - CppAstNodeFilePathQuery::LocFile::path.like(path_ + '%')); + CppAstNodeFilePathQuery::LocFile::path.like(path_ + '%') && + CppAstNodeFilePathQuery::CppAstNode::id.in_range( + nodesWithMetrics.begin(), nodesWithMetrics.end())); if (nodes.empty()) - { - core::InvalidInput ex; - ex.__set_msg("Invalid metric type for path: " + path_); - throw ex; - } + return; for (const auto& node : nodes) { @@ -167,22 +171,24 @@ void CppMetricsServiceHandler::getCppFileMetricsForPath( std::vector& _return, const std::string& path_) { - _transaction([&, this]() - { - typedef odb::query FileQuery; - typedef odb::result FileResult; + _transaction([&, this](){ + typedef odb::query FileQuery; + typedef odb::result FileResult; typedef odb::query CppFileMetricsQuery; typedef odb::result CppFileMetricsResult; - FileResult descendants = _db->query( - FileQuery::path.like(path_ + '%')); + auto filesRes = _db->query(); + std::set filesWithMetrics; + for (const auto& file : filesRes) + filesWithMetrics.insert(file.file); + + FileResult descendants = _db->query( + FileQuery::path.like(path_ + '%') && + CppFileMetricsQuery::file.in_range( + filesWithMetrics.begin(), filesWithMetrics.end())); if (descendants.empty()) - { - core::InvalidInput ex; - ex.__set_msg("Invalid metric type for path: " + path_); - throw ex; - } + return; for (const auto& file : descendants) {