Skip to content

Commit

Permalink
modified t1Referrals sharing logic to require users be in an active m…
Browse files Browse the repository at this point in the history
…ining and have no verified t1 referrals themselves to be eligible for receiving a t1 referral from someone else
  • Loading branch information
ice-ares committed Jul 9, 2024
1 parent ad9ab8a commit 9922782
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ require (

require (
cloud.google.com/go v0.115.0 // indirect
cloud.google.com/go/auth v0.6.1 // indirect
cloud.google.com/go/auth v0.7.0 // indirect
cloud.google.com/go/auth/oauth2adapt v0.2.2 // indirect
cloud.google.com/go/compute/metadata v0.4.0 // indirect
cloud.google.com/go/firestore v1.15.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
cloud.google.com/go v0.115.0 h1:CnFSK6Xo3lDYRoBKEcAtia6VSC837/ZkJuRduSFnr14=
cloud.google.com/go v0.115.0/go.mod h1:8jIM5vVgoAEoiVxQ/O4BFTfHqulPZgs/ufEzMcFMdWU=
cloud.google.com/go/auth v0.6.1 h1:T0Zw1XM5c1GlpN2HYr2s+m3vr1p2wy+8VN+Z1FKxW38=
cloud.google.com/go/auth v0.6.1/go.mod h1:eFHG7zDzbXHKmjJddFG/rBlcGp6t25SwRUiEQSlO4x4=
cloud.google.com/go/auth v0.7.0 h1:kf/x9B3WTbBUHkC+1VS8wwwli9TzhSt0vSTVBmMR8Ts=
cloud.google.com/go/auth v0.7.0/go.mod h1:D+WqdrpcjmiCgWrXmLLxOVq1GACoE36chW6KXoEvuIw=
cloud.google.com/go/auth/oauth2adapt v0.2.2 h1:+TTV8aXpjeChS9M+aTtN/TjdQnzJvmzKFt//oWu7HX4=
cloud.google.com/go/auth/oauth2adapt v0.2.2/go.mod h1:wcYjgpZI9+Yu7LyYBg4pqSiaRkfEK3GQcpb7C/uyF1Q=
cloud.google.com/go/compute/metadata v0.4.0 h1:vHzJCWaM4g8XIcm8kopr3XmDA4Gy/lblD3EhhSux05c=
Expand Down
4 changes: 2 additions & 2 deletions users/DDL.sql
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ ALTER TABLE users ADD COLUMN IF NOT EXISTS verified BOOLEAN NOT NULL DEFAULT FAL
ALTER TABLE users ADD COLUMN IF NOT EXISTS mining_boost_level smallint NOT NULL DEFAULT 0;
ALTER TABLE users ADD COLUMN IF NOT EXISTS verified_t1_referrals bigint NOT NULL DEFAULT 0;

CREATE INDEX IF NOT EXISTS users_shared_referral_lookup_ix ON users (id)
CREATE INDEX IF NOT EXISTS users_shared_referral_lookup_v2_ix ON users (last_mining_ended_at DESC NULLS LAST, id)
WHERE mining_boost_level = 0
AND verified = TRUE
AND verified_t1_referrals < 3;
AND verified_t1_referrals = 0;

CREATE OR REPLACE FUNCTION before_update_on_users()
RETURNS TRIGGER AS $$
Expand Down
9 changes: 7 additions & 2 deletions users/users_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package users

import (
"context"
"fmt"
"net"

"github.com/hashicorp/go-multierror"
Expand Down Expand Up @@ -131,17 +132,21 @@ func (r *repository) replaceReferredByWithARandomOneIfT1ReferralsSharingEnabled(
FROM users
WHERE mining_boost_level = 0
AND verified = TRUE
AND verified_t1_referrals < 3
AND verified_t1_referrals = 0
AND last_mining_ended_at > now()
AND id != ANY ($1)
ORDER BY RANDOM()
LIMIT 1) new_random_referral
WHERE input_referral.id = $2
AND input_referral.t1_referrals_sharing_enabled = TRUE`
res, err := storage.Get[struct{ NewReferredBy string }](ctx, r.db, sql, []string{usr.ReferredBy, usr.ID}, usr.ReferredBy)
if err != nil && !errors.Is(err, storage.ErrNotFound) {
if err != nil && !errors.Is(err, storage.ErrNotFound) { //nolint:gocritic // .
return errors.Wrapf(err, "failed to get new referred by if the provided one has t1 sharing enabled, id:%v, referredBy:%v", usr.ID, usr.ReferredBy)
} else if res != nil {
log.Info(fmt.Sprintf("[t1ReferalSharingTriggered][userID:%v] user input referredBy `%v` was switch with system provided referredBy `%v`", usr.ID, usr.ReferredBy, res.NewReferredBy)) //nolint:lll // .
usr.ReferredBy = res.NewReferredBy
} else {
log.Info(fmt.Sprintf("[t1ReferalSharingTriggered][no change][userID:%v] user input referredBy `%v` was not switched with a system provided referredBy because we couldn't find any", usr.ID, usr.ReferredBy)) //nolint:lll // .
}

return nil
Expand Down

0 comments on commit 9922782

Please sign in to comment.