Add MC Query caching support.
ci/woodpecker/push/build Pipeline is pending Details

This commit is contained in:
Captain ALM 2023-08-13 21:21:18 +01:00
parent 3520b1bd17
commit 8c929c43f9
Signed by: alfred
GPG Key ID: 4E4ADD02609997B1
2 changed files with 21 additions and 4 deletions

View File

@ -14,6 +14,7 @@ type DataYaml struct {
MCProtocolVersion int `yaml:"mcProtocolVersion"` MCProtocolVersion int `yaml:"mcProtocolVersion"`
MCClientGUID int64 `yaml:"mcClientGUID"` MCClientGUID int64 `yaml:"mcClientGUID"`
MCTimeout time.Duration `yaml:"mcTimeout"` MCTimeout time.Duration `yaml:"mcTimeout"`
MCQueryInterval time.Duration `yaml:"mcQueryInterval"`
AllowDisplayState bool `yaml:"allowDisplayState"` AllowDisplayState bool `yaml:"allowDisplayState"`
AllowDisplayVersion bool `yaml:"allowDisplayVersion"` AllowDisplayVersion bool `yaml:"allowDisplayVersion"`
AllowDisplayActualAddress bool `yaml:"allowDisplayActualAddress"` AllowDisplayActualAddress bool `yaml:"allowDisplayActualAddress"`

View File

@ -38,6 +38,8 @@ type Page struct {
PageTemplateMutex *sync.Mutex PageTemplateMutex *sync.Mutex
PageTemplate *template.Template PageTemplate *template.Template
LastModifiedTemplate time.Time LastModifiedTemplate time.Time
CachedMC *MC
CollectedMCExpiry time.Time
} }
func (p *Page) GetPath() string { func (p *Page) GetPath() string {
@ -95,11 +97,25 @@ func (p *Page) GetContents(urlParameters url.Values) (contentType string, conten
Parameters: template.URL(p.getNonThemedCleanQuery(urlParameters)), Parameters: template.URL(p.getNonThemedCleanQuery(urlParameters)),
Online: true, Online: true,
} }
theMC, err := theMarshal.NewMC() var theMC MC
theMarshal.Queried = theMC if time.Now().After(p.CollectedMCExpiry) || time.Now().Equal(p.CollectedMCExpiry) {
if err != nil { theMC, err = theMarshal.NewMC()
theMarshal.Online = false if err == nil {
p.CachedMC = &theMC
} else {
theMarshal.Online = false
p.CachedMC = nil
}
p.CollectedMCExpiry = time.Now().Add(theData.MCQueryInterval)
} else {
if p.CachedMC == nil {
theMC = MC{}
theMarshal.Online = false
} else {
theMC = *p.CachedMC
}
} }
theMarshal.Queried = theMC
theBuffer := &io.BufferedWriter{} theBuffer := &io.BufferedWriter{}
err = theTemplate.ExecuteTemplate(theBuffer, templateName, theMarshal) err = theTemplate.ExecuteTemplate(theBuffer, templateName, theMarshal)
if err != nil { if err != nil {