Skip to content

Commit

Permalink
fix: include most recent candles in the API response
Browse files Browse the repository at this point in the history
Signed-off-by: Elias Van Ootegem <[email protected]>
  • Loading branch information
EVODelavega committed Sep 23, 2024
1 parent 604858c commit c549c4e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
12 changes: 5 additions & 7 deletions datanode/candlesv2/candle_updates.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,18 +196,16 @@ func (s *CandleUpdates) getCandleUpdates(ctx context.Context, lastCandle *entiti
return nil, fmt.Errorf("getting candle updates:%w", err)
}

// allocate slice rather than doubling cap as we go.
updates = make([]entities.Candle, 0, len(candles))
for _, candle := range candles {
if candle.LastUpdateInPeriod.After(lastCandle.LastUpdateInPeriod) || candle.PeriodStart.After(lastCandle.PeriodStart) {
// not before so either newer, or the same (last) candle should be returned.
if !candle.LastUpdateInPeriod.Before(lastCandle.LastUpdateInPeriod) || !candle.PeriodStart.Before(lastCandle.PeriodStart) {
updates = append(updates, candle)
}
}
} else {
last := int32(1)
pagination, err := entities.NewCursorPagination(nil, nil, &last, nil, false)
if err != nil {
return nil, err
}
updates, _, err = s.candleSource.GetCandleDataForTimeSpan(ctx, s.candleID, nil, &now, pagination)
updates, _, err = s.candleSource.GetCandleDataForTimeSpan(ctx, s.candleID, nil, &now, entities.CursorPagination{})

if err != nil {
return nil, fmt.Errorf("getting candle updates:%w", err)
Expand Down
3 changes: 3 additions & 0 deletions datanode/sqlstore/candles.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"code.vegaprotocol.io/vega/datanode/entities"
"code.vegaprotocol.io/vega/datanode/metrics"
"code.vegaprotocol.io/vega/libs/crypto"
"code.vegaprotocol.io/vega/logging"
v2 "code.vegaprotocol.io/vega/protos/data-node/api/v2"

"github.com/georgysavva/scany/pgxscan"
Expand Down Expand Up @@ -193,6 +194,8 @@ func (cs *Candles) GetCandleDataForTimeSpan(ctx context.Context, candleID string

// now that we have the paged query, we can add in the subquery
query = fmt.Sprintf("with gap_filled_candles as (%s) %s", subQuery, query)
cs.log.Debug(">> Candle query", logging.String("query", query))
fmt.Printf(">>> QUERY: %s\n", query)

Check failure on line 198 in datanode/sqlstore/candles.go

View workflow job for this annotation

GitHub Actions / lint

use of `fmt.Printf` forbidden by pattern `fmt\.Print.*` (forbidigo)

defer metrics.StartSQLQuery("Candles", "GetCandleDataForTimeSpan")()
err = pgxscan.Select(ctx, cs.ConnectionSource, &candles, query, args...)
Expand Down

0 comments on commit c549c4e

Please sign in to comment.