Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetching users that have t1/t2 mismatch only. Additional check for achieved badges #31

Merged
merged 2 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func main() {

var bugfixStartTimestamp *time.Time
if bugfixStartTimestampString == "" {
log.Panic("empty bugfix start timestamp string")
log.Panic("empty bugfixStartTimestamp parameter")
}
bugfixStartTimestamp = new(time.Time)
log.Panic(errors.Wrapf(bugfixStartTimestamp.UnmarshalText([]byte(bugfixStartTimestampString)), "failed to parse bugfix start timestamp `%v`", bugfixStartTimestampString)) //nolint:lll,revive // .
Expand Down Expand Up @@ -108,15 +108,23 @@ func (u *updater) update(ctx context.Context, bugfixStartTimestamp *time.Time) {
******************************************************************************************************************************************************/
sql := `SELECT
u.id,
COUNT(t1.id) AS friends_invited
COUNT(DISTINCT t1.id) AS friends_invited
FROM users u
LEFT JOIN users t1
ON t1.referred_by = u.id
AND u.username != u.id
WHERE u.referred_by != u.id
AND u.username != u.id
AND u.created_at < $1
GROUP BY u.id
LEFT JOIN USERS t1
ON t1.referred_by = u.ID
AND t1.id != u.id
AND t1.username != t1.id
AND t1.referred_by != t1.id
LEFT JOIN USERS t2
ON t2.referred_by = t1.ID
AND t2.id != t1.id
AND t2.username != t2.id
AND t2.referred_by != t2.id
JOIN referral_acquisition_history rah
ON u.id = rah.user_id
WHERE u.created_at < $1
GROUP BY u.id, rah.t1, rah.t2
HAVING rah.t1 != COUNT(DISTINCT t1.id) OR rah.t2 != COUNT(DISTINCT t2.id)
ORDER BY u.hash_code ASC
LIMIT $2
OFFSET $3`
Expand All @@ -125,8 +133,6 @@ func (u *updater) update(ctx context.Context, bugfixStartTimestamp *time.Time) {
log.Panic("error on trying to get actual friends invited values crossed with already updated values", err)
}
if len(usrs) == 0 {
log.Debug("no more users to handle results for")

break
}

Expand Down Expand Up @@ -158,7 +164,6 @@ func (u *updater) update(ctx context.Context, bugfixStartTimestamp *time.Time) {
log.Panic("error on trying to get tasks", userKeysProgress, err)
}
if len(res) == 0 {
log.Debug("no results for: ", userKeysProgress, err)
offset += maxLimit

continue
Expand Down Expand Up @@ -240,26 +245,29 @@ func (u *updater) updateBadgesAndStatistics(ctx context.Context, usr *commonUser
return errors.Wrapf(multierror.Append(mErr, nil).ErrorOrNil(), "can't update badge statistics")
}

//nolint:gocognit,nestif,revive // .
func diffBadgeStatistics(usr *commonUser, newBadgesTypeCount map[badges.Type]int64) map[badges.Type]int64 {
oldBadgesTypeCounts := make(map[badges.Type]int64, len(badges.AllTypes))
oldGroupCounts := make(map[badges.GroupType]int64, len(badges.AllGroups))
for _, badge := range *usr.AchievedBadges {
switch badges.GroupTypeForEachType[badge] { //nolint:exhaustive // We need to handle only 2 groups.
case badges.CoinGroupType:
oldBadgesTypeCounts[badge]++
oldGroupCounts[badges.CoinGroupType]++
case badges.SocialGroupType:
oldBadgesTypeCounts[badge]++
oldGroupCounts[badges.SocialGroupType]++
default:
continue
if usr.AchievedBadges != nil {
for _, badge := range *usr.AchievedBadges {
switch badges.GroupTypeForEachType[badge] { //nolint:exhaustive // We need to handle only 2 groups.
case badges.CoinGroupType:
oldBadgesTypeCounts[badge]++
oldGroupCounts[badges.CoinGroupType]++
case badges.SocialGroupType:
oldBadgesTypeCounts[badge]++
oldGroupCounts[badges.SocialGroupType]++
default:
continue
}
}
}
if newBadgesTypeCount != nil {
for _, key := range &badges.AllTypes {
if _, ok1 := oldBadgesTypeCounts[key]; ok1 {
if _, ok2 := newBadgesTypeCount[key]; ok2 {
newBadgesTypeCount[key] -= oldBadgesTypeCounts[key]
if newBadgesTypeCount != nil {
for _, key := range &badges.AllTypes {
if _, ok1 := oldBadgesTypeCounts[key]; ok1 {
if _, ok2 := newBadgesTypeCount[key]; ok2 {
newBadgesTypeCount[key] -= oldBadgesTypeCounts[key]
}
}
}
}
Expand Down
46 changes: 23 additions & 23 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,42 @@ go 1.21
require (
github.com/goccy/go-json v0.10.2
github.com/hashicorp/go-multierror v1.1.1
github.com/ice-blockchain/eskimo v1.172.0
github.com/ice-blockchain/eskimo v1.176.0
github.com/ice-blockchain/wintr v1.125.0
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.8.4
github.com/swaggo/swag v1.16.2
github.com/testcontainers/testcontainers-go v0.25.0
github.com/testcontainers/testcontainers-go v0.26.0
)

require (
cloud.google.com/go v0.110.9 // indirect
cloud.google.com/go/compute v1.23.1 // indirect
cloud.google.com/go v0.110.10 // indirect
cloud.google.com/go/compute v1.23.3 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/firestore v1.14.0 // indirect
cloud.google.com/go/iam v1.1.3 // indirect
cloud.google.com/go/longrunning v0.5.2 // indirect
cloud.google.com/go/storage v1.33.0 // indirect
cloud.google.com/go/iam v1.1.5 // indirect
cloud.google.com/go/longrunning v0.5.4 // indirect
cloud.google.com/go/storage v1.34.1 // indirect
dario.cat/mergo v1.0.0 // indirect
firebase.google.com/go/v4 v4.12.1 // indirect
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect
github.com/KyleBanks/depth v1.2.1 // indirect
github.com/MicahParks/keyfunc v1.9.0 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/Microsoft/hcsshim v0.11.2 // indirect
github.com/Microsoft/hcsshim v0.11.4 // indirect
github.com/andybalholm/brotli v1.0.6 // indirect
github.com/bytedance/sonic v1.10.2 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
github.com/chenzhuoyu/iasm v0.9.0 // indirect
github.com/cloudflare/circl v1.3.5 // indirect
github.com/chenzhuoyu/iasm v0.9.1 // indirect
github.com/cloudflare/circl v1.3.6 // indirect
github.com/containerd/cgroups v1.1.0 // indirect
github.com/containerd/containerd v1.7.7 // indirect
github.com/containerd/containerd v1.7.8 // indirect
github.com/containerd/continuity v0.4.3 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/distribution/reference v0.5.0 // indirect
github.com/docker/distribution v2.8.3+incompatible // indirect
github.com/docker/docker v24.0.6+incompatible // indirect
github.com/docker/docker v24.0.7+incompatible // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
Expand All @@ -63,9 +63,9 @@ require (
github.com/golang-jwt/jwt/v5 v5.0.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/pprof v0.0.0-20231023181126-ff6d637d2a7b // indirect
github.com/google/pprof v0.0.0-20231101202521-4ca4178f5c7a // indirect
github.com/google/s2a-go v0.1.7 // indirect
github.com/google/uuid v1.3.1 // indirect
github.com/google/uuid v1.4.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.0 // indirect
github.com/gorilla/mux v1.8.0 // indirect
Expand Down Expand Up @@ -98,13 +98,13 @@ require (
github.com/onsi/ginkgo/v2 v2.13.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0-rc5 // indirect
github.com/opencontainers/runc v1.1.9 // indirect
github.com/opencontainers/runc v1.1.10 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/pierrec/lz4/v4 v4.1.18 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/quic-go/qpack v0.4.0 // indirect
github.com/quic-go/qtls-go1-20 v0.4.0 // indirect
github.com/quic-go/quic-go v0.39.1 // indirect
github.com/quic-go/qtls-go1-20 v0.4.1 // indirect
github.com/quic-go/quic-go v0.40.0 // indirect
github.com/refraction-networking/utls v1.5.4 // indirect
github.com/rs/zerolog v1.31.0 // indirect
github.com/sagikazarmark/locafero v0.3.0 // indirect
Expand All @@ -119,11 +119,11 @@ require (
github.com/swaggo/files v1.0.1 // indirect
github.com/swaggo/gin-swagger v1.6.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/twmb/franz-go v1.15.1 // indirect
github.com/twmb/franz-go v1.15.2 // indirect
github.com/twmb/franz-go/pkg/kadm v1.10.0 // indirect
github.com/twmb/franz-go/pkg/kmsg v1.7.0 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
github.com/vmihailenco/msgpack/v5 v5.4.0 // indirect
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
go.opencensus.io v0.24.0 // indirect
go.uber.org/mock v0.3.0 // indirect
Expand All @@ -140,12 +140,12 @@ require (
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.14.0 // indirect
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect
google.golang.org/api v0.148.0 // indirect
google.golang.org/api v0.149.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/appengine/v2 v2.0.5 // indirect
google.golang.org/genproto v0.0.0-20231016165738-49dd2c1f3d0b // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231016165738-49dd2c1f3d0b // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b // indirect
google.golang.org/genproto v0.0.0-20231030173426-d783a09b4405 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231030173426-d783a09b4405 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231030173426-d783a09b4405 // indirect
google.golang.org/grpc v1.59.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
Expand Down
Loading
Loading