David/new balance logic mk3 (#175)

* WIP will work on locks

* added concurrent test for referral, numbers rn still add up

* will change balance table to be a view instead of a table

* merged in devel. will proceed with migrations for rpc_stats_v2 and referral

* WIP

* WIP

* WIP compiling

* gotta add the balance_v2 view

* about to add balance view

* stupid missing closing param

* compiles again, now i will just have to implement the raw sql

* need to paste the real query and play with it

* ok now on to testing

* addresses many comments in PR

* app works for simple unauthorized access. will look into tests

* some tests pass, referral logic tests fail

* not sure why the test is failing

* invalidate cache for admin, will check for more possible targets

* user balance decrease test works

* all tests pass

* changed to active model

---------

Co-authored-by: yenicelik <david.yenicelik@gmail.com>
This commit is contained in:
Bryan Stitt 2023-07-09 20:15:32 -07:00 committed by GitHub
parent a560d47c48
commit 0ddd3662ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -447,21 +447,16 @@ impl BufferedRpcQueryStats {
{
trace!("Adding sender bonus balance");
// TODO: Should it be Unchanged, or do we have to load all numbers there again ..
new_referee_entity = referee::ActiveModel {
id: sea_orm::Unchanged(Default::default()),
one_time_bonus_applied_for_referee: sea_orm::Set(bonus_for_user),
credits_applied_for_referrer: sea_orm::Unchanged(Default::default()),
referral_start_date: sea_orm::Unchanged(Default::default()),
used_referral_code: sea_orm::Unchanged(Default::default()),
user_id: sea_orm::Unchanged(Default::default()),
};
let mut new_referral_entity = referral_entity.clone().into_active_model();
new_referral_entity.one_time_bonus_applied_for_referee =
sea_orm::Set(bonus_for_user);
// Update the cache
{
// Also no need to invalidate the cache here, just by itself
user_balance.total_deposits += bonus_for_user;
}
// The resulting field will not be read again, so I will not try to turn the ActiveModel into a Model one
new_referee_entity = new_referee_entity.save(&txn).await?;
new_referral_entity = new_referral_entity.save(&txn).await?;
}
// Apply the bonus to the referrer if they are premium right now