Skip to content

Commit

Permalink
Fix: histogram (#721)
Browse files Browse the repository at this point in the history
  • Loading branch information
aopoltorzhicky authored Jun 30, 2021
1 parent e5d2501 commit 9762dda
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 30 deletions.
3 changes: 3 additions & 0 deletions cmd/api/handlers/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ type getSeriesRequest struct {
}

func (req getSeriesRequest) isCached() bool {
if req.Address != "" {
return false
}
return req.Period == "month" && (req.Name == "contract" || req.Name == "operation" || req.Name == "paid_storage_size_diff" || req.Name == "consumed_gas")
}

Expand Down
17 changes: 16 additions & 1 deletion internal/postgres/core/histogram.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (p *Postgres) GetDateHistogram(period string, opts ...models.HistogramOptio
func (p *Postgres) GetCachedHistogram(period, name, network string) ([][]float64, error) {
view := fmt.Sprintf(`series_%s_by_%s_%s`, name, period, network)
var res []HistogramResponse
if err := p.DB.Table(view).Find(&res).Error; err != nil {
if err := p.DB.Table(view).Limit(limit(period)).Order("date_part desc").Find(&res).Error; err != nil {
return nil, err
}
hist := make([][]float64, 0, len(res))
Expand Down Expand Up @@ -175,3 +175,18 @@ func GetHistogramInterval(period string) string {
return "date '2018-06-25'"
}
}

func limit(period string) int {
switch period {
case "hour":
return 24
case "day":
return 30
case "week":
return 14
case "month":
return 12
default:
return 60
}
}
58 changes: 29 additions & 29 deletions scripts/nginx/nginx.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import (
)

const (
ogTitle = "Better Call Dev"
ogDescription = "Tezos smart contract explorer, developer dashboard, and API provider. Easy to spin up / integrate with your sandbox."
ogImage = "/img/logo_og.png"
pageTitle = "Better Call Dev — Tezos smart contract explorer by Baking Bad"
dappsTitle = "Tezos DApps"
pageDescription = "Tezos smart contract explorer & developer dashboard, simplifies perception and facilitates interaction. By Baking Bad."
dappsDescription = "Track the Tezos ecosystem growth: aggregated DApps usage stats, DEX token turnover, affiliated smart contracts, screenshots, social links, and more."
contractDescription = "Check out recent operations, inspect contract code and storage, invoke contract methods."
ogTitle = "Better Call Dev"
ogDescription = "Tezos smart contract explorer, developer dashboard, and API provider. Easy to spin up / integrate with your sandbox."
ogImage = "/img/logo_og.png"
pageTitle = "Better Call Dev — Tezos smart contract explorer by Baking Bad"
dappsTitle = "Tezos DApps"
pageDescription = "Tezos smart contract explorer & developer dashboard, simplifies perception and facilitates interaction. By Baking Bad."
dappsDescription = "Track the Tezos ecosystem growth: aggregated DApps usage stats, DEX token turnover, affiliated smart contracts, screenshots, social links, and more."
// contractDescription = "Check out recent operations, inspect contract code and storage, invoke contract methods."
)

const defaultConfTemplate = `server {
Expand Down Expand Up @@ -57,7 +57,7 @@ const locationTemplate = `
sub_filter_once on;
}`

func makeNginxConfig(dapps []dapp.DApp, aliases []tzip.TZIP, filepath, baseURL string) error {
func makeNginxConfig(dapps []dapp.DApp, _ []tzip.TZIP, filepath, baseURL string) error {
var locations strings.Builder
tmpl := template.Must(template.New("").Parse(locationTemplate))

Expand Down Expand Up @@ -152,26 +152,26 @@ func makeDappRootLocation(tmpl *template.Template, path, baseURL string) (string
return buf.String(), nil
}

func makeContractsLocation(tmpl *template.Template, address, alias, baseURL string) (string, error) {
buf := new(bytes.Buffer)
err := tmpl.Execute(buf, map[string]interface{}{
"location": fmt.Sprintf("/mainnet/%s", address),
"url": fmt.Sprintf("%s/mainnet/%s", baseURL, address),
"title": fmt.Sprintf("%s — %s", sanitizeQuotes(alias), ogTitle),
"description": contractDescription,
"ogTitle": ogTitle,
"ogDescription": ogDescription,
"ogImage": ogImage,
"pageTitle": pageTitle,
"pageDescription": pageDescription,
"logoURL": ogImage,
})
if err != nil {
return "", err
}

return buf.String(), nil
}
// func makeContractsLocation(tmpl *template.Template, address, alias, baseURL string) (string, error) {
// buf := new(bytes.Buffer)
// err := tmpl.Execute(buf, map[string]interface{}{
// "location": fmt.Sprintf("/mainnet/%s", address),
// "url": fmt.Sprintf("%s/mainnet/%s", baseURL, address),
// "title": fmt.Sprintf("%s — %s", sanitizeQuotes(alias), ogTitle),
// "description": contractDescription,
// "ogTitle": ogTitle,
// "ogDescription": ogDescription,
// "ogImage": ogImage,
// "pageTitle": pageTitle,
// "pageDescription": pageDescription,
// "logoURL": ogImage,
// })
// if err != nil {
// return "", err
// }

// return buf.String(), nil
// }

func sanitizeQuotes(str string) string {
return strings.ReplaceAll(str, "'", "’")
Expand Down

0 comments on commit 9762dda

Please sign in to comment.