1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-16 16:10:06 +02:00

AUP3: Deal with a couple of delays

The first was due to a left over bit of code in Compact and has
been removed.

The second is in SaveProject. This one can't be removed, so a
progress dialog was added.
This commit is contained in:
Leland Lucius 2020-07-29 09:00:38 -05:00
parent 0a4cae3a67
commit 863be98ccd
2 changed files with 44 additions and 16 deletions

View File

@ -68,11 +68,7 @@ bool DBConnection::Open(const char *fileName)
} }
// Set default mode // Set default mode
// // (See comments in ProjectFileIO::SaveProject() about threading
// NOTE: There is a noticable delay here when dealing with large multi-hour projects
// that were just created with "Save As". Presumably this is because of the
// journal mode switch from NONE to WAL. Should it be wrapped in a progress
// dialog?
SafeMode(); SafeMode();
// Kick off the checkpoint thread // Kick off the checkpoint thread

View File

@ -1015,11 +1015,6 @@ void ProjectFileIO::Compact(const std::shared_ptr<TrackList> &tracks, bool force
} }
} }
// Create the project doc
ProjectSerializer doc;
WriteXMLHeader(doc);
WriteXML(doc, false, tracks);
wxString origName = mFileName; wxString origName = mFileName;
wxString backName = origName + "_compact_back"; wxString backName = origName + "_compact_back";
wxString tempName = origName + "_compact_temp"; wxString tempName = origName + "_compact_temp";
@ -1047,6 +1042,7 @@ void ProjectFileIO::Compact(const std::shared_ptr<TrackList> &tracks, bool force
return; return;
} }
wxRenameFile(backName, origName); wxRenameFile(backName, origName);
} }
@ -1883,15 +1879,51 @@ bool ProjectFileIO::SaveProject(const FilePath &fileName, const std::shared_ptr<
// Open the newly created database // Open the newly created database
Connection newConn = std::make_unique<DBConnection>(mProject.shared_from_this()); Connection newConn = std::make_unique<DBConnection>(mProject.shared_from_this());
if (!newConn->Open(fileName))
// NOTE: There is a noticeable delay here when dealing with large multi-hour
// projects that we just created. The delay occurs in Open() when it
// calls SafeMode() and is due to the switch from the NONE journal mode
// to the WAL journal mode.
//
// So, we do the Open() in a thread and display a progress dialog. Since
// this is currently the only known instance where this occurs, we do the
// threading here. If more instances are identified, then the threading
// should be moved to DBConnection::Open(), wrapping the SafeMode() call
// there.
{ {
SetDBError( std::atomic_bool done = false;
XO("Failed to open copy of project file") bool success = false;
); auto thread = std::thread([&]
{
success = newConn->Open(fileName);
done = true;
});
newConn = nullptr; // Provides a progress dialog with indeterminate mode
wxGenericProgressDialog pd(XO("Syncing").Translation(),
XO("This may take several seconds").Translation(),
300000, // range
nullptr, // parent
wxPD_APP_MODAL | wxPD_ELAPSED_TIME | wxPD_SMOOTH);
return false; // Wait for the checkpoints to end
while (!done)
{
wxMilliSleep(50);
pd.Pulse();
}
thread.join();
if (!success)
{
SetDBError(
XO("Failed to open copy of project file")
);
newConn = nullptr;
return false;
}
} }
// Autosave no longer needed in original project file // Autosave no longer needed in original project file