diff options
| author | zousar <[email protected]> | 2023-12-05 23:33:47 -0700 |
|---|---|---|
| committer | zousar <[email protected]> | 2023-12-05 23:33:47 -0700 |
| commit | 722b4f350621dfe81b053f8904de17e029a2e662 (patch) | |
| tree | 3f673c2e5a3ec7eb4d9dfa1c4c4a5853573cac36 /src | |
| parent | Add endpoint for all chunk infos (diff) | |
| download | zen-722b4f350621dfe81b053f8904de17e029a2e662.tar.xz zen-722b4f350621dfe81b053f8904de17e029a2e662.zip | |
Get hash when retrieving chunks
Also changes the returned fields for each chunk from size->rawsize. Backwards compatibility is not a concern as this was unused in past zenserver releases.
Diffstat (limited to 'src')
| -rw-r--r-- | src/zenserver/projectstore/projectstore.cpp | 38 | ||||
| -rw-r--r-- | src/zenserver/projectstore/projectstore.h | 1 |
2 files changed, 32 insertions, 7 deletions
diff --git a/src/zenserver/projectstore/projectstore.cpp b/src/zenserver/projectstore/projectstore.cpp index b19913747..cf827b22e 100644 --- a/src/zenserver/projectstore/projectstore.cpp +++ b/src/zenserver/projectstore/projectstore.cpp @@ -752,6 +752,22 @@ ProjectStore::Oplog::GetAllChunksInfo() } void +ProjectStore::Oplog::IterateChunkMap( + std::function<void(const Oid&, const IoHash&)>&& Fn) +{ + RwLock::SharedLockScope _(m_OplogLock); + if (!m_Storage) + { + return; + } + + for (const auto& Kv : m_ChunkMap) + { + Fn(Kv.first, Kv.second); + } +} + +void ProjectStore::Oplog::IterateFileMap( std::function<void(const Oid&, const std::string_view& ServerPath, const std::string_view& ClientPath)>&& Fn) { @@ -2235,17 +2251,25 @@ ProjectStore::GetProjectChunks(const std::string_view ProjectId, const std::stri } Project->TouchOplog(OplogId); - std::vector<ProjectStore::Oplog::ChunkInfo> ChunkInfo = FoundLog->GetAllChunksInfo(); + std::vector<std::pair<Oid, IoHash>> ChunkInfos; + FoundLog->IterateChunkMap([&ChunkInfos](const Oid& Id, const IoHash& Hash) { + ChunkInfos.push_back({Id, Hash}); + }); - CbObjectWriter Response; + CbObjectWriter Response; Response.BeginArray("chunks"sv); - for (ProjectStore::Oplog::ChunkInfo& Info : ChunkInfo) + + for (const auto& ChunkInfo : ChunkInfos) { - Response.BeginObject(); - Response << "id"sv << Info.ChunkId; - Response << "size"sv << Info.ChunkSize; - Response.EndObject(); + if (IoBuffer Chunk = FoundLog->FindChunk(ChunkInfo.first)) + { + Response.BeginObject(); + Response << "id"sv << ChunkInfo.first; + Response << "rawhash"sv << ChunkInfo.second; + Response << "rawsize"sv << Chunk.GetSize(); + Response.EndObject(); + } } Response.EndArray(); diff --git a/src/zenserver/projectstore/projectstore.h b/src/zenserver/projectstore/projectstore.h index 555f8bdf2..813af9b37 100644 --- a/src/zenserver/projectstore/projectstore.h +++ b/src/zenserver/projectstore/projectstore.h @@ -93,6 +93,7 @@ public: }; std::vector<ChunkInfo> GetAllChunksInfo(); + void IterateChunkMap(std::function<void(const Oid&, const IoHash& Hash)>&& Fn); void IterateFileMap(std::function<void(const Oid&, const std::string_view& ServerPath, const std::string_view& ClientPath)>&& Fn); void IterateOplog(std::function<void(CbObjectView)>&& Fn); void IterateOplogWithKey(std::function<void(int, const Oid&, CbObjectView)>&& Fn); |