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 49 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 68 of file LocalProjectSnapshot.cpp.

72 , OnBlocksLocked { std::move(onBlocksLocked) }
73 {
75
77 {
80 }
81
82 Hasher = std::make_unique<BlockHasher>();
83
84 Hasher->ComputeHashes(*this, Blocks, [this] { CollectHashes(); });
85 }
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 87 of file LocalProjectSnapshot.cpp.

88 {
89 }

Member Function Documentation

◆ CollectHashes()

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

Definition at line 112 of file LocalProjectSnapshot.cpp.

113 {
114 // TakeResult() will call UpdateHash() for each block
115 // not found in the cache
116 const auto result = Hasher->TakeResult();
117
118 for (auto [id, hash] : result)
119 {
120 auto it = BlockIdToIndex.find(id);
121
122 if (it == BlockIdToIndex.end())
123 {
124 assert(false);
125 continue;
126 }
127
128 while (BlockHashToIndex.find(hash) != BlockHashToIndex.end())
129 {
130 // Hash is used by another block, rehash
131 hash = crypto::sha256(hash);
132 }
133
135 Blocks[it->second].Hash = std::move(hash);
136 }
137
138 // This will potentially block, if the cache is being updated
139 // already
141
142 if (OnBlocksLocked)
144 }
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 181 of file LocalProjectSnapshot.cpp.

182 {
183 for (const auto& urls : missingBlockUrls)
184 {
185 auto it = BlockHashToIndex.find(ToUpper(urls.Id));
186
187 if (it == BlockHashToIndex.end())
188 {
189 assert(false);
190 continue;
191 }
192
193 const auto index = it->second;
194
195 MissingBlocks.push_back(BlockUploadTask { urls, Blocks[index] });
196 }
197 }
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 160 of file LocalProjectSnapshot.cpp.

161 {
163 return false;
164
165 auto cachedResult = CloudProjectsDatabase::Get().GetBlockHash(
166 Extension.GetCloudProjectId(), blockId);
167
168 if (!cachedResult)
169 return false;
170
171 hash = std::move(*cachedResult);
172
173 return true;
174 }
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 176 of file LocalProjectSnapshot.cpp.

177 {
178 NewHashes.emplace_back(blockId, hash);
179 }

References NewHashes.

◆ UpdateProjectHashesInCache()

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

Definition at line 146 of file LocalProjectSnapshot.cpp.

147 {
149 return;
150
151 UpdateCacheFuture = std::async(
152 std::launch::async,
153 [this, hashes = std::move(NewHashes)]
154 {
156 Extension.GetCloudProjectId(), hashes);
157 });
158 }
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 91 of file LocalProjectSnapshot.cpp.

92 {
93 const auto visitor = [this](const SampleBlockPtr &pBlock){
94 const auto id = pBlock->GetBlockID();
95 if(id >= 0)
96 {
97 Blocks.push_back({
98 id, pBlock->GetSampleFormat(), pBlock });
99 BlockIdToIndex[id] = Blocks.size() - 1;
100 }
101 //Do not compute hashes for negative id's, which describe
102 //the length of a silenced sequence. Making an id record in
103 //project blob is enough to restore block contents fully.
104 //VS: Older versions of Audacity encoded them as a regular
105 //blocks, but due to wrong sanity checks in `WavPackCompressor`
106 //attempt to load them could fail. The check above will purge
107 //such blocks if they are present in old project.
108 };
110 }
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 59 of file LocalProjectSnapshot.cpp.

Referenced by CollectHashes(), and FillMissingBlocks().

◆ BlockIds

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

Definition at line 53 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 58 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 51 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 61 of file LocalProjectSnapshot.cpp.

Referenced by CollectHashes(), and ProjectBlocksLock().

◆ MissingBlocks

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

Definition at line 56 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 64 of file LocalProjectSnapshot.cpp.

Referenced by UpdateHash(), and UpdateProjectHashesInCache().

◆ OnBlocksLocked

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

Definition at line 66 of file LocalProjectSnapshot.cpp.

Referenced by CollectHashes().

◆ UpdateCacheFuture

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

Definition at line 63 of file LocalProjectSnapshot.cpp.

Referenced by UpdateProjectHashesInCache().


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