Skip to content

Commit 8d32dc6

Browse files
committed
Keep resolvers that never had success in the database
1 parent ade658e commit 8d32dc6

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

www/db.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,11 +215,14 @@ func (d *DB) PruneOldResults(olderThan time.Duration) (int64, error) {
215215
}
216216

217217
// RemoveStaleResolvers removes resolvers that haven't had a successful response
218-
// in the given duration. Returns the names of removed resolvers.
218+
// in the given duration. Only removes resolvers that have had at least one
219+
// successful test in the past (to avoid removing newly added resolvers).
220+
// Returns the names of removed resolvers.
219221
func (d *DB) RemoveStaleResolvers(noSuccessSince time.Duration) ([]string, error) {
220222
cutoff := time.Now().Add(-noSuccessSince)
221223

222-
// Find resolvers with no successful test after cutoff
224+
// Find resolvers with no successful test after cutoff,
225+
// but that have had at least one successful test before
223226
rows, err := d.db.Query(`
224227
SELECT r.id, r.name
225228
FROM resolvers r
@@ -232,6 +235,7 @@ func (d *DB) RemoveStaleResolvers(noSuccessSince time.Duration) ([]string, error
232235
AND EXISTS (
233236
SELECT 1 FROM test_results t2
234237
WHERE t2.resolver_id = r.id
238+
AND t2.success = 1
235239
)
236240
`, cutoff)
237241
if err != nil {

www/main.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ func main() {
3737
}
3838
log.Printf("Parsed %d resolvers/relays", len(resolvers))
3939
tester.TestAll(resolvers)
40+
41+
// Remove resolvers with no successful response for more than a week
42+
removed, err := db.RemoveStaleResolvers(7 * 24 * time.Hour)
43+
if err != nil {
44+
log.Printf("Failed to remove stale resolvers: %v", err)
45+
} else if len(removed) > 0 {
46+
log.Printf("Removed %d stale resolvers: %v", len(removed), removed)
47+
}
4048
return
4149
}
4250

0 commit comments

Comments
 (0)