Compare commits

...

3 Commits

Author SHA1 Message Date
daru
17a754b918 Anime lists did not age well 😵‍💫 2022-08-25 23:32:31 +02:00
daru
730f91e74e Anime lists didn't age well 😵‍💫 2022-08-25 23:31:18 +02:00
daru
dbd34abea1 Anime list fetching not broken but ugly insted ✔️ 2022-08-25 22:54:21 +02:00
5 changed files with 38 additions and 23 deletions

4
go.mod
View File

@@ -25,6 +25,6 @@ require (
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect
github.com/xujiajun/mmap-go v1.0.1 // indirect
github.com/xujiajun/utils v0.0.0-20190123093513-8bf096c4f53b // indirect
golang.org/x/crypto v0.0.0-20220817201139-bc19a97f63c8 // indirect
golang.org/x/sys v0.0.0-20220818161305-2296e01440c6 // indirect
golang.org/x/crypto v0.0.0-20220824171710-5757bc0c5503 // indirect
golang.org/x/sys v0.0.0-20220823224334-20c2bfdbfe24 // indirect
)

8
go.sum
View File

@@ -58,8 +58,8 @@ github.com/xujiajun/utils v0.0.0-20190123093513-8bf096c4f53b/go.mod h1:AZd87GYJl
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8=
golang.org/x/crypto v0.0.0-20220214200702-86341886e292/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.0.0-20220817201139-bc19a97f63c8 h1:GIAS/yBem/gq2MUqgNIzUHW7cJMmx3TGZOrnyYaNQ6c=
golang.org/x/crypto v0.0.0-20220817201139-bc19a97f63c8/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.0.0-20220824171710-5757bc0c5503 h1:vJ2V3lFLg+bBhgroYuRfyN583UzVveQmIXjc8T/y3to=
golang.org/x/crypto v0.0.0-20220824171710-5757bc0c5503/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210510120150-4163338589ed/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
@@ -73,8 +73,8 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220405210540-1e041c57c461/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220818161305-2296e01440c6 h1:Sx/u41w+OwrInGdEckYmEuU5gHoGSL4QbDz3S9s6j4U=
golang.org/x/sys v0.0.0-20220818161305-2296e01440c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220823224334-20c2bfdbfe24 h1:TyKJRhyo17yWxOMCTHKWrc5rddHORMlnZ/j57umaUd8=
golang.org/x/sys v0.0.0-20220823224334-20c2bfdbfe24/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=

View File

@@ -20,7 +20,7 @@ import (
)
const (
husoVersion = "1.7"
husoVersion = "1.7.1"
registerSecret = "綾波レイ"
seasonStrJikan = "seasons/"
userApiJikan = "users/"
@@ -67,6 +67,7 @@ var (
logOut *RingBuf
buildTime string
buildCommit string
lastAnnounce *SomewhatThreadSafeTime
)
func main() {
@@ -107,7 +108,7 @@ func main() {
log.Fatal(err)
}
defer searchCache.Close()
animeListCache, err = bigcache.NewBigCache(bigcache.DefaultConfig(42 * time.Minute))
animeListCache, err = bigcache.NewBigCache(bigcache.DefaultConfig(15 * time.Minute))
if err != nil {
log.Fatal(err)
}
@@ -126,6 +127,10 @@ func main() {
}
defer db.Close()
lastAnnounce = &SomewhatThreadSafeTime{
stamp: time.Now().Add(-1 * time.Hour),
}
color.Infoln("NutsDB connected")
logOut.WriteLine("🗃️ NutsDB connected")

View File

@@ -1,6 +1,9 @@
package main
import "time"
import (
"sync"
"time"
)
type AnimeUser struct {
Anime int64 `json:"anime"`
@@ -328,3 +331,8 @@ type MovieChart struct {
AvgScore float64 `json:"avgScore"`
UserCount int `json:"userCount"`
}
type SomewhatThreadSafeTime struct {
sync.Mutex
stamp time.Time
}

View File

@@ -12,7 +12,7 @@ import (
)
func Arbeiten() {
for range time.Tick(20 * time.Minute) {
for range time.Tick(10 * time.Minute) {
Arbeit()
}
}
@@ -27,15 +27,9 @@ func Arbeit() {
}
} else {
cleared := 0
checkDate := time.Now().Add(-1 * time.Hour)
lastAnnounce.Lock()
defer lastAnnounce.Unlock()
newCheckDate := time.Now()
data, err := animeListCache.Get(bucketAppoint)
if err == nil {
nanora, err := BytesToInt64(data)
if err == nil {
checkDate = time.Unix(0, nanora)
}
}
for _, a := range appoints {
if a.Time.Add(22 * time.Hour).Before(newCheckDate) {
// appointment expired
@@ -48,13 +42,13 @@ func Arbeit() {
cleared++
}
} else {
if checkDate.Add(time.Hour).Before(a.Time) && newCheckDate.Add(time.Hour).After(a.Time) {
if lastAnnounce.stamp.Add(time.Hour).Before(a.Time) && newCheckDate.Add(time.Hour).After(a.Time) {
// This has not happened and is happening soon
go AnnounceBomb(a.Anime, a.Time.Unix(), time.Until(a.Time.Add(-25*time.Minute)))
}
}
}
animeListCache.Set(bucketAppoint, Int64ToByte(newCheckDate.UnixNano()))
lastAnnounce.stamp = newCheckDate
if cleared > 0 {
color.Infof("Cleared %d expired appointments\n", cleared)
logOut.WriteLine(fmt.Sprintf("♻️ Cleared %d expired appointments", cleared))
@@ -70,8 +64,13 @@ func Arbeit() {
}
return
}
// ACTUALLY STUPID ENOUGH TO FIX A LOT OF PROBLEMS
animeListCache.Reset()
color.Infoln("Animelisten abfragen...")
logOut.WriteLine("📜 Animelisten abfragen...")
//logOut.WriteLine("📜 Animelisten abfragen...")
count := 0
// iterate anime
for _, a := range animesUsers {
@@ -123,8 +122,11 @@ func Arbeit() {
count++
}
}
color.Infof("%d Sachen aktualisiert\n", count)
logOut.WriteLine(fmt.Sprintf("📜 %d Sachen aktualisiert", count))
if count > 0 {
color.Infof("%d Sachen aktualisiert\n", count)
logOut.WriteLine(fmt.Sprintf("📜 %d Sachen aktualisiert", count))
}
}
func BissleArbeiten() {