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"`
MCClientGUID int64 `yaml:"mcClientGUID"`
MCTimeout time.Duration `yaml:"mcTimeout"`
MCQueryInterval time.Duration `yaml:"mcQueryInterval"`
AllowDisplayState bool `yaml:"allowDisplayState"`
AllowDisplayVersion bool `yaml:"allowDisplayVersion"`
AllowDisplayActualAddress bool `yaml:"allowDisplayActualAddress"`

View File

@ -38,6 +38,8 @@ type Page struct {
PageTemplateMutex *sync.Mutex
PageTemplate *template.Template
LastModifiedTemplate time.Time
CachedMC *MC
CollectedMCExpiry time.Time
}
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)),
Online: true,
}
theMC, err := theMarshal.NewMC()
theMarshal.Queried = theMC
if err != nil {
theMarshal.Online = false
var theMC MC
if time.Now().After(p.CollectedMCExpiry) || time.Now().Equal(p.CollectedMCExpiry) {
theMC, err = theMarshal.NewMC()
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{}
err = theTemplate.ExecuteTemplate(theBuffer, templateName, theMarshal)
if err != nil {