Skip to content

Commit

Permalink
Blockchain Statistics Update Cache Function (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
jessicaqgomez authored Apr 21, 2023
1 parent 318fb91 commit 0e23960
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ test_env_start: ## Start up backing services in test mode
@docker-compose -f docker/test_env/docker-compose.yml up --remove-orphans -d

test_env_rm: ## Stop and remove all test mode services
@docker-compose -f docker/standalone/docker-compose.yml down --remove-orphans --volumes
@docker-compose -f docker/test_env/docker-compose.yml down --remove-orphans --volumes

standalone_run: ## Run standalone mode
@docker-compose -f docker/standalone/docker-compose.yml up --remove-orphans
Expand Down
1 change: 1 addition & 0 deletions caching/aggregates_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@ func updateStatisticsCacheInfo(dbRunner *dbr.Session, transactionCache []models.
fmt.Println("Error insert: ", err.Error())
}
}
result = []models.StatisticsCache{}
}
}

Expand Down
4 changes: 2 additions & 2 deletions models/collections.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ type CResult struct {
type StatisticsStruct struct {
HighestNumber float64 `json:"highestValue"`
HighestDate string `json:"highestDate"`
LowestNumber float64 `json:"lowerValue"`
LowestDate string `json:"lowerDate"`
LowestNumber float64 `json:"lowestValue"`
LowestDate string `json:"lowestDate"`
TxInfo interface{} `json:"txInfo"`
}

Expand Down
8 changes: 4 additions & 4 deletions services/indexes/avax/reader_list_txs.go
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ func (r *Reader) GasUsedPerDay(ctx context.Context, p *params.ListParams) (model
func (r *Reader) AvgGasPriceUsed(ctx context.Context, p *params.ListParams) (models.StatisticsStruct, error) {
dbRunner, err := r.conns.DB().NewSession("avg_gas_price", cfg.RequestTimeout)
if err != nil {
return models.StatisticsStruct{TxInfo: []models.TransactionsInfo{}}, err
return models.StatisticsStruct{TxInfo: []models.GasUsedPerDate{}}, err
}
var gasPrice []*models.GasUsedPerDate
var statisticsStruct models.StatisticsStruct
Expand All @@ -846,7 +846,7 @@ func (r *Reader) AvgGasPriceUsed(ctx context.Context, p *params.ListParams) (mod

_, err = sa.LoadContext(ctx, &gasPrice)
if err != nil {
return models.StatisticsStruct{TxInfo: []models.TransactionsInfo{}}, err
return models.StatisticsStruct{TxInfo: []models.GasUsedPerDate{}}, err
}

_, err = dbRunner.Select("date as highest_date", "gas as highest_number").
Expand All @@ -855,7 +855,7 @@ func (r *Reader) AvgGasPriceUsed(ctx context.Context, p *params.ListParams) (mod
LoadContext(ctx, &statisticsStruct)

if err != nil {
return models.StatisticsStruct{TxInfo: []models.TransactionsInfo{}}, err
return models.StatisticsStruct{TxInfo: []models.GasUsedPerDate{}}, err
}

_, err = dbRunner.Select("date as lowest_date", "gas as lowest_number").
Expand All @@ -864,7 +864,7 @@ func (r *Reader) AvgGasPriceUsed(ctx context.Context, p *params.ListParams) (mod
LoadContext(ctx, &statisticsStruct)

if err != nil || len(gasPrice) == 0 {
return models.StatisticsStruct{TxInfo: []models.TransactionsInfo{}}, err
return models.StatisticsStruct{TxInfo: []models.GasUsedPerDate{}}, err
}

statisticsStruct.TxInfo = gasPrice
Expand Down

0 comments on commit 0e23960

Please sign in to comment.