Mercurial > dedupe
comparison SqliteDBLink.cpp @ 109:6cf5eb5b0be1
Embed batch operations in BEGIN-END TRANSACTION for speed improvement.
| author | Tom Fredrik Blenning Klaussen <bfg@bfgconsult.no> |
|---|---|
| date | Tue, 18 Feb 2014 19:41:23 +0100 |
| parents | e9b798e80bad |
| children | d4e337567960 |
comparison
equal
deleted
inserted
replaced
| 108:e9b798e80bad | 109:6cf5eb5b0be1 |
|---|---|
| 47 throw SQLException("No view"); | 47 throw SQLException("No view"); |
| 48 } | 48 } |
| 49 | 49 |
| 50 | 50 |
| 51 preparedBeginQuery = new QSqlQuery(db); | 51 preparedBeginQuery = new QSqlQuery(db); |
| 52 preparedBeginQuery->prepare("BEGIN"); | 52 preparedBeginQuery->prepare("BEGIN TRANSACTION"); |
| 53 | 53 |
| 54 preparedEndQuery = new QSqlQuery(db); | 54 preparedEndQuery = new QSqlQuery(db); |
| 55 preparedEndQuery->prepare("END"); | 55 preparedEndQuery->prepare("END TRANSACTION"); |
| 56 | 56 |
| 57 preparedSizePrefixQuery = new QSqlQuery(db); | 57 preparedSizePrefixQuery = new QSqlQuery(db); |
| 58 preparedSizePrefixQuery->prepare("SELECT * FROM files WHERE path LIKE :prefix AND size = :size"); | 58 preparedSizePrefixQuery->prepare("SELECT * FROM files WHERE path LIKE :prefix AND size = :size"); |
| 59 | 59 |
| 60 preparedSizeQuery = new QSqlQuery(db); | 60 preparedSizeQuery = new QSqlQuery(db); |
| 374 const Operation* operation = | 374 const Operation* operation = |
| 375 (operations.empty()) ? NULL : operations.takeFirst(); | 375 (operations.empty()) ? NULL : operations.takeFirst(); |
| 376 | 376 |
| 377 while (operation) { | 377 while (operation) { |
| 378 if (operation->type() != last) { | 378 if (operation->type() != last) { |
| 379 if (!preparedBeginQuery->exec()) | |
| 380 throw SQLException(*preparedBeginQuery); | |
| 379 executeOperation(paths, sizes, mtimes, hashes, last); | 381 executeOperation(paths, sizes, mtimes, hashes, last); |
| 382 if (!preparedEndQuery->exec()) | |
| 383 throw SQLException(*preparedEndQuery); | |
| 380 } | 384 } |
| 381 | 385 |
| 382 switch (operation->type()) { | 386 switch (operation->type()) { |
| 383 case Add: | 387 case Add: |
| 384 case Update: { | 388 case Update: { |
| 404 if (last != None) { | 408 if (last != None) { |
| 405 qDebug() << "Execute Operation" << typeString(last); | 409 qDebug() << "Execute Operation" << typeString(last); |
| 406 foreach(QVariant path, paths) { | 410 foreach(QVariant path, paths) { |
| 407 qDebug() << path.toString(); | 411 qDebug() << path.toString(); |
| 408 } | 412 } |
| 413 if (!preparedBeginQuery->exec()) | |
| 414 throw SQLException(*preparedBeginQuery); | |
| 409 executeOperation(paths, sizes, mtimes, hashes, last); | 415 executeOperation(paths, sizes, mtimes, hashes, last); |
| 416 if (!preparedEndQuery->exec()) | |
| 417 throw SQLException(*preparedEndQuery); | |
| 410 qDebug() << "Execute Operation Done"; | 418 qDebug() << "Execute Operation Done"; |
| 411 } | 419 } |
| 412 | 420 |
| 413 if (dirty) { | 421 if (dirty) { |
| 414 QSqlQuery whatToUpdate(db); | 422 QSqlQuery whatToUpdate(db); |
