Skip to content

Commit

Permalink
remove latency flag
Browse files Browse the repository at this point in the history
Less useful than before given decreased edge focus, and doesn't work
on AWS.
  • Loading branch information
glommer committed Nov 27, 2024
1 parent 897d149 commit bebcc55
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 89 deletions.
41 changes: 0 additions & 41 deletions internal/cmd/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,52 +130,11 @@ func envAccessToken() (string, error) {
return token, nil
}

type latMap struct {
id string
lat int
}

func locations(client *turso.Client) (map[string]string, error) {
settings, _ := settings.ReadSettings()
return readLocations(settings, client)
}

func latencies(client *turso.Client) (map[string]int, error) {
settings, _ := settings.ReadSettings()
locations, err := readLocations(settings, client)
if err != nil {
return nil, err
}

var wg sync.WaitGroup
latencies := make(map[string]int)
c := make(chan latMap, len(locations))
for id := range locations {
wg.Add(1)
go func(id string) {
defer wg.Done()
measure := math.MaxInt
// XXX: Running this in different goroutines makes all latencies dogslow.
// Not sure if this is contention at the client or API level
for i := 0; i < 3; i++ {
d := turso.ProbeLocation(id)
if d != nil {
measure = int(math.Min(float64(d.Milliseconds()), float64(measure)))
}
}
c <- latMap{id: id, lat: measure}
}(id)
}

wg.Wait()
close(c)

for kvp := range c {
latencies[kvp.id] = kvp.lat
}
return latencies, nil
}

func readLocations(settings *settings.Settings, client *turso.Client) (map[string]string, error) {
if locations := locationsCache(); locations != nil {
return locations, nil
Expand Down
45 changes: 6 additions & 39 deletions internal/cmd/db_locations.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cmd

import (
"fmt"
"math"
"sort"

"github.com/spf13/cobra"
Expand All @@ -13,7 +12,6 @@ import (

func init() {
dbCmd.AddCommand(regionsCmd)
addLatencyFlag(regionsCmd)
}

var regionsCmd = &cobra.Command{
Expand All @@ -39,52 +37,21 @@ var regionsCmd = &cobra.Command{

columns := make([]interface{}, 0)

lats := make(map[string]int)
var ids []string
if latencyFlag {
lats, err = latencies(client)
if err != nil {
return err
}
ids = maps.Keys(lats)
sort.Slice(ids, func(i, j int) bool {
return lats[ids[i]] < lats[ids[j]]
})
columns = append(columns, "ID")
columns = append(columns, "LOCATION")
columns = append(columns, "LATENCY↓")
} else {
ids = maps.Keys(locations)
sort.Strings(ids)
columns = append(columns, "ID↓")
columns = append(columns, "LOCATION")
}
ids = maps.Keys(locations)
sort.Strings(ids)
columns = append(columns, "ID↓")
columns = append(columns, "LOCATION")

tbl := turso.LocationsTable(columns)

for _, location := range ids {
description := locations[location]
lat, ok := lats[location]
var latency string
if ok && lat != math.MaxInt {
latency = fmt.Sprintf("%dms", lat)
} else {
latency = "???"
}

if location == closest {
description = fmt.Sprintf("%s [default]", description)
if latencyFlag {
tbl.AddRow(internal.Emph(location), internal.Emph(description), internal.Emph(latency))
} else {
tbl.AddRow(internal.Emph(location), internal.Emph(description))
}
tbl.AddRow(internal.Emph(location), internal.Emph(description))
} else {
if latencyFlag {
tbl.AddRow(location, description, latency)
} else {
tbl.AddRow(location, description)
}
tbl.AddRow(location, description)
}
}
tbl.Print()
Expand Down
9 changes: 0 additions & 9 deletions internal/cmd/latencies.go

This file was deleted.

0 comments on commit bebcc55

Please sign in to comment.