From 48287e9b0dc739bfcc2eb97b0b09722c7c31b685 Mon Sep 17 00:00:00 2001 From: Leland Lucius Date: Thu, 2 Jul 2020 22:08:39 -0500 Subject: [PATCH] AUP3: Provides relief from slow shutdown This is a hack to fix the long delay at Audacity shutdown after editing large files and tossing the results (not saving). --- src/ProjectFileIO.cpp | 22 +++++++++++++++++----- src/ProjectFileIO.h | 25 +++++++++++++++++++++---- src/ProjectManager.cpp | 3 +++ src/SqliteSampleBlock.cpp | 39 ++++++++++++++++++++------------------- 4 files changed, 61 insertions(+), 28 deletions(-) diff --git a/src/ProjectFileIO.cpp b/src/ProjectFileIO.cpp index ff2460313..9c915992a 100644 --- a/src/ProjectFileIO.cpp +++ b/src/ProjectFileIO.cpp @@ -87,13 +87,12 @@ static const char *ProjectFileSchema = ");" "" // CREATE SQL sampleblocks - // 'samples' are fixed size blocks of float32 numbers. + // 'samples' are fixed size blocks of int16, int32 or float32 numbers. // The blocks may be partially empty. // The quantity of valid data in the blocks is // provided in the project XML. // - // sampleformat was once used to specify whether floats - // or ints for the data, but is no longer used. + // sampleformat specifies the format of the samples stored. // // blockID is a 64 bit number. // @@ -198,6 +197,8 @@ ProjectFileIO::ProjectFileIO(AudacityProject &) mModified = false; mTemporary = true; + mBypass = false; + UpdatePrefs(); } @@ -1275,13 +1276,13 @@ const TranslatableString & ProjectFileIO::GetLibraryError() const return mLibraryError; } -void ProjectFileIO::SetError(const TranslatableString & msg) +void ProjectFileIO::SetError(const TranslatableString &msg) { mLastError = msg; mLibraryError = {}; } -void ProjectFileIO::SetDBError(const TranslatableString & msg) +void ProjectFileIO::SetDBError(const TranslatableString &msg) { mLastError = msg; if (mDB) @@ -1289,3 +1290,14 @@ void ProjectFileIO::SetDBError(const TranslatableString & msg) mLibraryError = Verbatim(sqlite3_errmsg(mDB)); } } + +void ProjectFileIO::Bypass(bool bypass) +{ + mBypass = bypass; +} + +bool ProjectFileIO::ShouldBypass() +{ + return mBypass; +} + diff --git a/src/ProjectFileIO.h b/src/ProjectFileIO.h index 8f3eb2f26..e72b5f0f6 100644 --- a/src/ProjectFileIO.h +++ b/src/ProjectFileIO.h @@ -19,6 +19,7 @@ Paul Licameli split from AudacityProject.h struct sqlite3; class AudacityProject; +class AutoCommitTransaction; class AutoSaveFile; class SqliteSampleBlock; class WaveTrack; @@ -46,8 +47,6 @@ public: ProjectFileIO &operator=( const ProjectFileIO & ) PROHIBITED; ~ProjectFileIO(); - bool WarnOfLegacyFile( ); - // It seems odd to put this method in this class, but the results do depend // on what is discovered while opening the file, such as whether it is a // recovery file @@ -76,8 +75,23 @@ public: wxLongLong GetFreeDiskSpace(); - const TranslatableString & GetLastError() const; - const TranslatableString & GetLibraryError() const; + const TranslatableString &GetLastError() const; + const TranslatableString &GetLibraryError() const; + + // Provides a means to bypass "DELETE"s at shutdown if the database + // is just going to be deleted anyway. This prevents a noticable + // delay caused by SampleBlocks being deleted when the Sequences that + // own them are deleted. + // + // This is definitely hackage territory. While this ability would + // still be needed, I think handling it in a DB abstraction might be + // a tad bit cleaner. + // + // For it's usage, see: + // SqliteSampleBlock::~SqliteSampleBlock() + // ProjectManager::OnCloseWindow() + void Bypass(bool bypass); + bool ShouldBypass(); private: // XMLTagHandler callback methods @@ -128,6 +142,9 @@ private: // Is this project still a temporary/unsaved project bool mTemporary; + // Bypass transactions if database will be deleted after close + bool mBypass; + sqlite3 *mDB; FilePath mDBPath; TranslatableString mLastError; diff --git a/src/ProjectManager.cpp b/src/ProjectManager.cpp index 2ccedc9f5..c5c487e84 100644 --- a/src/ProjectManager.cpp +++ b/src/ProjectManager.cpp @@ -672,6 +672,9 @@ void ProjectManager::OnCloseWindow(wxCloseEvent & event) } } + // See ProjectFileIO::Bypass() for a description + projectFileIO.Bypass(true); + #ifdef __WXMAC__ // Fix bug apparently introduced into 2.1.2 because of wxWidgets 3: // closing a project that was made full-screen (as by clicking the green dot diff --git a/src/SqliteSampleBlock.cpp b/src/SqliteSampleBlock.cpp index 44dd15f78..79a7b9404 100644 --- a/src/SqliteSampleBlock.cpp +++ b/src/SqliteSampleBlock.cpp @@ -283,7 +283,8 @@ SqliteSampleBlock::SqliteSampleBlock(AudacityProject *project) SqliteSampleBlock::~SqliteSampleBlock() { - if (mRefCnt == 0) + // See ProjectFileIO::Bypass() for a description of mIO.mBypass + if (mRefCnt == 0 && !mIO.ShouldBypass()) { Delete(); } @@ -320,9 +321,9 @@ size_t SqliteSampleBlock::GetSampleCount() const } size_t SqliteSampleBlock::GetSamples(samplePtr dest, - sampleFormat destformat, - size_t sampleoffset, - size_t numsamples) + sampleFormat destformat, + size_t sampleoffset, + size_t numsamples) { return GetBlob(dest, destformat, @@ -333,8 +334,8 @@ size_t SqliteSampleBlock::GetSamples(samplePtr dest, } bool SqliteSampleBlock::SetSamples(samplePtr src, - size_t numsamples, - sampleFormat srcformat) + size_t numsamples, + sampleFormat srcformat) { mSampleFormat = srcformat; @@ -365,24 +366,24 @@ bool SqliteSampleBlock::SetSilent(size_t numsamples, sampleFormat srcformat) } bool SqliteSampleBlock::GetSummary256(float *dest, - size_t frameoffset, - size_t numframes) + size_t frameoffset, + size_t numframes) { return GetSummary(dest, frameoffset, numframes, "summary256", mSummary256Bytes); } bool SqliteSampleBlock::GetSummary64k(float *dest, - size_t frameoffset, - size_t numframes) + size_t frameoffset, + size_t numframes) { return GetSummary(dest, frameoffset, numframes, "summary64k", mSummary64kBytes); } bool SqliteSampleBlock::GetSummary(float *dest, - size_t frameoffset, - size_t numframes, - const char *srccolumn, - size_t srcbytes) + size_t frameoffset, + size_t numframes, + const char *srccolumn, + size_t srcbytes) { return GetBlob(dest, floatSample, @@ -472,11 +473,11 @@ size_t SqliteSampleBlock::GetSpaceUsage() const } size_t SqliteSampleBlock::GetBlob(void *dest, - sampleFormat destformat, - const char *srccolumn, - sampleFormat srcformat, - size_t srcoffset, - size_t srcbytes) + sampleFormat destformat, + const char *srccolumn, + sampleFormat srcformat, + size_t srcoffset, + size_t srcbytes) { auto db = mIO.DB();