2
0
mirror of https://github.com/miguelmota/cointop synced 2024-11-05 00:00:14 +00:00

Merge branch 'lyricnz-feature/duplicate-symbols-cache-fix'

This commit is contained in:
Miguel Mota 2021-09-25 23:58:38 -07:00
commit ac9a4d44cc
No known key found for this signature in database
GPG Key ID: 67EC1161588A00F9
5 changed files with 20 additions and 10 deletions

View File

@ -10,10 +10,24 @@ import (
// CacheKey returns cached value given key
func (ct *Cointop) CacheKey(key string) string {
log.Debug("CacheKey()")
return strings.ToLower(fmt.Sprintf("%s_%s", ct.apiChoice, key))
}
// CompositeCacheKey returns a CacheKey for a coin (or globaldata)
func (ct *Cointop) CompositeCacheKey(symbol string, name string, convert string, chartRange string) string {
keyname := symbol
if name != "" {
keyname += "-" + name
}
if convert != "" {
keyname += "_" + convert
}
if chartRange != "" {
keyname += "_" + strings.Replace(chartRange, " ", "", -1) // "All Time" contains space
}
return ct.CacheKey(keyname)
}
// CacheAllCoinsSlugMap writes the coins map to the memory and disk cache
func (ct *Cointop) CacheAllCoinsSlugMap() {
log.Debug("CacheAllCoinsSlugMap()")

View File

@ -3,7 +3,6 @@ package cointop
import (
"fmt"
"sort"
"strings"
"sync"
"time"
@ -127,7 +126,7 @@ func (ct *Cointop) ChartPoints(symbol string, name string) error {
if keyname == "" {
keyname = "globaldata"
}
cachekey := ct.CacheKey(fmt.Sprintf("%s_%s", keyname, strings.Replace(ct.State.selectedChartRange, " ", "", -1)))
cachekey := ct.CompositeCacheKey(keyname, name, ct.State.currencyConversion, ct.State.selectedChartRange)
cached, found := ct.cache.Get(cachekey)
if found {
@ -219,7 +218,7 @@ func (ct *Cointop) PortfolioChart() error {
}
var graphData []float64
cachekey := strings.ToLower(fmt.Sprintf("%s_%s_%s", p.Symbol, convert, strings.Replace(selectedChartRange, " ", "", -1)))
cachekey := ct.CompositeCacheKey(p.Symbol, p.Name, convert, selectedChartRange)
cached, found := ct.cache.Get(cachekey)
if found {
// cache hit

View File

@ -445,7 +445,7 @@ func NewCointop(config *Config) (*Cointop, error) {
})
var globaldata []float64
chartcachekey := ct.CacheKey(fmt.Sprintf("%s_%s", "globaldata", strings.Replace(ct.State.selectedChartRange, " ", "", -1)))
chartcachekey := ct.CompositeCacheKey("globaldata", "", "", ct.State.selectedChartRange)
if ct.filecache != nil {
ct.filecache.Get(chartcachekey, &globaldata)
}

View File

@ -1,9 +1,6 @@
package cointop
import (
"fmt"
"strings"
log "github.com/sirupsen/logrus"
)
@ -99,7 +96,7 @@ func (ct *Cointop) layout() error {
ct.Views.Chart.SetBgColor(ct.colorscheme.GocuiBgColor(ct.Views.Chart.Name()))
go func() {
ct.UpdateChart()
cachekey := strings.ToLower(fmt.Sprintf("%s_%s", "globaldata", strings.Replace(ct.State.selectedChartRange, " ", "", -1)))
cachekey := ct.CompositeCacheKey("globaldata", "", "", ct.State.selectedChartRange)
_, found := ct.cache.Get(cachekey)
if found {
ct.cache.Delete(cachekey)

View File

@ -102,7 +102,7 @@ func (ct *Cointop) UpdateMarketbar() error {
var market types.GlobalMarketData
var err error
cachekey := ct.CacheKey("market")
cachekey := ct.CompositeCacheKey("market", "", ct.State.currencyConversion, "")
cached, found := ct.cache.Get(cachekey)
if found {