@@ -148,7 +148,7 @@ void CppMetricsServiceHandler::getCppMetricsForModule(
148148}
149149
150150void CppMetricsServiceHandler::queryCppAstNodeMetricsForPath (
151- std::map<core::AstNodeId, std:: vector<CppMetricsAstNodeSingle>>& _return ,
151+ std::vector<CppMetricsAstNodeEntry>& result_ ,
152152 const odb::query<model::CppAstNodeMetricsForPathView>& query_)
153153{
154154 _transaction ([&, this ](){
@@ -161,30 +161,40 @@ void CppMetricsServiceHandler::queryCppAstNodeMetricsForPath(
161161 metric.type = static_cast <CppAstNodeMetricsType::type>(node.type );
162162 metric.value = node.value ;
163163
164- if (_return.count (std::to_string (node.astNodeId )))
164+ // Try to find existing entry with same astNodeId
165+ auto it = std::find_if (result_.begin (), result_.end (),
166+ [&](const CppMetricsAstNodeEntry& entry) {
167+ return std::stoull (entry.astNodeId ) == node.astNodeId ;
168+ });
169+
170+ if (it != result_.end ())
165171 {
166- _return[std::to_string (node.astNodeId )].push_back (metric);
172+ // Found existing entry → append metric
173+ it->metrics .push_back (metric);
167174 }
175+
168176 else
169177 {
170- std::vector<CppMetricsAstNodeSingle> metricsList;
171- metricsList.push_back (metric);
172- _return.insert (std::make_pair (std::to_string (node.astNodeId ), metricsList));
178+ // No entry for this astNodeId → create new one
179+ CppMetricsAstNodeEntry entry;
180+ entry.astNodeId = std::to_string (node.astNodeId );
181+ entry.metrics .push_back (metric);
182+ result_.push_back (std::move (entry));
173183 }
174184 }
175185 });
176186}
177187
178188void CppMetricsServiceHandler::getCppAstNodeMetricsForPath (
179- std::map<core::AstNodeId, std:: vector<CppMetricsAstNodeSingle> >& _return,
189+ std::vector<CppMetricsAstNodeEntry >& _return,
180190 const std::string& path_)
181191{
182192 queryCppAstNodeMetricsForPath (_return,
183193 CppNodeMetricsQuery::LocFile::path.like (path_ + ' %' ));
184194}
185195
186196void CppMetricsServiceHandler::getPagedCppAstNodeMetricsForPath (
187- std::map<core::AstNodeId, std:: vector<CppMetricsAstNodeSingle> >& _return,
197+ std::vector<CppMetricsAstNodeEntry >& _return,
188198 const std::string& path_,
189199 const std::int32_t pageSize_,
190200 const core::AstNodeId& previousId_)
@@ -197,7 +207,7 @@ void CppMetricsServiceHandler::getPagedCppAstNodeMetricsForPath(
197207}
198208
199209void CppMetricsServiceHandler::queryCppAstNodeMetricsDetailedForPath (
200- std::map<core::AstNodeId, CppMetricsAstNodeDetailed >& _return ,
210+ std::vector<CppMetricsAstNodeDetailedEntry >& result_ ,
201211 const odb::query<model::CppAstNodeMetricsAndDataForPathView>& query_)
202212{
203213 _transaction ([&, this ](){
@@ -206,12 +216,21 @@ void CppMetricsServiceHandler::queryCppAstNodeMetricsDetailedForPath(
206216 for (const auto & node : nodes)
207217 {
208218 auto pair = std::make_pair (static_cast <CppAstNodeMetricsType::type>(node.type ), node.value );
209- if (_return.count (std::to_string (node.astNodeId )))
219+
220+ // Try to find existing entry with same astNodeId
221+ auto it = std::find_if (result_.begin (), result_.end (),
222+ [&](const CppMetricsAstNodeDetailedEntry& entry) {
223+ return std::stoull (entry.astNodeId ) == node.astNodeId ;
224+ });
225+
226+ if (it != result_.end ())
210227 {
211- _return[std::to_string (node.astNodeId )].metrics .insert (pair);
228+ // Found existing entry → append metric
229+ it->details .metrics .insert (pair);
212230 }
213231 else
214232 {
233+ // No entry for this astNodeId → create new one
215234 CppMetricsAstNodeDetailed metric;
216235 std::size_t pos = node.path .find_last_of (' /' );
217236 metric.path = node.path .substr (0 , pos + 1 );
@@ -223,22 +242,26 @@ void CppMetricsServiceHandler::queryCppAstNodeMetricsDetailedForPath(
223242 metric.astType = cc::model::astTypeToString (node.astType );
224243 metric.metrics .insert (pair);
225244
226- _return.insert (std::make_pair (std::to_string (node.astNodeId ), metric));
245+ CppMetricsAstNodeDetailedEntry entry;
246+ entry.astNodeId = std::to_string (node.astNodeId );
247+ entry.details = metric;
248+
249+ result_.push_back (std::move (entry));
227250 }
228251 }
229252 });
230253}
231254
232255void CppMetricsServiceHandler::getCppAstNodeMetricsDetailedForPath (
233- std::map<core::AstNodeId, CppMetricsAstNodeDetailed >& _return,
256+ std::vector<CppMetricsAstNodeDetailedEntry >& _return,
234257 const std::string& path_)
235258{
236259 queryCppAstNodeMetricsDetailedForPath (_return,
237260 CppNodeMetricsQuery::LocFile::path.like (path_ + ' %' ));
238261}
239262
240263void CppMetricsServiceHandler::getPagedCppAstNodeMetricsDetailedForPath (
241- std::map<core::AstNodeId, CppMetricsAstNodeDetailed >& _return,
264+ std::vector<CppMetricsAstNodeDetailedEntry >& _return,
242265 const std::string& path_,
243266 const std::int32_t pageSize_,
244267 const core::AstNodeId& previousId_)
@@ -247,11 +270,12 @@ void CppMetricsServiceHandler::getPagedCppAstNodeMetricsDetailedForPath(
247270 path_, pageSize_, previousId_.empty () ? 0 : std::stoull (previousId_));
248271
249272 queryCppAstNodeMetricsDetailedForPath (_return,
250- CppNodeMetricsQuery::CppAstNodeMetrics::astNodeId.in_range (paged_nodes.begin (), paged_nodes.end ()));
273+ CppNodeMetricsQuery::CppAstNodeMetrics::astNodeId.in_range (paged_nodes.begin (), paged_nodes.end ())
274+ + (" ORDER BY" + odb::query<model::CppAstNodeMetrics>::astNodeId));
251275}
252276
253277void CppMetricsServiceHandler::queryCppFileMetricsForPath (
254- std::map<core::FileId, std:: vector<CppMetricsModuleSingle>>& _return ,
278+ std::vector<CppMetricsModuleEntry>& result_ ,
255279 const odb::query<model::CppModuleMetricsForPathView>& query_)
256280{
257281 _transaction ([&, this ](){
@@ -264,38 +288,50 @@ void CppMetricsServiceHandler::queryCppFileMetricsForPath(
264288 metric.type = static_cast <CppModuleMetricsType::type>(file.type );
265289 metric.value = file.value ;
266290
267- if (_return.count (std::to_string (file.fileId )))
291+ // Try to find existing entry with same fileId
292+ auto it = std::find_if (result_.begin (), result_.end (),
293+ [&](const CppMetricsModuleEntry& entry) {
294+ return std::stoull (entry.fileId ) == file.fileId ;
295+ });
296+
297+ if (it != result_.end ())
268298 {
269- _return[std::to_string (file.fileId )].push_back (metric);
299+ // Found existing entry → append metric
300+ it->metrics .push_back (metric);
270301 }
302+
271303 else
272304 {
273- std::vector<CppMetricsModuleSingle> metricsList;
274- metricsList.push_back (metric);
275- _return.insert (std::make_pair (std::to_string (file.fileId ), metricsList));
305+ // No entry for this fileId → create new one
306+ CppMetricsModuleEntry entry;
307+ entry.fileId = std::to_string (file.fileId );
308+ entry.metrics .push_back (metric);
309+ result_.push_back (std::move (entry));
276310 }
277311 }
278312 });
279313}
280314
281315void CppMetricsServiceHandler::getCppFileMetricsForPath (
282- std::map<core::FileId, std:: vector<CppMetricsModuleSingle> >& _return,
316+ std::vector<CppMetricsModuleEntry >& _return,
283317 const std::string& path_)
284318{
285319 queryCppFileMetricsForPath (_return,
286320 CppModuleMetricsQuery::File::path.like (path_ + ' %' ));
287321}
288322
289323void CppMetricsServiceHandler::getPagedCppFileMetricsForPath (
290- std::map<core::FileId, std:: vector<CppMetricsModuleSingle> >& _return,
324+ std::vector<CppMetricsModuleEntry >& _return,
291325 const std::string& path_,
292326 const std::int32_t pageSize_,
293327 const core::FileId& previousId_)
294328{
295329 std::vector<model::FileId> paged_files = pageFileMetrics (
296330 path_, pageSize_, previousId_.empty () ? 0 : std::stoull (previousId_));
331+
297332 queryCppFileMetricsForPath (_return,
298- CppModuleMetricsQuery::CppFileMetrics::file.in_range (paged_files.begin (), paged_files.end ()));
333+ CppModuleMetricsQuery::CppFileMetrics::file.in_range (paged_files.begin (), paged_files.end ())
334+ + (" ORDER BY" + odb::query<model::CppFileMetrics>::file));
299335}
300336
301337std::string CppMetricsServiceHandler::getLimitQuery (
0 commit comments