@@ -14,8 +14,10 @@ namespace service
1414namespace cppmetrics
1515{
1616
17- typedef odb::query<cc::model::CppAstNode> AstQuery;
18- typedef odb::result<cc::model::CppAstNode> AstResult;
17+ typedef odb::query<model::CppAstNodeMetricsForPathView> CppNodeMetricsQuery;
18+ typedef odb::result<model::CppAstNodeMetricsForPathView> CppNodeMetricsResult;
19+ typedef odb::query<model::CppModuleMetricsForPathView> CppModuleMetricsQuery;
20+ typedef odb::result<model::CppModuleMetricsForPathView> CppModuleMetricsResult;
1921
2022CppMetricsServiceHandler::CppMetricsServiceHandler (
2123 std::shared_ptr<odb::database> db_,
@@ -137,18 +139,12 @@ void CppMetricsServiceHandler::getCppMetricsForModule(
137139 });
138140}
139141
140- void CppMetricsServiceHandler::getCppAstNodeMetricsForPath (
142+ void CppMetricsServiceHandler::queryCppAstNodeMetricsForPath (
141143 std::map<core::AstNodeId, std::vector<CppMetricsAstNodeSingle>>& _return,
142- const std::string& path_ )
144+ const odb::query<model::CppAstNodeMetricsForPathView>& query_ )
143145{
144146 _transaction ([&, this ](){
145- typedef odb::query<model::CppAstNodeFilePath> CppAstNodeFilePathQuery;
146- typedef odb::result<model::CppAstNodeFilePath> CppAstNodeFilePathResult;
147- typedef odb::query<model::CppAstNodeMetricsForPathView> CppAstNodeMetricsForPathViewQuery;
148- typedef odb::result<model::CppAstNodeMetricsForPathView> CppAstNodeMetricsForPathViewResult;
149-
150- auto nodes = _db->query <model::CppAstNodeMetricsForPathView>(
151- CppAstNodeFilePathQuery::LocFile::path.like (path_ + ' %' ));
147+ auto nodes = _db->query <model::CppAstNodeMetricsForPathView>(query_);
152148
153149 for (const auto & node : nodes)
154150 {
@@ -171,18 +167,33 @@ void CppMetricsServiceHandler::getCppAstNodeMetricsForPath(
171167 });
172168}
173169
174- void CppMetricsServiceHandler::getCppAstNodeMetricsDetailedForPath (
175- std::map<core::AstNodeId, CppMetricsAstNodeDetailed >& _return,
170+ void CppMetricsServiceHandler::getCppAstNodeMetricsForPath (
171+ std::map<core::AstNodeId, std::vector<CppMetricsAstNodeSingle> >& _return,
176172 const std::string& path_)
177173{
178- _transaction ([&, this ](){
179- typedef odb::query<model::CppAstNodeFilePath> CppAstNodeFilePathQuery;
180- typedef odb::result<model::CppAstNodeFilePath> CppAstNodeFilePathResult;
181- typedef odb::query<model::CppAstNodeMetricsAndDataForPathView> CppAstNodeMetricsAndDataForPathViewQuery;
182- typedef odb::result<model::CppAstNodeMetricsAndDataForPathView> CppAstNodeMetricsAndDataForPathViewResult;
174+ queryCppAstNodeMetricsForPath (_return,
175+ CppNodeMetricsQuery::LocFile::path.like (path_ + ' %' ));
176+ }
177+
178+ void CppMetricsServiceHandler::getPagedCppAstNodeMetricsForPath (
179+ std::map<core::AstNodeId, std::vector<CppMetricsAstNodeSingle>>& _return,
180+ const std::string& path_,
181+ const std::int32_t pageSize_,
182+ const std::int32_t pageNumber_)
183+ {
184+ std::vector<model::CppAstNodeId> paged_nodes = pageMetrics<model::CppAstNodeId, model::CppAstNodeMetricsDistinctView>(
185+ path_, pageSize_, pageNumber_);
186+
187+ queryCppAstNodeMetricsForPath (_return,
188+ CppNodeMetricsQuery::CppAstNodeMetrics::astNodeId.in_range (paged_nodes.begin (), paged_nodes.end ()));
189+ }
183190
184- auto nodes = _db->query <model::CppAstNodeMetricsAndDataForPathView>(
185- CppAstNodeFilePathQuery::LocFile::path.like (path_ + ' %' ));
191+ void CppMetricsServiceHandler::queryCppAstNodeMetricsDetailedForPath (
192+ std::map<core::AstNodeId, CppMetricsAstNodeDetailed>& _return,
193+ const odb::query<model::CppAstNodeMetricsAndDataForPathView>& query_)
194+ {
195+ _transaction ([&, this ](){
196+ auto nodes = _db->query <model::CppAstNodeMetricsAndDataForPathView>(query_);
186197
187198 for (const auto & node : nodes)
188199 {
@@ -210,16 +221,33 @@ void CppMetricsServiceHandler::getCppAstNodeMetricsDetailedForPath(
210221 });
211222}
212223
213- void CppMetricsServiceHandler::getCppFileMetricsForPath (
214- std::map<core::FileId, std::vector<CppMetricsModuleSingle> >& _return,
224+ void CppMetricsServiceHandler::getCppAstNodeMetricsDetailedForPath (
225+ std::map<core::AstNodeId, CppMetricsAstNodeDetailed >& _return,
215226 const std::string& path_)
216227{
217- _transaction ([&, this ](){
218- typedef odb::query<model::CppModuleMetricsForPathView> CppModuleMetricsQuery;
219- typedef odb::result<model::CppModuleMetricsForPathView> CppModuleMetricsResult;
228+ queryCppAstNodeMetricsDetailedForPath (_return,
229+ CppNodeMetricsQuery::LocFile::path.like (path_ + ' %' ));
230+ }
231+
232+ void CppMetricsServiceHandler::getPagedCppAstNodeMetricsDetailedForPath (
233+ std::map<core::AstNodeId, CppMetricsAstNodeDetailed>& _return,
234+ const std::string& path_,
235+ const std::int32_t pageSize_,
236+ const std::int32_t pageNumber_)
237+ {
238+ std::vector<model::CppAstNodeId> paged_nodes = pageMetrics<model::CppAstNodeId, model::CppAstNodeMetricsDistinctView>(
239+ path_, pageSize_, pageNumber_);
220240
221- auto files = _db->query <model::CppModuleMetricsForPathView>(
222- CppModuleMetricsQuery::File::path.like (path_ + ' %' ));
241+ queryCppAstNodeMetricsDetailedForPath (_return,
242+ CppNodeMetricsQuery::CppAstNodeMetrics::astNodeId.in_range (paged_nodes.begin (), paged_nodes.end ()));
243+ }
244+
245+ void CppMetricsServiceHandler::queryCppFileMetricsForPath (
246+ std::map<core::FileId, std::vector<CppMetricsModuleSingle>>& _return,
247+ const odb::query<model::CppModuleMetricsForPathView>& query_)
248+ {
249+ _transaction ([&, this ](){
250+ auto files = _db->query <model::CppModuleMetricsForPathView>(query_);
223251
224252 for (const auto & file : files)
225253 {
@@ -242,6 +270,47 @@ void CppMetricsServiceHandler::getCppFileMetricsForPath(
242270 });
243271}
244272
273+ void CppMetricsServiceHandler::getCppFileMetricsForPath (
274+ std::map<core::FileId, std::vector<CppMetricsModuleSingle>>& _return,
275+ const std::string& path_)
276+ {
277+ queryCppFileMetricsForPath (_return,
278+ CppModuleMetricsQuery::File::path.like (path_ + ' %' ));
279+ }
280+
281+ void CppMetricsServiceHandler::getPagedCppFileMetricsForPath (
282+ std::map<core::FileId, std::vector<CppMetricsModuleSingle>>& _return,
283+ const std::string& path_,
284+ const std::int32_t pageSize_,
285+ const std::int32_t pageNumber_)
286+ {
287+ std::vector<model::FileId> paged_files = pageMetrics<model::FileId, model::CppModuleMetricsDistinctView>(path_, pageSize_, pageNumber_);
288+ queryCppFileMetricsForPath (_return,
289+ CppModuleMetricsQuery::CppFileMetrics::file.in_range (paged_files.begin (), paged_files.end ()));
290+ }
291+
292+ std::string CppMetricsServiceHandler::getPagingQuery (
293+ const std::int32_t pageSize_,
294+ const std::int32_t pageNumber_)
295+ {
296+ if (pageSize_ <= 0 )
297+ {
298+ core::InvalidInput ex;
299+ ex.__set_msg (" Invalid page size: " + std::to_string (pageSize_));
300+ throw ex;
301+ }
302+
303+ if (pageNumber_ <= 0 )
304+ {
305+ core::InvalidInput ex;
306+ ex.__set_msg (" Invalid page number: " + std::to_string (pageNumber_));
307+ throw ex;
308+ }
309+
310+ const std::int32_t offset = (pageNumber_ - 1 ) * pageSize_;
311+ return " LIMIT " + std::to_string (pageSize_) + " OFFSET " + std::to_string (offset);
312+ }
313+
245314} // cppmetrics
246315} // service
247316} // cc
0 commit comments