Skip to content

Commit

Permalink
add timeout for version check
Browse files Browse the repository at this point in the history
  • Loading branch information
zyxkad committed Sep 30, 2023
1 parent 1071f8e commit 78855be
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions cmds/mcla/errdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/http"
"net/url"
"sync"
"time"

"github.com/GlobeMC/mcla"
)
Expand Down Expand Up @@ -41,6 +42,7 @@ type versionDataT struct {
type ghErrDB struct {
Prefix string
cachedVersion versionDataT
lastCheck time.Time
}

var _ mcla.ErrorDB = (*ghErrDB)(nil)
Expand Down Expand Up @@ -98,6 +100,10 @@ func (db *ghErrDB)getErrorDesc(id int)(desc *mcla.ErrorDesc, err error){
}

func (db *ghErrDB)checkUpdate()(err error){
if !db.lastCheck.IsZero() && time.Since(db.lastCheck) <= time.Minute {
return nil
}

newVersion, err := db.fetchGhDBVersion()
if err != nil {
return
Expand Down Expand Up @@ -151,6 +157,8 @@ func (db *ghErrDB)checkUpdate()(err error){
db.cachedVersion.Patch = newVersion.Patch
}
// setStorageValue("gh.db.version", db.cachedVersion)

db.lastCheck = time.Now()
return
}

Expand Down
8 changes: 8 additions & 0 deletions cmds/mcla_wasm/errdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"net/url"
"sync"
"time"

. "github.com/GlobeMC/mcla"
)
Expand Down Expand Up @@ -40,6 +41,7 @@ type versionDataT struct {
type ghErrDB struct {
Prefix string
cachedVersion versionDataT
lastCheck time.Time
}

var _ ErrorDB = (*ghErrDB)(nil)
Expand Down Expand Up @@ -94,6 +96,10 @@ func (db *ghErrDB)getErrorDesc(id int)(desc *ErrorDesc, err error){
}

func (db *ghErrDB)checkUpdate()(err error){
if !db.lastCheck.IsZero() && time.Since(db.lastCheck) <= time.Minute {
return nil
}

newVersion, err := db.fetchGhDBVersion()
if err != nil {
return
Expand Down Expand Up @@ -146,6 +152,8 @@ func (db *ghErrDB)checkUpdate()(err error){
db.cachedVersion.Patch = newVersion.Patch
}
setStorageValue("gh.db.version", db.cachedVersion)

db.lastCheck = time.Now()
return
}

Expand Down

0 comments on commit 78855be

Please sign in to comment.