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 55
66#include < util/hash.h>
77#include < util/logutil.h>
8+ #include < util/dbutil.h>
89
910#include < parser/sourcemanager.h>
1011
@@ -238,9 +239,9 @@ void SourceManager::removeFile(const model::File& file_)
238239 _transaction ([&]() {
239240 if (file_.content )
240241 {
241- auto relFiles = _db->query <model::File>(
242+ odb::result<model::File> relFiles = _db->query <model::File>(
242243 odb::query<model::File>::content == file_.content .object_id ());
243- if (relFiles. size () == 1 )
244+ if (util::isSingleResult (relFiles) )
244245 {
245246 removeContent = true ;
246247 _db->erase <model::FileContent>(file_.content .object_id ());
Original file line number Diff line number Diff line change @@ -45,6 +45,19 @@ struct CppRecordMetricsView
4545 double value;
4646};
4747
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+
4861#pragma db view \
4962 object (CppAstNodeMetrics) \
5063 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_)
3939 _fileIdCache.insert (fm.file );
4040 }
4141
42- for (const model::CppAstNodeMetrics & anm
43- : _ctx.db ->query <model::CppAstNodeMetrics >())
42+ for (const model::CppAstNodeMetricsFileView & anm
43+ : _ctx.db ->query <model::CppAstNodeMetricsFileView >())
4444 {
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 );
4846 }
4947 });
5048}
Original file line number Diff line number Diff line change @@ -97,6 +97,40 @@ inline std::string getDbDriver()
9797#endif
9898}
9999
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+
100134} // util
101135} // cc
102136
You can’t perform that action at this time.
0 commit comments