[REST] improve performance for JSON calls
JSON calls do not use the raw data generated for the .bin and .hex calls. By moving the raw data creation into the .bin and .hex switch branches, JSON calls become faster.
This commit is contained in:
parent
920c090f63
commit
30973e9844
1 changed files with 20 additions and 11 deletions
23
src/rest.cpp
23
src/rest.cpp
|
@ -157,13 +157,13 @@ static bool rest_headers(HTTPRequest* req,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch (rf) {
|
||||||
|
case RetFormat::BINARY: {
|
||||||
CDataStream ssHeader(SER_NETWORK, PROTOCOL_VERSION);
|
CDataStream ssHeader(SER_NETWORK, PROTOCOL_VERSION);
|
||||||
for (const CBlockIndex *pindex : headers) {
|
for (const CBlockIndex *pindex : headers) {
|
||||||
ssHeader << pindex->GetBlockHeader();
|
ssHeader << pindex->GetBlockHeader();
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (rf) {
|
|
||||||
case RetFormat::BINARY: {
|
|
||||||
std::string binaryHeader = ssHeader.str();
|
std::string binaryHeader = ssHeader.str();
|
||||||
req->WriteHeader("Content-Type", "application/octet-stream");
|
req->WriteHeader("Content-Type", "application/octet-stream");
|
||||||
req->WriteReply(HTTP_OK, binaryHeader);
|
req->WriteReply(HTTP_OK, binaryHeader);
|
||||||
|
@ -171,6 +171,11 @@ static bool rest_headers(HTTPRequest* req,
|
||||||
}
|
}
|
||||||
|
|
||||||
case RetFormat::HEX: {
|
case RetFormat::HEX: {
|
||||||
|
CDataStream ssHeader(SER_NETWORK, PROTOCOL_VERSION);
|
||||||
|
for (const CBlockIndex *pindex : headers) {
|
||||||
|
ssHeader << pindex->GetBlockHeader();
|
||||||
|
}
|
||||||
|
|
||||||
std::string strHex = HexStr(ssHeader.begin(), ssHeader.end()) + "\n";
|
std::string strHex = HexStr(ssHeader.begin(), ssHeader.end()) + "\n";
|
||||||
req->WriteHeader("Content-Type", "text/plain");
|
req->WriteHeader("Content-Type", "text/plain");
|
||||||
req->WriteReply(HTTP_OK, strHex);
|
req->WriteReply(HTTP_OK, strHex);
|
||||||
|
@ -224,11 +229,10 @@ static bool rest_block(HTTPRequest* req,
|
||||||
return RESTERR(req, HTTP_NOT_FOUND, hashStr + " not found");
|
return RESTERR(req, HTTP_NOT_FOUND, hashStr + " not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
CDataStream ssBlock(SER_NETWORK, PROTOCOL_VERSION | RPCSerializationFlags());
|
|
||||||
ssBlock << block;
|
|
||||||
|
|
||||||
switch (rf) {
|
switch (rf) {
|
||||||
case RetFormat::BINARY: {
|
case RetFormat::BINARY: {
|
||||||
|
CDataStream ssBlock(SER_NETWORK, PROTOCOL_VERSION | RPCSerializationFlags());
|
||||||
|
ssBlock << block;
|
||||||
std::string binaryBlock = ssBlock.str();
|
std::string binaryBlock = ssBlock.str();
|
||||||
req->WriteHeader("Content-Type", "application/octet-stream");
|
req->WriteHeader("Content-Type", "application/octet-stream");
|
||||||
req->WriteReply(HTTP_OK, binaryBlock);
|
req->WriteReply(HTTP_OK, binaryBlock);
|
||||||
|
@ -236,6 +240,8 @@ static bool rest_block(HTTPRequest* req,
|
||||||
}
|
}
|
||||||
|
|
||||||
case RetFormat::HEX: {
|
case RetFormat::HEX: {
|
||||||
|
CDataStream ssBlock(SER_NETWORK, PROTOCOL_VERSION | RPCSerializationFlags());
|
||||||
|
ssBlock << block;
|
||||||
std::string strHex = HexStr(ssBlock.begin(), ssBlock.end()) + "\n";
|
std::string strHex = HexStr(ssBlock.begin(), ssBlock.end()) + "\n";
|
||||||
req->WriteHeader("Content-Type", "text/plain");
|
req->WriteHeader("Content-Type", "text/plain");
|
||||||
req->WriteReply(HTTP_OK, strHex);
|
req->WriteReply(HTTP_OK, strHex);
|
||||||
|
@ -360,11 +366,11 @@ static bool rest_tx(HTTPRequest* req, const std::string& strURIPart)
|
||||||
if (!GetTransaction(hash, tx, Params().GetConsensus(), hashBlock, true))
|
if (!GetTransaction(hash, tx, Params().GetConsensus(), hashBlock, true))
|
||||||
return RESTERR(req, HTTP_NOT_FOUND, hashStr + " not found");
|
return RESTERR(req, HTTP_NOT_FOUND, hashStr + " not found");
|
||||||
|
|
||||||
|
switch (rf) {
|
||||||
|
case RetFormat::BINARY: {
|
||||||
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION | RPCSerializationFlags());
|
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION | RPCSerializationFlags());
|
||||||
ssTx << tx;
|
ssTx << tx;
|
||||||
|
|
||||||
switch (rf) {
|
|
||||||
case RetFormat::BINARY: {
|
|
||||||
std::string binaryTx = ssTx.str();
|
std::string binaryTx = ssTx.str();
|
||||||
req->WriteHeader("Content-Type", "application/octet-stream");
|
req->WriteHeader("Content-Type", "application/octet-stream");
|
||||||
req->WriteReply(HTTP_OK, binaryTx);
|
req->WriteReply(HTTP_OK, binaryTx);
|
||||||
|
@ -372,6 +378,9 @@ static bool rest_tx(HTTPRequest* req, const std::string& strURIPart)
|
||||||
}
|
}
|
||||||
|
|
||||||
case RetFormat::HEX: {
|
case RetFormat::HEX: {
|
||||||
|
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION | RPCSerializationFlags());
|
||||||
|
ssTx << tx;
|
||||||
|
|
||||||
std::string strHex = HexStr(ssTx.begin(), ssTx.end()) + "\n";
|
std::string strHex = HexStr(ssTx.begin(), ssTx.end()) + "\n";
|
||||||
req->WriteHeader("Content-Type", "text/plain");
|
req->WriteHeader("Content-Type", "text/plain");
|
||||||
req->WriteReply(HTTP_OK, strHex);
|
req->WriteReply(HTTP_OK, strHex);
|
||||||
|
|
Loading…
Add table
Reference in a new issue