mirror of
https://github.com/Expand-sys/CCash
synced 2025-12-17 08:32:13 +11:00
🚧🐎 preparing to use FBE, in the meantime its 99% faster
This commit is contained in:
parent
09911d5496
commit
80cc3a99cf
3 changed files with 11 additions and 7 deletions
|
|
@ -62,7 +62,7 @@ BankResponse Bank::GetLogs(const std::string &name) noexcept
|
||||||
{
|
{
|
||||||
BankResponse res;
|
BankResponse res;
|
||||||
#if MAX_LOG_SIZE > 0
|
#if MAX_LOG_SIZE > 0
|
||||||
if (!users.modify_if(name, [&res](User &u) { res = BankResponse(k200OK, u.log.GetLog().toStyledString()); }))
|
if (!users.modify_if(name, [&res](User &u) { res = BankResponse(k200OK, u.log.GetLog()); }))
|
||||||
{
|
{
|
||||||
return BankResponse(k404NotFound, "\"User not found\"");
|
return BankResponse(k404NotFound, "\"User not found\"");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -51,12 +51,11 @@ void api::GetLogs(req_args)
|
||||||
{
|
{
|
||||||
if constexpr (MAX_LOG_SIZE > 0)
|
if constexpr (MAX_LOG_SIZE > 0)
|
||||||
{
|
{
|
||||||
RESPONSE_PARSE(bank.GetLogs(NAME_PARAM));
|
RESPONSE_PARSE(bank.GetLogs("twix"));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto resp = HttpResponse::newHttpJsonResponse("Logs are Disabled");
|
auto resp = HttpResponse::newCustomHttpResponse(BankResponse(k404NotFound, "\"Logs are Disabled\""));
|
||||||
resp->setStatusCode(k404NotFound);
|
|
||||||
CACHE_FOREVER
|
CACHE_FOREVER
|
||||||
callback(resp);
|
callback(resp);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
11
src/log.cpp
11
src/log.cpp
|
|
@ -1,5 +1,10 @@
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
|
Log::Log() noexcept
|
||||||
|
{
|
||||||
|
log_flag.SetChangesOn();
|
||||||
|
}
|
||||||
|
|
||||||
void Log::AddTrans(Transaction &&t) noexcept
|
void Log::AddTrans(Transaction &&t) noexcept
|
||||||
{
|
{
|
||||||
#if MAX_LOG_SIZE == 1
|
#if MAX_LOG_SIZE == 1
|
||||||
|
|
@ -7,7 +12,7 @@ void Log::AddTrans(Transaction &&t) noexcept
|
||||||
#else
|
#else
|
||||||
if (data.size() == MAX_LOG_SIZE) // If we hit the max size
|
if (data.size() == MAX_LOG_SIZE) // If we hit the max size
|
||||||
{
|
{
|
||||||
for (uint32_t i = 1; i < data.size(); i++) // Make room at the back
|
for (size_t i = 1; i < data.size(); i++) // Make room at the back
|
||||||
{
|
{
|
||||||
data[i - 1] = std::move(data[i]); // Shifts everything left
|
data[i - 1] = std::move(data[i]); // Shifts everything left
|
||||||
}
|
}
|
||||||
|
|
@ -19,7 +24,7 @@ void Log::AddTrans(Transaction &&t) noexcept
|
||||||
log_flag.SetChangesOn();
|
log_flag.SetChangesOn();
|
||||||
}
|
}
|
||||||
|
|
||||||
const Json::Value &Log::GetLog() noexcept
|
const std::string &Log::GetLog() noexcept
|
||||||
{
|
{
|
||||||
if (log_flag.GetChangeState()) //if there are changes
|
if (log_flag.GetChangeState()) //if there are changes
|
||||||
{
|
{
|
||||||
|
|
@ -42,7 +47,7 @@ const Json::Value &Log::GetLog() noexcept
|
||||||
res[i - 1]["time"] = (Json::Int64)data[data.size() - i].time;
|
res[i - 1]["time"] = (Json::Int64)data[data.size() - i].time;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
log_snapshot = res;
|
log_snapshot = res.toStyledString();
|
||||||
log_flag.SetChangesOff();
|
log_flag.SetChangesOff();
|
||||||
}
|
}
|
||||||
return log_snapshot;
|
return log_snapshot;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue