Audacity 3.2.0
Public Member Functions | Public Attributes | List of all members
audacity::cloud::audiocom::sync::LocalProjectSnapshot::ProjectBlocksLock Struct Referencefinal
Inheritance diagram for audacity::cloud::audiocom::sync::LocalProjectSnapshot::ProjectBlocksLock:
[legend]
Collaboration diagram for audacity::cloud::audiocom::sync::LocalProjectSnapshot::ProjectBlocksLock:
[legend]

Public Member Functions

 ProjectBlocksLock (ProjectCloudExtension &extension, AudacityProject &project, std::function< void()> onBlocksLocked)
 
 ~ProjectBlocksLock () override
 
void VisitBlocks (TrackList &tracks)
 
void CollectHashes ()
 
void UpdateProjectHashesInCache ()
 
bool GetHash (int64_t blockId, std::string &hash) const override
 
void UpdateHash (int64_t blockId, const std::string &hash) override
 
void FillMissingBlocks (const std::vector< UploadUrls > &missingBlockUrls)
 

Public Attributes

ProjectCloudExtensionExtension
 
SampleBlockIDSet BlockIds
 
std::vector< LockedBlockBlocks
 
std::vector< BlockUploadTaskMissingBlocks
 
std::unordered_map< int64_t, size_t > BlockIdToIndex
 
std::unordered_map< std::string, size_t > BlockHashToIndex
 
std::unique_ptr< BlockHasherHasher
 
std::future< void > UpdateCacheFuture
 
std::vector< std::pair< int64_t, std::string > > NewHashes
 
std::function< void()> OnBlocksLocked
 

Additional Inherited Members

- Private Member Functions inherited from audacity::cloud::audiocom::sync::BlockHashCache
virtual ~BlockHashCache ()=default
 
virtual bool GetHash (int64_t blockId, std::string &hash) const =0
 
virtual void UpdateHash (int64_t blockId, const std::string &hash)=0
 

Detailed Description

Definition at line 48 of file LocalProjectSnapshot.cpp.

Constructor & Destructor Documentation

◆ ProjectBlocksLock()

audacity::cloud::audiocom::sync::LocalProjectSnapshot::ProjectBlocksLock::ProjectBlocksLock ( ProjectCloudExtension extension,
AudacityProject project,
std::function< void()>  onBlocksLocked 
)
inlineexplicit

Definition at line 67 of file LocalProjectSnapshot.cpp.

71 , OnBlocksLocked { std::move(onBlocksLocked) }
72 {
74
76 {
79 }
80
81 Hasher = std::make_unique<BlockHasher>();
82
83 Hasher->ComputeHashes(*this, Blocks, [this] { CollectHashes(); });
84 }
const auto project
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:314
void UpdateProjectBlockList(std::string_view projectId, const SampleBlockIDSet &blockSet)

References BlockIds, Blocks, CollectHashes(), Extension, audacity::cloud::audiocom::sync::CloudProjectsDatabase::Get(), TrackList::Get(), audacity::cloud::audiocom::sync::ProjectCloudExtension::GetCloudProjectId(), Hasher, audacity::cloud::audiocom::sync::ProjectCloudExtension::IsCloudProject(), project, audacity::cloud::audiocom::sync::CloudProjectsDatabase::UpdateProjectBlockList(), and VisitBlocks().

Here is the call graph for this function:

◆ ~ProjectBlocksLock()

audacity::cloud::audiocom::sync::LocalProjectSnapshot::ProjectBlocksLock::~ProjectBlocksLock ( )
inlineoverride

Definition at line 86 of file LocalProjectSnapshot.cpp.

87 {
88 }

Member Function Documentation

◆ CollectHashes()

void audacity::cloud::audiocom::sync::LocalProjectSnapshot::ProjectBlocksLock::CollectHashes ( )
inline

Definition at line 101 of file LocalProjectSnapshot.cpp.

102 {
103 // TakeResult() will call UpdateHash() for each block
104 // not found in the cache
105 const auto result = Hasher->TakeResult();
106
107 for (auto [id, hash] : result)
108 {
109 auto it = BlockIdToIndex.find(id);
110
111 if (it == BlockIdToIndex.end())
112 {
113 assert(false);
114 continue;
115 }
116
117 while (BlockHashToIndex.find(hash) != BlockHashToIndex.end())
118 {
119 // Hash is used by another block, rehash
120 hash = crypto::sha256(hash);
121 }
122
124 Blocks[it->second].Hash = std::move(hash);
125 }
126
127 // This will potentially block, if the cache is being updated
128 // already
130
131 if (OnBlocksLocked)
133 }
int id
std::string sha256(const T &data)
Definition: SHA256.h:50

References BlockHashToIndex, BlockIdToIndex, Blocks, Hasher, id, OnBlocksLocked, crypto::sha256(), and UpdateProjectHashesInCache().

Referenced by ProjectBlocksLock().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FillMissingBlocks()

void audacity::cloud::audiocom::sync::LocalProjectSnapshot::ProjectBlocksLock::FillMissingBlocks ( const std::vector< UploadUrls > &  missingBlockUrls)
inline

Definition at line 170 of file LocalProjectSnapshot.cpp.

171 {
172 for (const auto& urls : missingBlockUrls)
173 {
174 auto it = BlockHashToIndex.find(ToUpper(urls.Id));
175
176 if (it == BlockHashToIndex.end())
177 {
178 assert(false);
179 continue;
180 }
181
182 const auto index = it->second;
183
184 MissingBlocks.push_back(BlockUploadTask { urls, Blocks[index] });
185 }
186 }
std::string ToUpper(const std::string &str)
Definition: StringUtils.cpp:46

References BlockHashToIndex, Blocks, MissingBlocks, and ToUpper().

Here is the call graph for this function:

◆ GetHash()

bool audacity::cloud::audiocom::sync::LocalProjectSnapshot::ProjectBlocksLock::GetHash ( int64_t  blockId,
std::string &  hash 
) const
inlineoverridevirtual

Implements audacity::cloud::audiocom::sync::BlockHashCache.

Definition at line 149 of file LocalProjectSnapshot.cpp.

150 {
152 return false;
153
154 auto cachedResult = CloudProjectsDatabase::Get().GetBlockHash(
155 Extension.GetCloudProjectId(), blockId);
156
157 if (!cachedResult)
158 return false;
159
160 hash = std::move(*cachedResult);
161
162 return true;
163 }
std::optional< std::string > GetBlockHash(std::string_view projectId, int64_t blockId) const

References Extension, audacity::cloud::audiocom::sync::CloudProjectsDatabase::Get(), audacity::cloud::audiocom::sync::CloudProjectsDatabase::GetBlockHash(), audacity::cloud::audiocom::sync::ProjectCloudExtension::GetCloudProjectId(), and audacity::cloud::audiocom::sync::ProjectCloudExtension::IsCloudProject().

Here is the call graph for this function:

◆ UpdateHash()

void audacity::cloud::audiocom::sync::LocalProjectSnapshot::ProjectBlocksLock::UpdateHash ( int64_t  blockId,
const std::string &  hash 
)
inlineoverridevirtual

Implements audacity::cloud::audiocom::sync::BlockHashCache.

Definition at line 165 of file LocalProjectSnapshot.cpp.

166 {
167 NewHashes.emplace_back(blockId, hash);
168 }

References NewHashes.

◆ UpdateProjectHashesInCache()

void audacity::cloud::audiocom::sync::LocalProjectSnapshot::ProjectBlocksLock::UpdateProjectHashesInCache ( )
inline

Definition at line 135 of file LocalProjectSnapshot.cpp.

136 {
138 return;
139
140 UpdateCacheFuture = std::async(
141 std::launch::async,
142 [this, hashes = std::move(NewHashes)]
143 {
145 Extension.GetCloudProjectId(), hashes);
146 });
147 }
void UpdateBlockHashes(std::string_view projectId, const std::vector< std::pair< int64_t, std::string > > &hashes)

References Extension, audacity::cloud::audiocom::sync::CloudProjectsDatabase::Get(), audacity::cloud::audiocom::sync::ProjectCloudExtension::GetCloudProjectId(), audacity::cloud::audiocom::sync::ProjectCloudExtension::IsCloudProject(), NewHashes, audacity::cloud::audiocom::sync::CloudProjectsDatabase::UpdateBlockHashes(), and UpdateCacheFuture.

Referenced by CollectHashes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ VisitBlocks()

void audacity::cloud::audiocom::sync::LocalProjectSnapshot::ProjectBlocksLock::VisitBlocks ( TrackList tracks)
inline

Definition at line 90 of file LocalProjectSnapshot.cpp.

91 {
92 const auto visitor = [this](const SampleBlockPtr &pBlock){
93 const auto id = pBlock->GetBlockID();
94 Blocks.push_back({
95 id, pBlock->GetSampleFormat(), pBlock });
96 BlockIdToIndex[id] = Blocks.size() - 1;
97 };
99 }
std::shared_ptr< SampleBlock > SampleBlockPtr
Definition: CloudSyncDTO.h:25
const auto tracks
WAVE_TRACK_API void VisitBlocks(TrackList &tracks, BlockVisitor visitor, SampleBlockIDSet *pIDs=nullptr)

References BlockIds, BlockIdToIndex, Blocks, id, tracks, and WaveTrackUtilities::VisitBlocks().

Referenced by ProjectBlocksLock().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ BlockHashToIndex

std::unordered_map<std::string, size_t> audacity::cloud::audiocom::sync::LocalProjectSnapshot::ProjectBlocksLock::BlockHashToIndex

Definition at line 58 of file LocalProjectSnapshot.cpp.

Referenced by CollectHashes(), and FillMissingBlocks().

◆ BlockIds

SampleBlockIDSet audacity::cloud::audiocom::sync::LocalProjectSnapshot::ProjectBlocksLock::BlockIds

Definition at line 52 of file LocalProjectSnapshot.cpp.

Referenced by ProjectBlocksLock(), and VisitBlocks().

◆ BlockIdToIndex

std::unordered_map<int64_t, size_t> audacity::cloud::audiocom::sync::LocalProjectSnapshot::ProjectBlocksLock::BlockIdToIndex

Definition at line 57 of file LocalProjectSnapshot.cpp.

Referenced by CollectHashes(), and VisitBlocks().

◆ Blocks

std::vector<LockedBlock> audacity::cloud::audiocom::sync::LocalProjectSnapshot::ProjectBlocksLock::Blocks

◆ Extension

ProjectCloudExtension& audacity::cloud::audiocom::sync::LocalProjectSnapshot::ProjectBlocksLock::Extension

Definition at line 50 of file LocalProjectSnapshot.cpp.

Referenced by GetHash(), ProjectBlocksLock(), and UpdateProjectHashesInCache().

◆ Hasher

std::unique_ptr<BlockHasher> audacity::cloud::audiocom::sync::LocalProjectSnapshot::ProjectBlocksLock::Hasher

Definition at line 60 of file LocalProjectSnapshot.cpp.

Referenced by CollectHashes(), and ProjectBlocksLock().

◆ MissingBlocks

std::vector<BlockUploadTask> audacity::cloud::audiocom::sync::LocalProjectSnapshot::ProjectBlocksLock::MissingBlocks

Definition at line 55 of file LocalProjectSnapshot.cpp.

Referenced by FillMissingBlocks().

◆ NewHashes

std::vector<std::pair<int64_t, std::string> > audacity::cloud::audiocom::sync::LocalProjectSnapshot::ProjectBlocksLock::NewHashes

Definition at line 63 of file LocalProjectSnapshot.cpp.

Referenced by UpdateHash(), and UpdateProjectHashesInCache().

◆ OnBlocksLocked

std::function<void()> audacity::cloud::audiocom::sync::LocalProjectSnapshot::ProjectBlocksLock::OnBlocksLocked

Definition at line 65 of file LocalProjectSnapshot.cpp.

Referenced by CollectHashes().

◆ UpdateCacheFuture

std::future<void> audacity::cloud::audiocom::sync::LocalProjectSnapshot::ProjectBlocksLock::UpdateCacheFuture

Definition at line 62 of file LocalProjectSnapshot.cpp.

Referenced by UpdateProjectHashesInCache().


The documentation for this struct was generated from the following file: