forked from osuripple/ripple-cron-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathredis_relax.go
More file actions
89 lines (75 loc) · 1.77 KB
/
redis_relax.go
File metadata and controls
89 lines (75 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package main
import (
"strings"
"time"
"github.com/fatih/color"
redis "gopkg.in/redis.v5"
)
func opPopulateRedisRX() {
defer wg.Done()
s, err := r.Keys("ripple:leaderboard_relax:*").Result()
if err != nil {
color.Red("> PopulateRedisRX: %v", err)
return
}
if len(s) > 0 {
err = r.Eval("return redis.call('del', unpack(redis.call('keys', 'ripple:leaderboard_relax:*')))", nil).Err()
if err != nil {
color.Red("> PopulateRedisRX: %v", err)
return
}
}
r.Del("hanayo:country_list")
const initQuery = `
SELECT
rx_stats.id, rx_stats.country, pp_std,
pp_taiko, pp_ctb,
playcount_std, playcount_taiko, playcount_ctb,
users.latest_activity
FROM rx_stats INNER JOIN users ON users.id = rx_stats.id WHERE privileges & 1 > 0`
rows, err := db.Query(initQuery)
if err != nil {
queryError(err, initQuery)
return
}
currentSeconds := time.Now().Unix()
var (
uid int
country string
pp [4]int64
playcount [4]int
latestActivity int64
)
for rows.Next() {
err = rows.Scan(
&uid, &country, &pp[0],
&pp[1], &pp[2],
&playcount[0], &playcount[1], &playcount[2],
&latestActivity,
)
if err != nil {
queryError(err, initQuery)
continue
}
country = strings.ToLower(country)
if country != "xx" && country != "" {
r.ZIncrBy("hanayo:country_list", 1, country)
}
for k, v := range pp {
if isInactive(float64(currentSeconds-latestActivity), playcount[k]) {
continue
}
r.ZAdd("ripple:leaderboard_relax:"+modes[k], redis.Z{
Member: uid,
Score: float64(v),
})
if country != "xx" && country != "" {
r.ZAdd("ripple:leaderboard_relax:"+modes[k]+":"+country, redis.Z{
Member: uid,
Score: float64(v),
})
}
}
}
color.Green("> PopulateRedis [RELAX]: done!")
}