Skip to content

Commit

Permalink
Extends plugin parsers with the capability to decide whether they wou…
Browse files Browse the repository at this point in the history
…ld like to run before or after DB indexing.
  • Loading branch information
mcserep committed Jun 20, 2024
1 parent 0b7517d commit a42d30e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
10 changes: 10 additions & 0 deletions parser/include/parser/abstractparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ class AbstractParser
* @return Returns true if the parse succeeded, false otherwise.
*/
virtual bool parse() = 0;
/**
* Returns true in case database indices are required for the parser, due to performance reasons.
*
* Should return the same value on each call for the same object.
* @return
*/
virtual bool isDatabaseIndexRequired() const
{
return false;
}

protected:
ParserContext& _ctx;
Expand Down
19 changes: 17 additions & 2 deletions parser/src/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,18 +411,33 @@ int main(int argc, char* argv[])
incrementalCleanup(ctx);
}

std::vector<std::string> afterIndexingPlugins;

// TODO: Handle errors returned by parse().
for (const std::string& pluginName : pluginNames)
{
LOG(info) << "[" << pluginName << "] parse started!";
pHandler.getParser(pluginName)->parse();
auto plugin = pHandler.getParser(pluginName);
if (!plugin->isDatabaseIndexRequired())
{
LOG(info) << "[" << pluginName << "] parse started!";
plugin->parse();
}
else {
afterIndexingPlugins.push_back(pluginName);
}
}

//--- Add indexes to the database ---//

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

for (const std::string& pluginName : afterIndexingPlugins)
{
LOG(info) << "[" << pluginName << "] parse started!";
pHandler.getParser(pluginName)->parse();
}

//--- Create project config file ---//

boost::property_tree::ptree pt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ class CppMetricsParser : public AbstractParser
virtual bool cleanupDatabase() override;
virtual bool parse() override;

virtual bool isDatabaseIndexRequired() const override
{
return true;
}

private:
// Calculate the count of parameters for every function.
void functionParameters();
Expand Down

0 comments on commit a42d30e

Please sign in to comment.