Skip to content

Commit 6ce7855

Browse files
authored
Merge pull request #753 from mcserep/parsing-after-indexing
Optionally run Plugin parsers after DB indexing
2 parents a375af5 + 48b431c commit 6ce7855

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

parser/include/parser/abstractparser.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ class AbstractParser
4444
* @return Returns true if the parse succeeded, false otherwise.
4545
*/
4646
virtual bool parse() = 0;
47+
/**
48+
* Returns true in case database indices are required for the parser, due to performance reasons.
49+
*
50+
* Should return the same value on each call for the same object.
51+
* @return Returns true if the database indexing has to be performed before the parser is executed.
52+
*/
53+
virtual bool isDatabaseIndexRequired() const
54+
{
55+
return false;
56+
}
4757

4858
protected:
4959
ParserContext& _ctx;

parser/src/parser.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,18 +411,33 @@ int main(int argc, char* argv[])
411411
incrementalCleanup(ctx);
412412
}
413413

414+
std::vector<std::string> afterIndexingPlugins;
415+
414416
// TODO: Handle errors returned by parse().
415417
for (const std::string& pluginName : pluginNames)
416418
{
417-
LOG(info) << "[" << pluginName << "] parse started!";
418-
pHandler.getParser(pluginName)->parse();
419+
auto plugin = pHandler.getParser(pluginName);
420+
if (!plugin->isDatabaseIndexRequired())
421+
{
422+
LOG(info) << "[" << pluginName << "] parse started!";
423+
plugin->parse();
424+
}
425+
else {
426+
afterIndexingPlugins.push_back(pluginName);
427+
}
419428
}
420429

421430
//--- Add indexes to the database ---//
422431

423432
if (vm.count("force") || isNewDb)
424433
cc::util::createIndexes(db, SQL_DIR);
425434

435+
for (const std::string& pluginName : afterIndexingPlugins)
436+
{
437+
LOG(info) << "[" << pluginName << "] parse started!";
438+
pHandler.getParser(pluginName)->parse();
439+
}
440+
426441
//--- Create project config file ---//
427442

428443
boost::property_tree::ptree pt;

plugins/cpp_metrics/parser/include/cppmetricsparser/cppmetricsparser.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ class CppMetricsParser : public AbstractParser
5959
virtual bool cleanupDatabase() override;
6060
virtual bool parse() override;
6161

62+
virtual bool isDatabaseIndexRequired() const override
63+
{
64+
return true;
65+
}
66+
6267
private:
6368
// Calculate the count of parameters for every function.
6469
void functionParameters();

0 commit comments

Comments
 (0)