diff --git a/plugins/cpp_metrics/service/cxxmetrics.thrift b/plugins/cpp_metrics/service/cxxmetrics.thrift index ca5826aaa..d766bdcf1 100644 --- a/plugins/cpp_metrics/service/cxxmetrics.thrift +++ b/plugins/cpp_metrics/service/cxxmetrics.thrift @@ -61,10 +61,22 @@ struct CppMetricsModuleSingle 3:double value } -struct CppMetricsModuleAll +struct CppMetricsAstNodeEntry { - 1:common.FileId id, - 2:list metrics + 1: common.AstNodeId astNodeId, + 2: list metrics +} + +struct CppMetricsAstNodeDetailedEntry +{ + 1: common.AstNodeId astNodeId, + 2: CppMetricsAstNodeDetailed details +} + +struct CppMetricsModuleEntry +{ + 1: common.FileId fileId, + 2: list metrics } service CppMetricsService @@ -97,7 +109,7 @@ service CppMetricsService * * The given path is a handled as a prefix. */ - map> getCppAstNodeMetricsForPath( + list getCppAstNodeMetricsForPath( 1:string path) /** @@ -106,7 +118,7 @@ service CppMetricsService * * The given path is a handled as a prefix. */ - map> getPagedCppAstNodeMetricsForPath( + list getPagedCppAstNodeMetricsForPath( 1:string path 2:i32 pageSize, 3:common.AstNodeId previousId) @@ -117,7 +129,7 @@ service CppMetricsService * * The given path is a handled as a prefix. */ - map getCppAstNodeMetricsDetailedForPath( + list getCppAstNodeMetricsDetailedForPath( 1:string path) /** @@ -126,7 +138,7 @@ service CppMetricsService * * The given path is a handled as a prefix. */ - map getPagedCppAstNodeMetricsDetailedForPath( + list getPagedCppAstNodeMetricsDetailedForPath( 1:string path, 2:i32 pageSize, 3:common.AstNodeId previousId) @@ -137,7 +149,7 @@ service CppMetricsService * * The given path is a handled as a prefix. */ - map> getCppFileMetricsForPath( + list getCppFileMetricsForPath( 1:string path) /** @@ -146,7 +158,7 @@ service CppMetricsService * * The given path is a handled as a prefix. */ - map> getPagedCppFileMetricsForPath( + list getPagedCppFileMetricsForPath( 1:string path, 2:i32 pageSize, 3:common.FileId previousId) diff --git a/plugins/cpp_metrics/service/include/service/cppmetricsservice.h b/plugins/cpp_metrics/service/include/service/cppmetricsservice.h index f51be4a49..3c6bc048a 100644 --- a/plugins/cpp_metrics/service/include/service/cppmetricsservice.h +++ b/plugins/cpp_metrics/service/include/service/cppmetricsservice.h @@ -50,31 +50,31 @@ class CppMetricsServiceHandler : virtual public CppMetricsServiceIf const core::FileId& fileId_) override; void getCppAstNodeMetricsForPath( - std::map>& _return, + std::vector& _return, const std::string& path_) override; void getPagedCppAstNodeMetricsForPath( - std::map>& _return, + std::vector& _return, const std::string& path_, const std::int32_t pageSize_, const core::AstNodeId& previousId_) override; void getCppAstNodeMetricsDetailedForPath( - std::map& _return, + std::vector& _return, const std::string& path_) override; void getPagedCppAstNodeMetricsDetailedForPath( - std::map& _return, + std::vector& _return, const std::string& path_, const std::int32_t pageSize_, const core::AstNodeId& previousId_) override; void getCppFileMetricsForPath( - std::map>& _return, + std::vector& _return, const std::string& path_) override; void getPagedCppFileMetricsForPath( - std::map>& _return, + std::vector& _return, const std::string& path_, const std::int32_t pageSize_, const core::FileId& previousId_) override; @@ -104,15 +104,15 @@ class CppMetricsServiceHandler : virtual public CppMetricsServiceIf const model::FileId previousId_); void queryCppAstNodeMetricsForPath( - std::map>& _return, + std::vector& result_, const odb::query& query_); void queryCppAstNodeMetricsDetailedForPath( - std::map& _return, + std::vector& result_, const odb::query& query_); void queryCppFileMetricsForPath( - std::map>& _return, + std::vector& result_, const odb::query& query_); }; diff --git a/plugins/cpp_metrics/service/src/cppmetricsservice.cpp b/plugins/cpp_metrics/service/src/cppmetricsservice.cpp index 45bc8be68..4f5c282bd 100644 --- a/plugins/cpp_metrics/service/src/cppmetricsservice.cpp +++ b/plugins/cpp_metrics/service/src/cppmetricsservice.cpp @@ -148,7 +148,7 @@ void CppMetricsServiceHandler::getCppMetricsForModule( } void CppMetricsServiceHandler::queryCppAstNodeMetricsForPath( - std::map>& _return, + std::vector& result_, const odb::query& query_) { _transaction([&, this](){ @@ -161,22 +161,32 @@ void CppMetricsServiceHandler::queryCppAstNodeMetricsForPath( metric.type = static_cast(node.type); metric.value = node.value; - if (_return.count(std::to_string(node.astNodeId))) + // Try to find existing entry with same astNodeId + auto it = std::find_if(result_.begin(), result_.end(), + [&](const CppMetricsAstNodeEntry& entry) { + return std::stoull(entry.astNodeId) == node.astNodeId; + }); + + if (it != result_.end()) { - _return[std::to_string(node.astNodeId)].push_back(metric); + // Found existing entry → append metric + it->metrics.push_back(metric); } + else { - std::vector metricsList; - metricsList.push_back(metric); - _return.insert(std::make_pair(std::to_string(node.astNodeId), metricsList)); + // No entry for this astNodeId → create new one + CppMetricsAstNodeEntry entry; + entry.astNodeId = std::to_string(node.astNodeId); + entry.metrics.push_back(metric); + result_.push_back(std::move(entry)); } } }); } void CppMetricsServiceHandler::getCppAstNodeMetricsForPath( - std::map>& _return, + std::vector& _return, const std::string& path_) { queryCppAstNodeMetricsForPath(_return, @@ -184,7 +194,7 @@ void CppMetricsServiceHandler::getCppAstNodeMetricsForPath( } void CppMetricsServiceHandler::getPagedCppAstNodeMetricsForPath( - std::map>& _return, + std::vector& _return, const std::string& path_, const std::int32_t pageSize_, const core::AstNodeId& previousId_) @@ -197,7 +207,7 @@ void CppMetricsServiceHandler::getPagedCppAstNodeMetricsForPath( } void CppMetricsServiceHandler::queryCppAstNodeMetricsDetailedForPath( - std::map& _return, + std::vector& result_, const odb::query& query_) { _transaction([&, this](){ @@ -206,12 +216,21 @@ void CppMetricsServiceHandler::queryCppAstNodeMetricsDetailedForPath( for (const auto& node : nodes) { auto pair = std::make_pair(static_cast(node.type), node.value); - if (_return.count(std::to_string(node.astNodeId))) + + // Try to find existing entry with same astNodeId + auto it = std::find_if(result_.begin(), result_.end(), + [&](const CppMetricsAstNodeDetailedEntry& entry) { + return std::stoull(entry.astNodeId) == node.astNodeId; + }); + + if (it != result_.end()) { - _return[std::to_string(node.astNodeId)].metrics.insert(pair); + // Found existing entry → append metric + it->details.metrics.insert(pair); } else { + // No entry for this astNodeId → create new one CppMetricsAstNodeDetailed metric; std::size_t pos = node.path.find_last_of('/'); metric.path = node.path.substr(0, pos + 1); @@ -223,14 +242,18 @@ void CppMetricsServiceHandler::queryCppAstNodeMetricsDetailedForPath( metric.astType = cc::model::astTypeToString(node.astType); metric.metrics.insert(pair); - _return.insert(std::make_pair(std::to_string(node.astNodeId), metric)); + CppMetricsAstNodeDetailedEntry entry; + entry.astNodeId = std::to_string(node.astNodeId); + entry.details = metric; + + result_.push_back(std::move(entry)); } } }); } void CppMetricsServiceHandler::getCppAstNodeMetricsDetailedForPath( - std::map& _return, + std::vector& _return, const std::string& path_) { queryCppAstNodeMetricsDetailedForPath(_return, @@ -238,7 +261,7 @@ void CppMetricsServiceHandler::getCppAstNodeMetricsDetailedForPath( } void CppMetricsServiceHandler::getPagedCppAstNodeMetricsDetailedForPath( - std::map& _return, + std::vector& _return, const std::string& path_, const std::int32_t pageSize_, const core::AstNodeId& previousId_) @@ -247,11 +270,12 @@ void CppMetricsServiceHandler::getPagedCppAstNodeMetricsDetailedForPath( path_, pageSize_, previousId_.empty() ? 0 : std::stoull(previousId_)); queryCppAstNodeMetricsDetailedForPath(_return, - CppNodeMetricsQuery::CppAstNodeMetrics::astNodeId.in_range(paged_nodes.begin(), paged_nodes.end())); + CppNodeMetricsQuery::CppAstNodeMetrics::astNodeId.in_range(paged_nodes.begin(), paged_nodes.end()) + + ("ORDER BY" + odb::query::astNodeId)); } void CppMetricsServiceHandler::queryCppFileMetricsForPath( - std::map>& _return, + std::vector& result_, const odb::query& query_) { _transaction([&, this](){ @@ -264,22 +288,32 @@ void CppMetricsServiceHandler::queryCppFileMetricsForPath( metric.type = static_cast(file.type); metric.value = file.value; - if (_return.count(std::to_string(file.fileId))) + // Try to find existing entry with same fileId + auto it = std::find_if(result_.begin(), result_.end(), + [&](const CppMetricsModuleEntry& entry) { + return std::stoull(entry.fileId) == file.fileId; + }); + + if (it != result_.end()) { - _return[std::to_string(file.fileId)].push_back(metric); + // Found existing entry → append metric + it->metrics.push_back(metric); } + else { - std::vector metricsList; - metricsList.push_back(metric); - _return.insert(std::make_pair(std::to_string(file.fileId), metricsList)); + // No entry for this fileId → create new one + CppMetricsModuleEntry entry; + entry.fileId = std::to_string(file.fileId); + entry.metrics.push_back(metric); + result_.push_back(std::move(entry)); } } }); } void CppMetricsServiceHandler::getCppFileMetricsForPath( - std::map>& _return, + std::vector& _return, const std::string& path_) { queryCppFileMetricsForPath(_return, @@ -287,15 +321,17 @@ void CppMetricsServiceHandler::getCppFileMetricsForPath( } void CppMetricsServiceHandler::getPagedCppFileMetricsForPath( - std::map>& _return, + std::vector& _return, const std::string& path_, const std::int32_t pageSize_, const core::FileId& previousId_) { std::vector paged_files = pageFileMetrics( path_, pageSize_, previousId_.empty() ? 0 : std::stoull(previousId_)); + queryCppFileMetricsForPath(_return, - CppModuleMetricsQuery::CppFileMetrics::file.in_range(paged_files.begin(), paged_files.end())); + CppModuleMetricsQuery::CppFileMetrics::file.in_range(paged_files.begin(), paged_files.end()) + + ("ORDER BY" + odb::query::file)); } std::string CppMetricsServiceHandler::getLimitQuery( diff --git a/webgui-new/package-lock.json b/webgui-new/package-lock.json index 74ba3d3c9..cde42c7f4 100644 --- a/webgui-new/package-lock.json +++ b/webgui-new/package-lock.json @@ -2702,9 +2702,9 @@ "dev": true }, "node_modules/brace-expansion": { - "version": "1.1.11", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", - "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "version": "1.1.12", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.12.tgz", + "integrity": "sha512-9T9UjW3r0UW5c1Q7GTwllptXwhvYmEzFhzMfZ9H7FQWt+uZePjZPjBP/W1ZEyZ1twGWom5/56TF4lPcqjnDHcg==", "dev": true, "dependencies": { "balanced-match": "^1.0.0", @@ -3019,9 +3019,9 @@ "integrity": "sha512-VQ2MBenTq1fWZUH9DJNGti7kKv6EeAuYr3cLwxUWhIu1baTaXh4Ib5W2CqHVqib4/MqbYGJqiL3Zb8GJZr3l4g==" }, "node_modules/cross-spawn": { - "version": "7.0.3", - "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", - "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==", + "version": "7.0.6", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz", + "integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==", "dev": true, "dependencies": { "path-key": "^3.1.0", @@ -4076,9 +4076,9 @@ } }, "node_modules/express": { - "version": "4.21.1", - "resolved": "https://registry.npmjs.org/express/-/express-4.21.1.tgz", - "integrity": "sha512-YSFlK1Ee0/GC8QaO91tHcDxJiE/X4FbpAyQWkxAvG6AXCuR65YzK8ua6D9hvi/TzUfZMpc+BwuM1IPw8fmQBiQ==", + "version": "4.21.2", + "resolved": "https://registry.npmjs.org/express/-/express-4.21.2.tgz", + "integrity": "sha512-28HqgMZAmih1Czt9ny7qr6ek2qddF4FclbMzwhCREB6OFfH+rXAnuNCwo1/wFvrtbgsQDb4kSbX9de9lFbrXnA==", "dev": true, "dependencies": { "accepts": "~1.3.8", @@ -4100,7 +4100,7 @@ "methods": "~1.1.2", "on-finished": "2.4.1", "parseurl": "~1.3.3", - "path-to-regexp": "0.1.10", + "path-to-regexp": "0.1.12", "proxy-addr": "~2.0.7", "qs": "6.13.0", "range-parser": "~1.2.1", @@ -4115,6 +4115,10 @@ }, "engines": { "node": ">= 0.10.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" } }, "node_modules/express/node_modules/debug": { @@ -5466,12 +5470,12 @@ } }, "node_modules/micromatch": { - "version": "4.0.5", - "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.5.tgz", - "integrity": "sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA==", + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.8.tgz", + "integrity": "sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA==", "dev": true, "dependencies": { - "braces": "^3.0.2", + "braces": "^3.0.3", "picomatch": "^2.3.1" }, "engines": { @@ -5930,9 +5934,9 @@ "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==" }, "node_modules/path-to-regexp": { - "version": "0.1.10", - "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.10.tgz", - "integrity": "sha512-7lf7qcQidTku0Gu3YDPc8DJ1q7OOucfa/BSsIwjuh56VU7katFvuM8hULfkwB3Fns/rsVF7PwPKVw1sl5KQS9w==", + "version": "0.1.12", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.12.tgz", + "integrity": "sha512-RA1GjUVMnvYFxuqovrEqZoxxW5NUZqbwKtYz/Tt7nXerk0LbLblQmrsgdeOxV5SFHf0UDggjS/bSeOZwt1pmEQ==", "dev": true }, "node_modules/path-type": {