diff options
| author | siddharth ravikumar <s@ricketyspace.net> | 2026-04-01 21:12:16 -0400 |
|---|---|---|
| committer | siddharth ravikumar <s@ricketyspace.net> | 2026-04-01 21:12:26 -0400 |
| commit | 91d58507e84dd14caef1d7d3edfd10275642a643 (patch) | |
| tree | 5f298c282445ee76c4153edcbd9c2b33cec6f828 /db | |
| parent | 85ca1ebc7de98da7db308309edbcccee85281520 (diff) | |
db: go fix
Diffstat (limited to 'db')
| -rw-r--r-- | db/db.go | 8 | ||||
| -rw-r--r-- | db/db_test.go | 12 |
2 files changed, 6 insertions, 14 deletions
@@ -8,6 +8,7 @@ import ( "fmt" "os" "path" + "slices" "sync" "ricketyspace.net/fern/file" @@ -87,12 +88,7 @@ func (fdb *FernDB) exists(feed, entry string) bool { if _, ok := fdb.downloaded[feed]; !ok { return false } - for _, e := range fdb.downloaded[feed] { - if e == entry { - return true - } - } - return false + return slices.Contains(fdb.downloaded[feed], entry) } // Returns true if an `entry` for `feed` exists in the database; false diff --git a/db/db_test.go b/db/db_test.go index 966ce85..15c62a3 100644 --- a/db/db_test.go +++ b/db/db_test.go @@ -7,16 +7,12 @@ import ( "fmt" "os" "path" + "slices" "testing" ) func stringsContain(haystack []string, needle string) bool { - for _, s := range haystack { - if s == needle { - return true - } - } - return false + return slices.Contains(haystack, needle) } func TestOpenPathNotSet(t *testing.T) { @@ -386,7 +382,7 @@ func TestConcurrentWrites(t *testing.T) { // Randomly create a some entries. numEntries := 1000 entries := make([]string, 0) - for i := 0; i < numEntries; i++ { + for i := range numEntries { entries = append(entries, fmt.Sprintf("entry-%d", i)) } @@ -402,7 +398,7 @@ func TestConcurrentWrites(t *testing.T) { donec := make(chan int) feed := "npr" routines := 5 - for i := 0; i < routines; i++ { + for range routines { go addEntries(db, feed, entries, donec) } routinesDone := 0 |
