🐛 prune users should return on del if enabled

This commit is contained in:
William Katz 2021-07-23 15:12:12 -07:00 committed by GitHub
parent f48ad92f25
commit 7a0a5d4036
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -195,15 +195,24 @@ BankResponse Bank::PruneUsers(time_t threshold_time, uint32_t threshold_bal) noe
size_t deleted_count = 0;
for (const auto &u : users)
{
if (users.erase_if(u.first, [threshold_time, threshold_bal, &deleted_count](User &u) -> bool
{
#if MAX_LOG_SIZE > 0
return ((!u.log.data.size() || u.log.data.back().time < threshold_time) && u.balance < threshold_bal);
#if RETURN_ON_DEL
uint32_t bal;
if (users.erase_if(u.first, [threshold_time, threshold_bal, &bal, &deleted_count](User &u) -> bool {
bal = u.balance;
#else
return (u.balance < threshold_bal);
if (users.erase_if(u.first, [threshold_time, threshold_bal, &deleted_count](User &u) -> bool {
#endif
}))
#if MAX_LOG_SIZE > 0
return ((!u.log.data.size() || u.log.data.back().time < threshold_time) && u.balance < threshold_bal);
#else
return (u.balance < threshold_bal);
#endif
}))
{
#if RETURN_ON_DEL
users.modify_if(return_account, [bal](User &u) { u.balance += bal; });
#endif
SET_CHANGES_ON;
++deleted_count;
}