Skip to content

Commit

Permalink
Merge branch 'simon-anz-bugfix/range-update-corrupt-cache'
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelmota committed Aug 29, 2021
2 parents bda145d + 2c7f703 commit ebcb850
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions cointop/chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,10 @@ func (ct *Cointop) PortfolioChart() error {
chart := chartplot.NewChartPlot()
chart.SetHeight(ct.State.chartHeight)

rangeseconds := ct.chartRangesMap[ct.State.selectedChartRange]
if ct.State.selectedChartRange == "YTD" {
convert := ct.State.currencyConversion // cache here
selectedChartRange := ct.State.selectedChartRange // cache here
rangeseconds := ct.chartRangesMap[selectedChartRange]
if selectedChartRange == "YTD" {
ytd := time.Now().Unix() - int64(timeutil.BeginningOfYear().Unix())
rangeseconds = time.Duration(ytd) * time.Second
}
Expand All @@ -216,7 +218,7 @@ func (ct *Cointop) PortfolioChart() error {
}

var graphData []float64
cachekey := strings.ToLower(fmt.Sprintf("%s_%s", p.Symbol, strings.Replace(ct.State.selectedChartRange, " ", "", -1)))
cachekey := strings.ToLower(fmt.Sprintf("%s_%s_%s", p.Symbol, convert, strings.Replace(selectedChartRange, " ", "", -1)))
cached, found := ct.cache.Get(cachekey)
if found {
// cache hit
Expand All @@ -230,7 +232,6 @@ func (ct *Cointop) PortfolioChart() error {
if len(graphData) == 0 {
time.Sleep(2 * time.Second)

convert := ct.State.currencyConversion
apiGraphData, err := ct.api.GetCoinGraphData(convert, p.Symbol, p.Name, start, end)
if err != nil {
return err
Expand Down

0 comments on commit ebcb850

Please sign in to comment.