Skip to content

Commit

Permalink
[style] speed up importXML() by using SQL transaction
Browse files Browse the repository at this point in the history
Gains are significant, importing 100 symbols would take 2.86s,
but takes only 0.18s when using transaction.
  • Loading branch information
nirvn committed Nov 22, 2016
1 parent bc130be commit 0a0b3a7
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/core/symbology-ng/qgsstyle.cpp
Expand Up @@ -1555,6 +1555,11 @@ bool QgsStyle::importXml( const QString& filename )
QDomElement symbolsElement = docEl.firstChildElement( QStringLiteral( "symbols" ) );
QDomElement e = symbolsElement.firstChildElement();

// gain speed by re-grouping the INSERT statements in a transaction
char* query;
query = sqlite3_mprintf( "BEGIN TRANSACTION;" );
runEmptyQuery( query );

if ( version == STYLE_CURRENT_VERSION )
{
// For the new style, load symbols individualy
Expand Down Expand Up @@ -1639,6 +1644,9 @@ bool QgsStyle::importXml( const QString& filename )
e = e.nextSiblingElement();
}

query = sqlite3_mprintf( "COMMIT TRANSACTION;" );
runEmptyQuery( query );

mFileName = filename;
return true;
}
Expand Down

0 comments on commit 0a0b3a7

Please sign in to comment.