Skip to content

Conversation

mcserep
Copy link
Collaborator

@mcserep mcserep commented Aug 26, 2025

C++ metrics results are not properly sorted, since currently the results are returned in a std::map, whose key is the ASTNode ID (or File ID), interpreted as strings. However, these IDs are stored as signed integers in the database, while in the CodeCompass codebase they are unsigned integers. Their comparison should therefore be performed as integers (because the database engine also does this for the ORDER BY clause), otherwise it is not certain that the last element will be the largest ID in the given result set. This is especially troubling for paginated results.

@mcserep mcserep self-assigned this Aug 26, 2025
@mcserep mcserep requested a review from Copilot August 26, 2025 07:26
@mcserep mcserep added Kind: Bug ⚠️ Plugin: C++ Issues related to the parsing and presentation of C++ projects. Plugin: Metrics Issues related to the code metrics plugin. labels Aug 26, 2025
@mcserep mcserep added this to the Upcoming Release milestone Aug 26, 2025
@mcserep mcserep added this to Roadmap Aug 26, 2025
@github-project-automation github-project-automation bot moved this to In progress in Roadmap Aug 26, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR changes the C++ metrics API from returning results in std::map containers (keyed by string representations of IDs) to returning results in ordered std::vector containers. This addresses a sorting issue where string-based comparison of IDs was inconsistent with integer-based database ordering, particularly problematic for paginated results.

  • Replaced std::map return types with std::vector of structured entry types
  • Added explicit ORDER BY clauses to database queries for consistent ordering
  • Introduced new Thrift struct types to support the vector-based API

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
cxxmetrics.thrift Defines new entry struct types for vector-based API
cppmetricsservice.h Updates method signatures to use vector return types
cppmetricsservice.cpp Implements vector-based logic with proper ordering

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

// 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;
Copy link
Preview

Copilot AI Aug 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Converting string to unsigned long long for every comparison creates a performance bottleneck. Consider storing the numeric ID alongside the string ID in the entry struct to avoid repeated conversions.

Copilot uses AI. Check for mistakes.

// 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;
Copy link
Preview

Copilot AI Aug 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Converting string to unsigned long long for every comparison creates a performance bottleneck. Consider storing the numeric ID alongside the string ID in the entry struct to avoid repeated conversions.

Suggested change
return std::stoull(entry.astNodeId) == node.astNodeId;
return entry.astNodeIdNum == node.astNodeId;

Copilot uses AI. Check for mistakes.

// 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;
Copy link
Preview

Copilot AI Aug 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Converting string to unsigned long long for every comparison creates a performance bottleneck. Consider storing the numeric ID alongside the string ID in the entry struct to avoid repeated conversions.

Suggested change
return std::stoull(entry.fileId) == file.fileId;
return entry.fileIdNumeric == file.fileId;

Copilot uses AI. Check for mistakes.

@mcserep mcserep force-pushed the order_metrics_results branch from 75ac188 to a392e4a Compare August 26, 2025 07:30
@mcserep mcserep merged commit 196c6f0 into Ericsson:master Aug 26, 2025
10 checks passed
@github-project-automation github-project-automation bot moved this from In progress to Done in Roadmap Aug 26, 2025
@mcserep mcserep deleted the order_metrics_results branch August 26, 2025 17:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Kind: Bug ⚠️ Plugin: C++ Issues related to the parsing and presentation of C++ projects. Plugin: Metrics Issues related to the code metrics plugin.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

1 participant