aboutsummaryrefslogtreecommitdiff
path: root/src/zenserver/projectstore/projectstore.cpp
diff options
context:
space:
mode:
authorMartin Ridgers <[email protected]>2024-09-12 13:11:56 +0200
committerMartin Ridgers <[email protected]>2024-09-19 15:26:13 +0200
commit1107d22721223de03ac2ab33f641ad1bfec1f156 (patch)
treeb0e8e1a3f28e335885357b7404ef7d17ed0edab8 /src/zenserver/projectstore/projectstore.cpp
parentAdded brief section on building for macOS with multiple users (diff)
downloadzen-1107d22721223de03ac2ab33f641ad1bfec1f156.tar.xz
zen-1107d22721223de03ac2ab33f641ad1bfec1f156.zip
Optional paged results when iterating oplog entries
Diffstat (limited to 'src/zenserver/projectstore/projectstore.cpp')
-rw-r--r--src/zenserver/projectstore/projectstore.cpp24
1 files changed, 20 insertions, 4 deletions
diff --git a/src/zenserver/projectstore/projectstore.cpp b/src/zenserver/projectstore/projectstore.cpp
index a34f2f4d5..d47b4e50b 100644
--- a/src/zenserver/projectstore/projectstore.cpp
+++ b/src/zenserver/projectstore/projectstore.cpp
@@ -2032,14 +2032,14 @@ ProjectStore::Oplog::IterateFileMap(
}
void
-ProjectStore::Oplog::IterateOplog(std::function<void(CbObjectView)>&& Handler)
+ProjectStore::Oplog::IterateOplog(std::function<void(CbObjectView)>&& Handler, const Paging& EntryPaging)
{
RwLock::SharedLockScope _(m_OplogLock);
- IterateOplogLocked(std::move(Handler));
+ IterateOplogLocked(std::move(Handler), EntryPaging);
}
void
-ProjectStore::Oplog::IterateOplogLocked(std::function<void(CbObjectView)>&& Handler)
+ProjectStore::Oplog::IterateOplogLocked(std::function<void(CbObjectView)>&& Handler, const Paging& EntryPaging)
{
ZEN_TRACE_CPU("Store::Oplog::IterateOplogLocked");
if (!m_Storage)
@@ -2062,7 +2062,23 @@ ProjectStore::Oplog::IterateOplogLocked(std::function<void(CbObjectView)>&& Hand
return Lhs.Offset < Rhs.Offset;
});
- m_Storage->ReplayLogEntries(Entries, [&](CbObjectView Op) { Handler(Op); });
+ std::span<OplogEntryAddress> EntrySpan;
+ if (EntryPaging.Start >= 0 || EntryPaging.Count >= 0)
+ {
+ int32_t Indices[2] = {EntryPaging.Start, EntryPaging.Start + EntryPaging.Count};
+ for (int32_t& Index : Indices)
+ {
+ Index = std::max<int32_t>(0, Index);
+ Index = std::min<int32_t>(Index, int32_t(Entries.size()));
+ }
+ EntrySpan = decltype(EntrySpan)(Entries.begin() + Indices[0], Indices[1] - Indices[0]);
+ }
+ else
+ {
+ EntrySpan = Entries;
+ }
+
+ m_Storage->ReplayLogEntries(EntrySpan, [&](CbObjectView Op) { Handler(Op); });
}
static constexpr uint32_t OplogMetaDataExpectedMagic = 0x6f'74'6d'62; // 'omta';