Skip to content
Permalink
Browse files

[style] speed up importXML() by using SQL transaction

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 0a0b3a70cc27e6673e6d4500c48b04db63ede288
Showing with 8 additions and 0 deletions.
  1. +8 −0 src/core/symbology-ng/qgsstyle.cpp
@@ -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
@@ -1639,6 +1644,9 @@ bool QgsStyle::importXml( const QString& filename )
e = e.nextSiblingElement();
}

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

mFileName = filename;
return true;
}

0 comments on commit 0a0b3a7

Please sign in to comment.
You can’t perform that action at this time.