-
Notifications
You must be signed in to change notification settings - Fork 113
Query paginated metrics efficiently #804
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -187,10 +187,10 @@ void CppMetricsServiceHandler::getPagedCppAstNodeMetricsForPath( | |||||||||||||||||||||||||||||||||||
| std::map<core::AstNodeId, std::vector<CppMetricsAstNodeSingle>>& _return, | ||||||||||||||||||||||||||||||||||||
| const std::string& path_, | ||||||||||||||||||||||||||||||||||||
| const std::int32_t pageSize_, | ||||||||||||||||||||||||||||||||||||
| const std::int32_t pageNumber_) | ||||||||||||||||||||||||||||||||||||
| const core::AstNodeId& previousId_) | ||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||
| std::vector<model::CppAstNodeId> paged_nodes = pageMetrics<model::CppAstNodeId, model::CppAstNodeMetricsDistinctView>( | ||||||||||||||||||||||||||||||||||||
| path_, pageSize_, pageNumber_); | ||||||||||||||||||||||||||||||||||||
| std::vector<model::CppAstNodeId> paged_nodes = pageAstNodeMetrics( | ||||||||||||||||||||||||||||||||||||
| path_, pageSize_, previousId_.empty() ? 0 : std::stoull(previousId_)); | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| queryCppAstNodeMetricsForPath(_return, | ||||||||||||||||||||||||||||||||||||
| CppNodeMetricsQuery::CppAstNodeMetrics::astNodeId.in_range(paged_nodes.begin(), paged_nodes.end())); | ||||||||||||||||||||||||||||||||||||
|
|
@@ -241,10 +241,10 @@ void CppMetricsServiceHandler::getPagedCppAstNodeMetricsDetailedForPath( | |||||||||||||||||||||||||||||||||||
| std::map<core::AstNodeId, CppMetricsAstNodeDetailed>& _return, | ||||||||||||||||||||||||||||||||||||
| const std::string& path_, | ||||||||||||||||||||||||||||||||||||
| const std::int32_t pageSize_, | ||||||||||||||||||||||||||||||||||||
| const std::int32_t pageNumber_) | ||||||||||||||||||||||||||||||||||||
| const core::AstNodeId& previousId_) | ||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||
| std::vector<model::CppAstNodeId> paged_nodes = pageMetrics<model::CppAstNodeId, model::CppAstNodeMetricsDistinctView>( | ||||||||||||||||||||||||||||||||||||
| path_, pageSize_, pageNumber_); | ||||||||||||||||||||||||||||||||||||
| std::vector<model::CppAstNodeId> paged_nodes = pageAstNodeMetrics( | ||||||||||||||||||||||||||||||||||||
| path_, pageSize_, previousId_.empty() ? 0 : std::stoull(previousId_)); | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| queryCppAstNodeMetricsDetailedForPath(_return, | ||||||||||||||||||||||||||||||||||||
| CppNodeMetricsQuery::CppAstNodeMetrics::astNodeId.in_range(paged_nodes.begin(), paged_nodes.end())); | ||||||||||||||||||||||||||||||||||||
|
|
@@ -290,16 +290,16 @@ void CppMetricsServiceHandler::getPagedCppFileMetricsForPath( | |||||||||||||||||||||||||||||||||||
| std::map<core::FileId, std::vector<CppMetricsModuleSingle>>& _return, | ||||||||||||||||||||||||||||||||||||
| const std::string& path_, | ||||||||||||||||||||||||||||||||||||
| const std::int32_t pageSize_, | ||||||||||||||||||||||||||||||||||||
| const std::int32_t pageNumber_) | ||||||||||||||||||||||||||||||||||||
| const core::FileId& previousId_) | ||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||
| std::vector<model::FileId> paged_files = pageMetrics<model::FileId, model::CppModuleMetricsDistinctView>(path_, pageSize_, pageNumber_); | ||||||||||||||||||||||||||||||||||||
| std::vector<model::FileId> paged_files = pageFileMetrics( | ||||||||||||||||||||||||||||||||||||
| path_, pageSize_, previousId_.empty() ? 0 : std::stoull(previousId_)); | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+295
to
+296
|
||||||||||||||||||||||||||||||||||||
| std::vector<model::FileId> paged_files = pageFileMetrics( | |
| path_, pageSize_, previousId_.empty() ? 0 : std::stoull(previousId_)); | |
| std::uint64_t previousIdValue = 0; | |
| if (!previousId_.empty()) { | |
| try { | |
| previousIdValue = std::stoull(previousId_); | |
| } catch (const std::invalid_argument& e) { | |
| core::InvalidInput ex; | |
| ex.__set_msg("Invalid previousId_: " + previousId_ + ". Must be a numeric value."); | |
| throw ex; | |
| } catch (const std::out_of_range& e) { | |
| core::InvalidInput ex; | |
| ex.__set_msg("Invalid previousId_: " + previousId_ + ". Value out of range."); | |
| throw ex; | |
| } | |
| } | |
| std::vector<model::FileId> paged_files = pageFileMetrics(path_, pageSize_, previousIdValue); |
Copilot
AI
Jul 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pre-sizing the vector with paged_nodes.size() may not be accurate since the result set size might differ from the allocated size. Consider using reserve() instead of sizing the constructor, or use emplace_back() in the transform operation.
Copilot
AI
Jul 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pre-sizing the vector with paged_nodes.size() may not be accurate since the result set size might differ from the allocated size. Consider using reserve() instead of sizing the constructor, or use emplace_back() in the transform operation.
| std::vector<model::FileId> paged_ids(paged_nodes.size()); | |
| std::transform(paged_nodes.begin(), paged_nodes.end(), paged_ids.begin(), | |
| [](const model::CppModuleMetricsDistinctView& e){ | |
| return e.fileId; | |
| }); | |
| std::vector<model::FileId> paged_ids; | |
| paged_ids.reserve(paged_nodes.size()); | |
| for (const auto& e : paged_nodes) { | |
| paged_ids.emplace_back(e.fileId); | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The std::stoull function can throw std::invalid_argument or std::out_of_range exceptions when the string cannot be converted to an unsigned long long. Consider adding proper error handling or validation for the previousId_ parameter.