Optimize database during scan to ease very large DB imports
This commit is contained in:
@@ -187,4 +187,14 @@ namespace Database
|
||||
LMS_LOG(DB, INFO) << "Database Analyze complete";
|
||||
}
|
||||
|
||||
void Session::optimize()
|
||||
{
|
||||
LMS_LOG(DB, INFO) << "Optimizing database...";
|
||||
{
|
||||
auto uniqueTransaction{ createUniqueTransaction() };
|
||||
_session.execute("PRAGMA optimize");
|
||||
}
|
||||
LMS_LOG(DB, INFO) << "Database optimizing complete";
|
||||
}
|
||||
|
||||
} // namespace Database
|
||||
|
||||
@@ -61,6 +61,7 @@ namespace Database
|
||||
void checkSharedLocked();
|
||||
|
||||
void analyze();
|
||||
void optimize();
|
||||
|
||||
void prepareTables(); // need to run only once at startup
|
||||
|
||||
|
||||
@@ -307,6 +307,10 @@ namespace Scanner
|
||||
|
||||
context.currentStepStats.processedElems++;
|
||||
_progressCallback(context.currentStepStats);
|
||||
|
||||
// optimize the database during scan (if we import a very large database, it may be too late to do it once at end)
|
||||
if ((context.stats.nbChanges() % 5'000) == 0)
|
||||
_db.getTLSSession().optimize();
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user