Skip to content

Commit

Permalink
Merge branch 'release-3.5.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
crsib committed Apr 11, 2024
2 parents 7b46f37 + ea926c5 commit 16df49d
Show file tree
Hide file tree
Showing 77 changed files with 317,757 additions and 287,598 deletions.
135 changes: 126 additions & 9 deletions libraries/lib-cloud-audiocom/sync/CloudProjectsDatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace audacity::cloud::audiocom::sync
{
namespace
{
const auto createTableQuery = R"(
const char* createTableQuery = R"(
CREATE TABLE IF NOT EXISTS projects
(
project_id TEXT,
Expand Down Expand Up @@ -87,10 +87,23 @@ CREATE TABLE IF NOT EXISTS project_users
user_name TEXT,
PRIMARY KEY (project_id)
);
CREATE TABLE IF NOT EXISTS migration
(
version INTEGER
);
INSERT OR IGNORE INTO migration (version) VALUES (0);
)";

}
const auto addProjectSyncedDialogShownColumn = R"(
ALTER TABLE projects ADD COLUMN synced_dialog_shown INTEGER DEFAULT 1;
)";

const char* migrations[] = {
addProjectSyncedDialogShownColumn,
};
} // namespace

CloudProjectsDatabase& CloudProjectsDatabase::Get()
{
Expand Down Expand Up @@ -123,7 +136,7 @@ CloudProjectsDatabase::GetProjectData(std::string_view projectId) const
return {};

auto statement = connection->CreateStatement(
"SELECT project_id, snapshot_id, saves_count, last_audio_preview_save, local_path, last_modified, last_read, sync_status FROM projects WHERE project_id = ? LIMIT 1");
"SELECT project_id, snapshot_id, saves_count, last_audio_preview_save, local_path, last_modified, last_read, sync_status, synced_dialog_shown FROM projects WHERE project_id = ? LIMIT 1");

if (!statement)
return {};
Expand All @@ -140,7 +153,7 @@ std::optional<DBProjectData> CloudProjectsDatabase::GetProjectDataForPath(
return {};

auto statement = connection->CreateStatement(
"SELECT project_id, snapshot_id, saves_count, last_audio_preview_save, local_path, last_modified, last_read, sync_status FROM projects WHERE local_path = ? LIMIT 1");
"SELECT project_id, snapshot_id, saves_count, last_audio_preview_save, local_path, last_modified, last_read, sync_status, synced_dialog_shown FROM projects WHERE local_path = ? LIMIT 1");

if (!statement)
return {};
Expand All @@ -159,7 +172,7 @@ cloud::audiocom::sync::CloudProjectsDatabase::GetCloudProjects() const
return result;

auto statement = connection->CreateStatement(
"SELECT project_id, snapshot_id, saves_count, last_audio_preview_save, local_path, last_modified, last_read, sync_status FROM projects");
"SELECT project_id, snapshot_id, saves_count, last_audio_preview_save, local_path, last_modified, last_read, sync_status, synced_dialog_shown FROM projects");

if (!statement)
return result;
Expand Down Expand Up @@ -319,7 +332,7 @@ bool CloudProjectsDatabase::UpdateProjectData(const DBProjectData& projectData)
return false;

auto statement = connection->CreateStatement(
"INSERT OR REPLACE INTO projects (project_id, snapshot_id, saves_count, last_audio_preview_save, local_path, last_modified, last_read, sync_status) VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
"INSERT OR REPLACE INTO projects (project_id, snapshot_id, saves_count, last_audio_preview_save, local_path, last_modified, last_read, sync_status, synced_dialog_shown) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)");

if (!statement)
return false;
Expand All @@ -329,12 +342,59 @@ bool CloudProjectsDatabase::UpdateProjectData(const DBProjectData& projectData)
projectData.ProjectId, projectData.SnapshotId,
projectData.SavesCount, projectData.LastAudioPreview,
projectData.LocalPath, projectData.LastModified,
projectData.LastRead, projectData.SyncStatus)
projectData.LastRead, projectData.SyncStatus,
projectData.FirstSyncDialogShown)
.Run();

return result.IsOk();
}

bool cloud::audiocom::sync::CloudProjectsDatabase::IsFirstSyncDialogShown(
std::string_view projectId) const
{
auto connection = GetConnection();

if (!connection)
return false;

auto statement = connection->CreateStatement (
"SELECT synced_dialog_shown FROM projects WHERE project_id = ? LIMIT 1");

if (!statement)
return false;

auto result = statement->Prepare(projectId).Run();

for (auto row : result)
{
bool shown;

if (!row.Get(0, shown))
return false;

return shown;
}

return false;
}

void cloud::audiocom::sync::CloudProjectsDatabase::SetFirstSyncDialogShown(
std::string_view projectId, bool shown)
{
auto connection = GetConnection();

if (!connection)
return;

auto statement = connection->CreateStatement (
"UPDATE projects SET synced_dialog_shown = ? WHERE project_id = ?");

if (!statement)
return;

statement->Prepare(shown, projectId).Run();
}

std::string
CloudProjectsDatabase::GetProjectUserSlug(std::string_view projectId)
{
Expand Down Expand Up @@ -717,6 +777,9 @@ CloudProjectsDatabase::DoGetProjectData(const sqlite::Row& row) const

data.SyncStatus = static_cast<DBProjectData::SyncStatusType>(status);

if (!row.Get(8, data.FirstSyncDialogShown))
return {};

return data;
}

Expand Down Expand Up @@ -746,14 +809,68 @@ bool CloudProjectsDatabase::OpenConnection()
if (!mConnection)
return false;

auto result = mConnection->Acquire()->Execute(createTableQuery);
auto connection = mConnection->Acquire();

auto result = connection->Execute(createTableQuery);

if (!result)
{
mConnection = {};
return false;
}

return true;
return RunMigrations();
}

bool CloudProjectsDatabase::RunMigrations()
{
auto connection = mConnection->Acquire();

auto getMigrationVersion =
connection->CreateStatement("SELECT version FROM migration LIMIT 1");

if (!getMigrationVersion)
return false;

auto versionResult = getMigrationVersion->Prepare().Run();

if (!versionResult.IsOk())
return false;

int version = 0;

for (auto row : versionResult)
{
if (!row.Get(0, version))
return false;
break;
}

const auto migrationsCount = std::size(migrations);

if (version >= migrationsCount)
return true;

auto tx = connection->BeginTransaction("RunMigrations");

for (int i = version; i < migrationsCount; ++i)
{
auto result = connection->Execute(migrations[i]);

if (!result)
return false;
}

auto updateVersion =
connection->CreateStatement("UPDATE migration SET version = ?");

if (!updateVersion)
return false;

if (!updateVersion->Prepare(migrationsCount).Run().IsOk())
return false;

return tx.Commit().IsOk();
}

} // namespace audacity::cloud::audiocom::sync
6 changes: 6 additions & 0 deletions libraries/lib-cloud-audiocom/sync/CloudProjectsDatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ struct DBProjectData final
int64_t LastModified = 0;
int64_t LastRead = 0;

bool FirstSyncDialogShown { false };

enum SyncStatusType
{
SyncStatusSynced = 0,
Expand Down Expand Up @@ -108,6 +110,9 @@ class CloudProjectsDatabase final

bool UpdateProjectData(const DBProjectData& projectData);

bool IsFirstSyncDialogShown(std::string_view projectId) const;
void SetFirstSyncDialogShown(std::string_view projectId, bool shown = true);

std::string GetProjectUserSlug(std::string_view projectId);
void SetProjectUserSlug(std::string_view projectId, std::string_view slug);

Expand Down Expand Up @@ -142,6 +147,7 @@ class CloudProjectsDatabase final
DoGetProjectData(sqlite::RunResult result) const;

bool OpenConnection();
bool RunMigrations();

std::mutex mConnectionMutex;
std::shared_ptr<sqlite::SafeConnection> mConnection;
Expand Down
20 changes: 20 additions & 0 deletions libraries/lib-cloud-audiocom/sync/ProjectCloudExtension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,26 @@ ProjectSyncStatus ProjectCloudExtension::GetCurrentSyncStatus() const
return mLastStatus.Status;
}

bool ProjectCloudExtension::IsFirstSyncDialogShown() const
{
auto lock = std::lock_guard { mIdentifiersMutex };

if (mProjectId.empty())
return false;

return CloudProjectsDatabase::Get().IsFirstSyncDialogShown(mProjectId);
}

void ProjectCloudExtension::SetFirstSyncDialogShown(bool shown)
{
auto lock = std::lock_guard { mIdentifiersMutex };

if (mProjectId.empty())
return;

CloudProjectsDatabase::Get().SetFirstSyncDialogShown(mProjectId, shown);
}

bool CloudStatusChangedMessage::IsSyncing() const noexcept
{
return Status == ProjectSyncStatus::Syncing;
Expand Down
3 changes: 3 additions & 0 deletions libraries/lib-cloud-audiocom/sync/ProjectCloudExtension.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ class CLOUD_AUDIOCOM_API ProjectCloudExtension final : public ClientData::Base

ProjectSyncStatus GetCurrentSyncStatus() const;

bool IsFirstSyncDialogShown() const;
void SetFirstSyncDialogShown(bool shown = true);

private:
struct UploadQueueElement;
struct CloudStatusChangedNotifier;
Expand Down
3 changes: 3 additions & 0 deletions libraries/lib-cloud-audiocom/sync/RemoteProjectSnapshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,9 @@ void RemoteProjectSnapshot::MarkProjectInDB(bool successfulDownload)
if (data.SavesCount == 0)
data.SavesCount = 1;

// For the downloaded projects - we don't need to show the dialog
data.FirstSyncDialogShown = true;

db.UpdateProjectData(data);

if (successfulDownload)
Expand Down
2 changes: 0 additions & 2 deletions libraries/lib-concurrency/concurrency/CancellationContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
* SPDX-FileContributor: Dmitry Vedenko
*/

#pragma once

#include "CancellationContext.h"

#include <algorithm>
Expand Down
5 changes: 5 additions & 0 deletions libraries/lib-sqlite-helpers/sqlite/Statement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ RunContext::Bind(int index, long long value)
return DoBind([&] { return sqlite3_bind_int64(*mStatement, index, value); });
}

RunContext& sqlite::RunContext::Bind(int index, std::size_t value)
{
return DoBind([&] { return sqlite3_bind_int64(*mStatement, index, value); });
}

RunContext&
RunContext::Bind(int index, float value)
{
Expand Down
1 change: 1 addition & 0 deletions libraries/lib-sqlite-helpers/sqlite/Statement.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ class SQLITE_HELPERS_API RunContext final
RunContext& Bind(int index, int value);
RunContext& Bind(int index, long value);
RunContext& Bind(int index, long long value);
RunContext& Bind(int index, std::size_t value);
RunContext& Bind(int index, float value);
RunContext& Bind(int index, double value);

Expand Down
Loading

0 comments on commit 16df49d

Please sign in to comment.