mirror of
https://github.com/abraunegg/onedrive
synced 2024-05-21 07:06:40 +02:00
Merge contents of SQLite WAL file into main database file on sync completion (#1128)
* When using WAL and SHM files, certain thresholds are used to automatically determine when WAL and SHM data is committed to the main database file. If these thresholds are not met, the data is not written. Before terminating the program, commit the data, and at the end of each monitor loop, commit the data * Only try and write data to DB file and destroy variable if it was set to begin with * Only try and destroy 'onedrive' variable if set, rather than set to null
This commit is contained in:
parent
d2193c97f5
commit
57d6753f80
|
@ -474,4 +474,11 @@ final class ItemDatabase
|
|||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
// Perform a vacuum on the database, commit WAL / SHM to file
|
||||
void performVacuum()
|
||||
{
|
||||
auto stmt = db.prepare("VACUUM;");
|
||||
stmt.exec();
|
||||
}
|
||||
}
|
||||
|
|
43
src/main.d
43
src/main.d
|
@ -62,10 +62,16 @@ int main(string[] args)
|
|||
if (onedriveInitialised) {
|
||||
oneDrive.shutdown();
|
||||
}
|
||||
// Make sure the .wal file is incorporated into the main db before we exit
|
||||
destroy(itemDb);
|
||||
// was itemDb initialised?
|
||||
if (itemDb !is null) {
|
||||
// Make sure the .wal file is incorporated into the main db before we exit
|
||||
itemDb.performVacuum();
|
||||
destroy(itemDb);
|
||||
}
|
||||
// free API instance
|
||||
oneDrive = null;
|
||||
if (oneDrive !is null) {
|
||||
destroy(oneDrive);
|
||||
}
|
||||
// Perform Garbage Cleanup
|
||||
GC.collect();
|
||||
// Display memory details
|
||||
|
@ -83,10 +89,16 @@ int main(string[] args)
|
|||
if (onedriveInitialised) {
|
||||
oneDrive.shutdown();
|
||||
}
|
||||
// Make sure the .wal file is incorporated into the main db before we exit
|
||||
destroy(itemDb);
|
||||
// was itemDb initialised?
|
||||
if (itemDb !is null) {
|
||||
// Make sure the .wal file is incorporated into the main db before we exit
|
||||
itemDb.performVacuum();
|
||||
destroy(itemDb);
|
||||
}
|
||||
// free API instance
|
||||
oneDrive = null;
|
||||
if (oneDrive !is null) {
|
||||
destroy(oneDrive);
|
||||
}
|
||||
// Perform Garbage Cleanup
|
||||
GC.collect();
|
||||
// Display memory details
|
||||
|
@ -901,6 +913,10 @@ int main(string[] args)
|
|||
// fullScanRequired = false, for final true-up
|
||||
// but if we have sync_list configured, use syncListConfigured which = true
|
||||
performSync(sync, cfg.getValueString("single_directory"), cfg.getValueBool("download_only"), cfg.getValueBool("local_first"), cfg.getValueBool("upload_only"), LOG_NORMAL, false, syncListConfigured, displaySyncOptions, cfg.getValueBool("monitor"), m);
|
||||
|
||||
// Write WAL and SHM data to file for this sync
|
||||
log.vdebug("Merge contents of WAL and SHM files into main database file");
|
||||
itemDb.performVacuum();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1112,8 +1128,15 @@ int main(string[] args)
|
|||
if (displayMemoryUsage) {
|
||||
log.displayMemoryUsagePostGC();
|
||||
}
|
||||
|
||||
// Write WAL and SHM data to file for this loop
|
||||
log.vdebug("Merge contents of WAL and SHM files into main database file");
|
||||
itemDb.performVacuum();
|
||||
|
||||
// monitor loop complete
|
||||
logOutputMessage = "################################################ LOOP COMPLETE ###############################################";
|
||||
|
||||
// Handle display options
|
||||
if (displaySyncOptions) {
|
||||
log.log(logOutputMessage);
|
||||
} else {
|
||||
|
@ -1419,8 +1442,12 @@ extern(C) nothrow @nogc @system void exitHandler(int value) {
|
|||
try {
|
||||
assumeNoGC ( () {
|
||||
log.log("Got termination signal, shutting down db connection");
|
||||
// make sure the .wal file is incorporated into the main db
|
||||
destroy(itemDb);
|
||||
// was itemDb initialised?
|
||||
if (itemDb !is null) {
|
||||
// Make sure the .wal file is incorporated into the main db before we exit
|
||||
itemDb.performVacuum();
|
||||
destroy(itemDb);
|
||||
}
|
||||
// Use exit scopes to shutdown OneDrive API
|
||||
})();
|
||||
} catch(Exception e) {}
|
||||
|
|
Loading…
Reference in a new issue