Skip to content

Commit f208eb4

Browse files
author
Barnabás Domozi
committed
Use native COUNT instead of odb::result::size() in metrics calculations.
1 parent 20e0d0d commit f208eb4

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

plugins/cpp_metrics/model/include/model/cpptypedependencymetrics.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,11 @@ struct CppTypeDependencyMetricsPathView
5656
object(File = EntityFile : EntityAstNode::location.file == EntityFile::id) \
5757
object(CppAstNode = DependencyAstNode : CppTypeDependencyMetrics::dependencyHash == DependencyAstNode::entityHash \
5858
&& DependencyAstNode::astType == cc::model::CppAstNode::AstType::Definition) \
59-
object(File = DependencyFile : DependencyAstNode::location.file == DependencyFile::id) \
60-
query((?), distinct)
61-
struct CppDistinctTypeDependencyMetricsPathView
59+
object(File = DependencyFile : DependencyAstNode::location.file == DependencyFile::id)
60+
struct CppTypeDependencyMetricsPathViewDistinctCount
6261
{
63-
#pragma db column(CppTypeDependencyMetrics::dependencyHash)
64-
std::size_t dependencyHash;
62+
#pragma db column("count(distinct" + CppTypeDependencyMetrics::dependencyHash + ")")
63+
std::size_t count;
6564
};
6665

6766
} // model

plugins/cpp_metrics/parser/src/cppmetricsparser.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,8 @@ void CppMetricsParser::efferentTypeLevel()
395395
// Count parent types
396396
auto inheritanceView = _ctx.db->query<model::CppInheritance>(
397397
InheritanceQuery::derived == type.entityHash);
398+
auto inheritanceCount = _ctx.db->query_value<model::CppInheritanceCount>(
399+
InheritanceQuery::derived == type.entityHash);
398400

399401
// Count unique attribute types
400402
// and unique types in function parameters and local variables
@@ -426,7 +428,7 @@ void CppMetricsParser::efferentTypeLevel()
426428
model::CppAstNodeMetrics metric;
427429
metric.astNodeId = type.astNodeId;
428430
metric.type = model::CppAstNodeMetrics::Type::EFFERENT_TYPE;
429-
metric.value = inheritanceView.size() + dependentTypes.size();
431+
metric.value = inheritanceCount.count + dependentTypes.size();
430432
_ctx.db->persist(metric);
431433

432434
auto typeRelationInserter = [this](const std::uint64_t& entityHash, const std::uint64_t& dependencyHash)
@@ -555,19 +557,19 @@ void CppMetricsParser::efferentModuleLevel()
555557
{
556558
util::OdbTransaction{_ctx.db}([&, this]
557559
{
558-
typedef odb::query<cc::model::CppDistinctTypeDependencyMetricsPathView> TypeDependencyQuery;
559-
typedef odb::result<cc::model::CppDistinctTypeDependencyMetricsPathView> TypeDependencyResult;
560+
typedef odb::query<model::CppTypeDependencyMetricsPathViewDistinctCount> TypeDependencyQuery;
561+
typedef model::CppTypeDependencyMetricsPathViewDistinctCount TypeDependencyResult;
560562

561563
for (const model::File& file : tasks)
562564
{
563-
TypeDependencyResult types = _ctx.db->query<model::CppDistinctTypeDependencyMetricsPathView>(
565+
TypeDependencyResult types = _ctx.db->query_value<model::CppTypeDependencyMetricsPathViewDistinctCount>(
564566
TypeDependencyQuery::EntityFile::path.like(file.path + '%') &&
565567
!TypeDependencyQuery::DependencyFile::path.like(file.path + '%'));
566568

567569
model::CppFileMetrics metric;
568570
metric.file = file.id;
569571
metric.type = model::CppFileMetrics::Type::EFFERENT_MODULE;
570-
metric.value = types.size();
572+
metric.value = types.count;
571573
_ctx.db->persist(metric);
572574
}
573575
});

0 commit comments

Comments
 (0)