Skip to content

Commit

Permalink
diff: automatically set replication url for 1m/1h/24h intervalls
Browse files Browse the repository at this point in the history
  • Loading branch information
olt committed Jun 19, 2024
1 parent 8d3ea00 commit 3881e3e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
10 changes: 8 additions & 2 deletions import_/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,15 @@ func estimateFromPBF(filename string, before time.Duration, replicationURL strin

func estimateFromTimestamp(timestamp time.Time, before time.Duration, replicationURL string, replicationInterval time.Duration) (*state.DiffState, error) {
if replicationURL == "" {
replicationURL = "https://planet.openstreetmap.org/replication/minute/"
switch replicationInterval {
case time.Hour:
replicationURL = "https://planet.openstreetmap.org/replication/hour/"
case time.Hour * 24:
replicationURL = "https://planet.openstreetmap.org/replication/day/"
default:
replicationURL = "https://planet.openstreetmap.org/replication/minute/"
}
}

seq, err := estimateSequence(replicationURL, replicationInterval, timestamp)
if err != nil {
return nil, errors.Wrap(err, "fetching current sequence for estimated import sequence")
Expand Down
6 changes: 2 additions & 4 deletions import_/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package import_

import (
"regexp"
"strings"
"testing"
"time"
)
Expand Down Expand Up @@ -38,7 +39,6 @@ func TestStateFromTimestamp(t *testing.T) {
timestamp: "2024-01-01T10:00:00+00:00",
expectedDailyDrift: 0.1,
maxSeq: 99065,
url: "https://planet.openstreetmap.org/replication/hour/",
before: time.Hour * 10,
interval: time.Hour,
},
Expand All @@ -47,7 +47,6 @@ func TestStateFromTimestamp(t *testing.T) {
timestamp: "2024-01-01T00:00:00+00:00",
expectedDailyDrift: 0.1,
maxSeq: 98825,
url: "https://planet.openstreetmap.org/replication/hour/",
before: time.Hour * 24 * 10,
interval: time.Hour,
},
Expand All @@ -56,7 +55,6 @@ func TestStateFromTimestamp(t *testing.T) {
timestamp: "2015-04-27T22:21:02+02:00",
expectedDailyDrift: 1.0 / 365,
maxSeq: 958,
url: "https://planet.openstreetmap.org/replication/day/",
before: time.Hour * 24 * 3,
interval: time.Hour * 24,
},
Expand Down Expand Up @@ -93,7 +91,7 @@ func TestStateFromTimestamp(t *testing.T) {
t.Fatal(err)
}
if tt.url == "" {
if state.URL != "https://planet.openstreetmap.org/replication/minute/" {
if !strings.HasPrefix(state.URL, "https://planet.openstreetmap.org/replication/") {
t.Error("unexpected state URL", state)
}
} else if state.URL != tt.url {
Expand Down

0 comments on commit 3881e3e

Please sign in to comment.