File tree Expand file tree Collapse file tree 4 files changed +53
-7
lines changed Expand file tree Collapse file tree 4 files changed +53
-7
lines changed Original file line number Diff line number Diff line change 5
5
6
6
#include < util/hash.h>
7
7
#include < util/logutil.h>
8
+ #include < util/dbutil.h>
8
9
9
10
#include < parser/sourcemanager.h>
10
11
@@ -238,9 +239,9 @@ void SourceManager::removeFile(const model::File& file_)
238
239
_transaction ([&]() {
239
240
if (file_.content )
240
241
{
241
- auto relFiles = _db->query <model::File>(
242
+ odb::result<model::File> relFiles = _db->query <model::File>(
242
243
odb::query<model::File>::content == file_.content .object_id ());
243
- if (relFiles. size () == 1 )
244
+ if (util::isSingleResult (relFiles) )
244
245
{
245
246
removeContent = true ;
246
247
_db->erase <model::FileContent>(file_.content .object_id ());
Original file line number Diff line number Diff line change @@ -45,6 +45,19 @@ struct CppRecordMetricsView
45
45
double value;
46
46
};
47
47
48
+ #pragma db view \
49
+ object (CppAstNodeMetrics) \
50
+ object (CppAstNode : CppAstNodeMetrics::astNodeId == CppAstNode::id) \
51
+ object (File : CppAstNode::location.file)
52
+ struct CppAstNodeMetricsFileView
53
+ {
54
+ #pragma db column(CppAstNode::id)
55
+ CppAstNodeId astNodeId;
56
+
57
+ #pragma db column(File::id)
58
+ FileId fileId;
59
+ };
60
+
48
61
#pragma db view \
49
62
object (CppAstNodeMetrics) \
50
63
object (CppAstNode : CppAstNodeMetrics::astNodeId == CppAstNode::id) \
Original file line number Diff line number Diff line change @@ -39,12 +39,10 @@ CppMetricsParser::CppMetricsParser(ParserContext& ctx_): AbstractParser(ctx_)
39
39
_fileIdCache.insert (fm.file );
40
40
}
41
41
42
- for (const model::CppAstNodeMetrics & anm
43
- : _ctx.db ->query <model::CppAstNodeMetrics >())
42
+ for (const model::CppAstNodeMetricsFileView & anm
43
+ : _ctx.db ->query <model::CppAstNodeMetricsFileView >())
44
44
{
45
- auto node = _ctx.db ->query_one <model::CppAstNode>(
46
- odb::query<model::CppAstNode>::id == anm.astNodeId );
47
- _astNodeIdCache.insert ({anm.astNodeId , node->location .file ->id });
45
+ _astNodeIdCache.emplace (anm.astNodeId , anm.fileId );
48
46
}
49
47
});
50
48
}
Original file line number Diff line number Diff line change @@ -97,6 +97,40 @@ inline std::string getDbDriver()
97
97
#endif
98
98
}
99
99
100
+ // / @brief Determines if the specified ODB query result only contains
101
+ // / a single entity. That single entity is then stored in 'single_'.
102
+ // / @tparam TEntity The type of entities in the query result.
103
+ // / @param result_ The ODB query result in question.
104
+ // / @param single_ The variable that receives the first entity (if any).
105
+ // / @return Returns true if 'result_' only contained 'single_';
106
+ // / otherwise false.
107
+ template <typename TEntity>
108
+ bool isSingleResult (odb::result<TEntity>& result_, TEntity& single_)
109
+ {
110
+ auto it_b = result_.begin ();
111
+ const auto it_e = result_.end ();
112
+ if (it_b != it_e)
113
+ {
114
+ single_ = *it_b;
115
+ return ++it_b == it_e;
116
+ }
117
+ else return false ;
118
+ }
119
+
120
+ // / @brief Determines if the specified ODB query result only contains
121
+ // / a single entity.
122
+ // / @tparam TEntity The type of entities in the query result.
123
+ // / @param result_ The ODB query result in question.
124
+ // / @return Returns true if 'result_' only contained a single entity;
125
+ // / otherwise false.
126
+ template <typename TEntity>
127
+ bool isSingleResult (odb::result<TEntity>& result_)
128
+ {
129
+ auto it_b = result_.begin ();
130
+ const auto it_e = result_.end ();
131
+ return (it_b != it_e) && (++it_b == it_e);
132
+ }
133
+
100
134
} // util
101
135
} // cc
102
136
You can’t perform that action at this time.
0 commit comments