mirror of
https://github.com/statbate/special-pancake.git
synced 2026-08-11 03:12:42 +00:00
update
This commit is contained in:
parent
baafa45aac
commit
4b0b928cef
1 changed files with 15 additions and 11 deletions
26
app/save.go
26
app/save.go
|
|
@ -69,11 +69,24 @@ func saveDB() {
|
||||||
index := make(map[string]int64)
|
index := make(map[string]int64)
|
||||||
|
|
||||||
ticker := time.NewTicker(10 * time.Second)
|
ticker := time.NewTicker(10 * time.Second)
|
||||||
|
defer ticker.Stop()
|
||||||
|
|
||||||
|
cleanCache := time.NewTicker(12 * time.Hour)
|
||||||
|
defer cleanCache.Stop()
|
||||||
|
|
||||||
index = map[string]int64{"hours": int64(hours), "tokens": getSumTokens(), "last": time.Now().Unix()}
|
index = map[string]int64{"hours": int64(hours), "tokens": getSumTokens(), "last": time.Now().Unix()}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
|
case <-cleanCache.C:
|
||||||
|
l := len(data)
|
||||||
|
now := time.Now().Unix()
|
||||||
|
for k, v := range data {
|
||||||
|
if now > v.Last+60*60*48 {
|
||||||
|
delete(data, k)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fmt.Println("Clean map:", l, "=>", len(data))
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
if len(bulk) > 0 {
|
if len(bulk) > 0 {
|
||||||
tx, err := Mysql.Begin()
|
tx, err := Mysql.Begin()
|
||||||
|
|
@ -160,23 +173,13 @@ func saveDB() {
|
||||||
Index int64 `json:"index"`
|
Index int64 `json:"index"`
|
||||||
}{
|
}{
|
||||||
Chanel: "chaturbate",
|
Chanel: "chaturbate",
|
||||||
Index: index["tokens"] / int64(seconds) * 3600 / 1000 * 5 / 100
|
Index: index["tokens"] / int64(seconds) * 3600 / 1000 * 5 / 100,
|
||||||
})
|
})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
socketServer <- msg
|
socketServer <- msg
|
||||||
}
|
}
|
||||||
index["last"] = now
|
index["last"] = now
|
||||||
}
|
}
|
||||||
|
|
||||||
if randInt(0, 10000) == 777 { // 0.001%
|
|
||||||
l := len(data)
|
|
||||||
for k, v := range data {
|
|
||||||
if now > v.Last+60*60*48 {
|
|
||||||
delete(data, k)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fmt.Println("Clean map:", l, "=>", len(data))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -184,6 +187,7 @@ func saveDB() {
|
||||||
func saveLogs() {
|
func saveLogs() {
|
||||||
bulk := []saveLog{}
|
bulk := []saveLog{}
|
||||||
ticker := time.NewTicker(10 * time.Second)
|
ticker := time.NewTicker(10 * time.Second)
|
||||||
|
defer ticker.Stop()
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue