-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #190 from moov-io/speedup-file-listing
filelist: only scan parts of bucket when listing files
- Loading branch information
Showing
4 changed files
with
154 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package yyyymmdd | ||
|
||
import ( | ||
"slices" | ||
"time" | ||
) | ||
|
||
// Given two time.Time values generate a start and end prefix (in yyyy-mm-dd format) | ||
// which serves as prefixs usable to filter. | ||
// | ||
// Examples: | ||
// | ||
// 2023-12-23 to 2023-12-31 produces 2023-12-2, 2023-12-3 | ||
// 2023-12-23 to 2024-01-10 produces 2023-12-2, 2023-12-3, 2024-01-0, 2024-01-10 | ||
func Prefixes(start, end time.Time) []string { | ||
var out []string | ||
|
||
// For now just iterate over each day and chop off the trailing day digit | ||
for { | ||
if start.After(end) { | ||
break | ||
} | ||
|
||
// Add the current day to our list | ||
ts := start.Format("2006-01-02") | ||
|
||
// Only when the end day is 10, 20, 30 we can extend the timestamp | ||
if (start.Month() == end.Month()) && (start.Day() == end.Day()) && end.Day()%10 == 0 { | ||
// do nothing | ||
} else { | ||
ts = ts[:len(ts)-1] // chop off the last digit | ||
} | ||
|
||
out = append(out, ts) | ||
|
||
start = start.Add(24 * time.Hour) | ||
} | ||
|
||
slices.Sort(out) | ||
return slices.Compact(out) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package yyyymmdd | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestPrefixes(t *testing.T) { | ||
start := time.Date(2023, time.December, 23, 0, 0, 0, 0, time.UTC) | ||
end := time.Date(2023, time.December, 31, 0, 0, 0, 0, time.UTC) | ||
expected := []string{"2023-12-2", "2023-12-3"} | ||
require.ElementsMatch(t, expected, Prefixes(start, end)) | ||
|
||
end = time.Date(2024, time.January, 4, 0, 0, 0, 0, time.UTC) | ||
expected = append(expected, "2024-01-0") | ||
require.ElementsMatch(t, expected, Prefixes(start, end)) | ||
|
||
end = time.Date(2024, time.January, 10, 0, 0, 0, 0, time.UTC) | ||
expected = append(expected, "2024-01-10") | ||
require.ElementsMatch(t, expected, Prefixes(start, end)) | ||
|
||
end = time.Date(2024, time.January, 11, 0, 0, 0, 0, time.UTC) | ||
expected = []string{"2023-12-2", "2023-12-3", "2024-01-0", "2024-01-1"} | ||
require.ElementsMatch(t, expected, Prefixes(start, end)) | ||
|
||
end = time.Date(2024, time.January, 20, 0, 0, 0, 0, time.UTC) | ||
expected = []string{"2023-12-2", "2023-12-3", "2024-01-0", "2024-01-1", "2024-01-20"} | ||
require.ElementsMatch(t, expected, Prefixes(start, end)) | ||
|
||
end = time.Date(2024, time.January, 25, 0, 0, 0, 0, time.UTC) | ||
expected = []string{"2023-12-2", "2023-12-3", "2024-01-0", "2024-01-1", "2024-01-2"} | ||
require.ElementsMatch(t, expected, Prefixes(start, end)) | ||
|
||
end = time.Date(2024, time.January, 30, 0, 0, 0, 0, time.UTC) | ||
expected = []string{"2023-12-2", "2023-12-3", "2024-01-0", "2024-01-1", "2024-01-2", "2024-01-30"} | ||
require.ElementsMatch(t, expected, Prefixes(start, end)) | ||
} |