diff options
author | Uwe Klotz <uklotz@mixxx.org> | 2020-12-27 14:18:56 +0100 |
---|---|---|
committer | Uwe Klotz <uklotz@mixxx.org> | 2020-12-27 14:21:00 +0100 |
commit | d49e7cef64ab592f6ba9ce0d9d2c34033e636347 (patch) | |
tree | eb298b409409480f858a4d92806f079ed9215dd0 /src/library | |
parent | 6255bb1f40e5887ea268c68cb3c5a533bde816ca (diff) |
LibraryScanner: Extract db cleanup into function
Diffstat (limited to 'src/library')
-rw-r--r-- | src/library/scanner/libraryscanner.cpp | 56 |
1 files changed, 29 insertions, 27 deletions
diff --git a/src/library/scanner/libraryscanner.cpp b/src/library/scanner/libraryscanner.cpp index 4e63cae6d5..f75e24c246 100644 --- a/src/library/scanner/libraryscanner.cpp +++ b/src/library/scanner/libraryscanner.cpp @@ -38,6 +38,34 @@ int execCleanupQuery(FwdSqlQuery& query) { return query.numRowsAffected(); } +/// Clean up the database and fix inconsistencies from previous runs. +/// See also: https://bugs.launchpad.net/mixxx/+bug/1846945 +void cleanUpDatabase(const QSqlDatabase& database) { + kLogger.info() + << "Cleaning up database..."; + PerformanceTimer timer; + timer.start(); + const auto sqlStmt = QStringLiteral( + "DELETE FROM LibraryHashes WHERE hash<>:unequalHash " + "AND directory_path NOT IN " + "(SELECT directory FROM track_locations)"); + FwdSqlQuery query(database, sqlStmt); + query.bindValue( + QStringLiteral(":unequalHash"), + static_cast<mixxx::cache_key_signed_t>(mixxx::invalidCacheKey())); + auto numRows = execCleanupQuery(query); + if (numRows < 0) { + kLogger.warning() + << "Failed to delete orphaned directory hashes"; + } else if (numRows > 0) { + kLogger.info() + << "Deleted" << numRows << "orphaned directory hashes"; + } + kLogger.info() + << "Finished database cleanup:" + << timer.elapsed().debugMillisWithUnit(); +} + } // anonymous namespace LibraryScanner::LibraryScanner( @@ -132,33 +160,7 @@ void LibraryScanner::slotStartScan() { kLogger.debug() << "slotStartScan()"; DEBUG_ASSERT(m_state == STARTING); - // Clean up the database and fix inconsistencies from previous runs. - // See also: https://bugs.launchpad.net/mixxx/+bug/1846945 - { - kLogger.info() - << "Cleaning up database before scanning..."; - PerformanceTimer timer; - timer.start(); - const auto sqlStmt = QStringLiteral( - "DELETE FROM LibraryHashes WHERE hash <> :unequalHash " - "AND directory_path NOT IN " - "(SELECT directory FROM track_locations)"); - FwdSqlQuery query(m_libraryHashDao.database(), sqlStmt); - query.bindValue( - QStringLiteral(":unequalHash"), - static_cast<mixxx::cache_key_signed_t>(mixxx::invalidCacheKey())); - auto numRows = execCleanupQuery(query); - if (numRows < 0) { - kLogger.warning() - << "Failed to delete orphaned directory hashes"; - } else if (numRows > 0) { - kLogger.info() - << "Deleted" << numRows << "orphaned directory hashes)"; - } - kLogger.info() - << "Finished database cleanup:" - << timer.elapsed().debugMillisWithUnit(); - } + cleanUpDatabase(m_libraryHashDao.database()); // Recursively scan each directory in the directories table. m_libraryRootDirs = m_directoryDao.getDirs(); |