mirror of
https://github.com/Expand-sys/CCash
synced 2025-12-16 16:12:14 +11:00
🐎 optimized PruneUsers() for if logs are disabled
This commit is contained in:
parent
2b7330f48a
commit
dbaa6c6beb
3 changed files with 20 additions and 0 deletions
|
|
@ -56,7 +56,11 @@ public:
|
|||
BankResponse SetBal(const std::string &name, uint32_t amount) noexcept;
|
||||
BankResponse ImpactBal(const std::string &name, int64_t amount) noexcept;
|
||||
bool Contains(const std::string &name) const noexcept;
|
||||
#if MAX_LOG_SIZE > 0
|
||||
BankResponse PruneUsers(time_t threshold_time, uint32_t threshold_bal) noexcept;
|
||||
#else
|
||||
BankResponse PruneUsers(uint32_t threshold_bal) noexcept;
|
||||
#endif
|
||||
|
||||
BankResponse AddUser(const std::string &name, uint32_t init_bal, const std::string &init_pass) noexcept;
|
||||
BankResponse DelUser(const std::string &name) noexcept;
|
||||
|
|
|
|||
|
|
@ -181,7 +181,11 @@ bool Bank::Contains(const std::string &name) const noexcept
|
|||
{
|
||||
return ValidUsername(name) && users.contains(name);
|
||||
}
|
||||
#if MAX_LOG_SIZE > 0
|
||||
BankResponse Bank::PruneUsers(time_t threshold_time, uint32_t threshold_bal) noexcept
|
||||
#else
|
||||
BankResponse Bank::PruneUsers(uint32_t threshold_bal) noexcept
|
||||
#endif
|
||||
{
|
||||
std::unique_lock<std::shared_mutex> lock{iter_lock};
|
||||
size_t deleted_count = 0;
|
||||
|
|
|
|||
|
|
@ -235,6 +235,7 @@ void api::PruneUsers(req_args) const
|
|||
}
|
||||
else
|
||||
{
|
||||
#if MAX_LOG_SIZE > 0
|
||||
auto time = doc.find_field("time").get_int64();
|
||||
auto amount = doc.find_field("amount").get_uint64();
|
||||
if (time.error() || amount.error())
|
||||
|
|
@ -245,6 +246,17 @@ void api::PruneUsers(req_args) const
|
|||
{
|
||||
res = bank.PruneUsers(time.value(), amount.value());
|
||||
}
|
||||
#else
|
||||
auto amount = doc.find_field("amount").get_uint64();
|
||||
if (amount.error())
|
||||
{
|
||||
res = BankResponse{k400BadRequest, "\"Missing JSON arg(s)\""};
|
||||
}
|
||||
else
|
||||
{
|
||||
res = bank.PruneUsers(amount.value());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
RESPONSE_PARSE(std::move(res));
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue