Skip to content

Commit

Permalink
Merge pull request #130 from ipinfo/uman/fix-upper-limit
Browse files Browse the repository at this point in the history
Use `lats` len or a 10k upper limit otherwise
  • Loading branch information
UmanShahzad authored Feb 1, 2023
2 parents 66f77c7 + 47fd6b1 commit e648e11
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion ipinfo/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,11 @@ func (c *BoltdbCache) delBulk() {

// sort by last-accessed timestamp, and delete the oldest 10k in bulk.
sort.Sort(lats)
for i := 0; i < 10000; i++ {
upperLimit := len(lats)
if upperLimit > 10000 {
upperLimit = 10000
}
for i := 0; i < upperLimit; i++ {
if err := bucket.Delete([]byte(lats[i].k)); err != nil {
return err
}
Expand Down

0 comments on commit e648e11

Please sign in to comment.