From 1d992a472c54ef9a63364996031e3c6d2f8affe5 Mon Sep 17 00:00:00 2001 From: Dan Engelbrecht Date: Fri, 13 Oct 2023 09:38:02 +0200 Subject: faster oplog iteration (#471) * use a CbObjectView instead of CbObject to avoid creating IOBufferCore instances * use BasicFileBuffer directly where possible * changelog --- src/zenserver/projectstore/httpprojectstore.cpp | 27 ++++++++++++------------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'src/zenserver/projectstore/httpprojectstore.cpp') diff --git a/src/zenserver/projectstore/httpprojectstore.cpp b/src/zenserver/projectstore/httpprojectstore.cpp index 3edcf5903..261485834 100644 --- a/src/zenserver/projectstore/httpprojectstore.cpp +++ b/src/zenserver/projectstore/httpprojectstore.cpp @@ -57,14 +57,13 @@ CSVWriteOp(CidStore& CidStore, bool AttachmentDetails, int LSN, const Oid& Key, - CbObject Op, + CbObjectView Op, StringBuilderBase& CSVWriter) { StringBuilder<32> KeyStringBuilder; Key.ToString(KeyStringBuilder); const std::string_view KeyString = KeyStringBuilder.ToView(); - SharedBuffer Buffer = Op.GetBuffer(); if (AttachmentDetails) { Op.IterateAttachments([&CidStore, &CSVWriter, &ProjectId, &OplogId, LSN, &KeyString](CbFieldView FieldView) { @@ -86,8 +85,8 @@ CSVWriteOp(CidStore& CidStore, AttachmentsSize += Attachment.GetSize(); }); CSVWriter << "\r\n" - << ProjectId << ", " << OplogId << ", " << LSN << ", " << KeyString << ", " << gsl::narrow(Buffer.GetSize()) - << ", " << AttachmentCount << ", " << gsl::narrow(AttachmentsSize); + << ProjectId << ", " << OplogId << ", " << LSN << ", " << KeyString << ", " << gsl::narrow(Op.GetSize()) << ", " + << AttachmentCount << ", " << gsl::narrow(AttachmentsSize); } else { @@ -105,17 +104,16 @@ namespace { bool AttachmentDetails, int LSN, const Oid& Key, - CbObject Op, + CbObjectView Op, CbObjectWriter& CbWriter) { CbWriter.BeginObject(); { - SharedBuffer Buffer = Op.GetBuffer(); CbWriter.AddObjectId("key", Key); if (Details) { CbWriter.AddInteger("lsn", LSN); - CbWriter.AddInteger("size", gsl::narrow(Buffer.GetSize())); + CbWriter.AddInteger("size", gsl::narrow(Op.GetSize())); } if (AttachmentDetails) { @@ -176,7 +174,7 @@ namespace { { Cbo.BeginArray("ops"); { - Oplog.IterateOplogWithKey([&Cbo, &CidStore, Details, OpDetails, AttachmentDetails](int LSN, const Oid& Key, CbObject Op) { + Oplog.IterateOplogWithKey([&Cbo, &CidStore, Details, OpDetails, AttachmentDetails](int LSN, const Oid& Key, CbObjectView Op) { CbWriteOp(CidStore, Details, OpDetails, AttachmentDetails, LSN, Key, Op, Cbo); }); } @@ -1350,7 +1348,7 @@ HttpProjectService::HandleOpLogEntriesRequest(HttpRouterRequest& Req) { Response.BeginArray("entries"sv); - FoundLog->IterateOplog([&Response](CbObject Op) { Response << Op; }); + FoundLog->IterateOplog([&Response](CbObjectView Op) { Response << Op; }); Response.EndArray(); } @@ -1638,7 +1636,7 @@ HttpProjectService::HandleDetailsRequest(HttpRouterRequest& Req) m_ProjectStore->IterateProjects([&](ProjectStore::Project& Project) { Project.IterateOplogs([&](const RwLock::SharedLockScope&, ProjectStore::Oplog& Oplog) { Oplog.IterateOplogWithKey( - [this, &Project, &Oplog, &CSVWriter, Details, AttachmentDetails](int LSN, const Oid& Key, CbObject Op) { + [this, &Project, &Oplog, &CSVWriter, Details, AttachmentDetails](int LSN, const Oid& Key, CbObjectView Op) { CSVWriteOp(m_CidStore, Project.Identifier, Oplog.OplogId(), Details, AttachmentDetails, LSN, Key, Op, CSVWriter); }); }); @@ -1693,7 +1691,7 @@ HttpProjectService::HandleProjectDetailsRequest(HttpRouterRequest& Req) FoundProject->IterateOplogs([&](const RwLock::SharedLockScope&, ProjectStore::Oplog& Oplog) { Oplog.IterateOplogWithKey( - [this, &Project, &Oplog, &CSVWriter, Details, AttachmentDetails](int LSN, const Oid& Key, CbObject Op) { + [this, &Project, &Oplog, &CSVWriter, Details, AttachmentDetails](int LSN, const Oid& Key, CbObjectView Op) { CSVWriteOp(m_CidStore, Project.Identifier, Oplog.OplogId(), Details, AttachmentDetails, LSN, Key, Op, CSVWriter); }); }); @@ -1748,9 +1746,10 @@ HttpProjectService::HandleOplogDetailsRequest(HttpRouterRequest& Req) ExtendableStringBuilder<4096> CSVWriter; CSVHeader(Details, AttachmentDetails, CSVWriter); - Oplog.IterateOplogWithKey([this, &Project, &Oplog, &CSVWriter, Details, AttachmentDetails](int LSN, const Oid& Key, CbObject Op) { - CSVWriteOp(m_CidStore, Project.Identifier, Oplog.OplogId(), Details, AttachmentDetails, LSN, Key, Op, CSVWriter); - }); + Oplog.IterateOplogWithKey( + [this, &Project, &Oplog, &CSVWriter, Details, AttachmentDetails](int LSN, const Oid& Key, CbObjectView Op) { + CSVWriteOp(m_CidStore, Project.Identifier, Oplog.OplogId(), Details, AttachmentDetails, LSN, Key, Op, CSVWriter); + }); HttpReq.WriteResponse(HttpResponseCode::OK, HttpContentType::kText, CSVWriter.ToView()); } else -- cgit v1.2.3