Skip to content

Commit

Permalink
feat: write gohbem masterfile to cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabio1988 committed Jan 7, 2025
1 parent 955b8ef commit 68bbdfd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
15 changes: 12 additions & 3 deletions decoder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,10 @@ func InitialiseOhbem() {
}

gohbemLogger := &gohbemLogger{}

cacheFileLocation := "cache/master-latest-basics.json"
o := &gohbem.Ohbem{Leagues: leagues, LevelCaps: config.Config.Pvp.LevelCaps,
IncludeHundosUnderCap: config.Config.Pvp.IncludeHundosUnderCap, Logger: gohbemLogger}
IncludeHundosUnderCap: config.Config.Pvp.IncludeHundosUnderCap,
MasterFileCachePath: cacheFileLocation, Logger: gohbemLogger}
switch config.Config.Pvp.RankingComparator {
case "prefer_higher_cp":
o.RankingComparator = gohbem.RankingComparatorPreferHigherCp
Expand All @@ -197,7 +198,15 @@ func InitialiseOhbem() {
}

if err := o.FetchPokemonData(); err != nil {
log.Errorf("ohbem.FetchPokemonData: %s", err)
if err2 := o.LoadPokemonData(cacheFileLocation); err2 != nil {
log.Errorf("ohbem.FetchPokemonData failed. ohbem.LoadPokemonData failed: %s", err2)
} else {
log.Warnf("ohbem.FetchPokemonData failed, loaded from cache: %s", err)
}
}

if o.PokemonData.Initialized == true {
_ = o.SavePokemonData(cacheFileLocation)
}

_ = o.WatchPokemonData()
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ toolchain go1.23.2

require (
github.com/Depado/ginprom v1.8.1
github.com/UnownHash/gohbem v0.11.3
github.com/UnownHash/gohbem v0.12.0
github.com/getsentry/sentry-go v0.29.1
github.com/gin-gonic/gin v1.10.0
github.com/go-sql-driver/mysql v1.8.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERo
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
github.com/UnownHash/gohbem v0.11.3 h1:ffl+EMsp74GoSReJ+O2LSFwTeBVL/vHRnz0Yf6h77GY=
github.com/UnownHash/gohbem v0.11.3/go.mod h1:I7SrAlxOo56fGlUD7pLtitcGcmRd7rr9/HWpgmseqSc=
github.com/UnownHash/gohbem v0.12.0 h1:eSyioEWJSU/81i6wf5x4XaiRZBXm6dW/KuYiHKjcELI=
github.com/UnownHash/gohbem v0.12.0/go.mod h1:PUeicvRH6HyjTgkuaivjYHzDUzErf2QlsXZ24m0DaNU=
github.com/appleboy/gofight/v2 v2.1.2 h1:VOy3jow4vIK8BRQJoC/I9muxyYlJ2yb9ht2hZoS3rf4=
github.com/appleboy/gofight/v2 v2.1.2/go.mod h1:frW+U1QZEdDgixycTj4CygQ48yLTUhplt43+Wczp3rw=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
Expand Down

0 comments on commit 68bbdfd

Please sign in to comment.