|
23 | 23 | const INSTANCES = ['search.charliewhiskey.net', 'search.im-in.space', 'search.ipsys.bf', 'search.mycotrip.tech', 'search.ononoki.org', 'search.pollorebozado.com', 'search.rowie.at', 'search.system51.co.uk', 'search.undertale.uk', 'search.url4irl.com', 'searx.bndkt.io', 'searx.dresden.network', 'searx.foss.family', 'searx.oloke.xyz', 'searx.ox2.fr', 'searx.party', 'searx.perennialte.ch', 'searx.tiekoetter.com', 'searx.zhenyapav.com', 'searxng.shreven.org'] |
24 | 24 | const LANGUAGES = ['en']; |
25 | 25 | const TIMEOUT = 5000; |
26 | | -const ATTEMPTS = 10; |
| 26 | +const ATTEMPTS = 5; |
27 | 27 | const CUSTOM_PARAMS = ['attempts', 'languages', 'fast', 'instances', 'timeout']; |
28 | 28 | const STATS_KEY = 'searxngRedirectorStats'; |
29 | | -const STATS_TTL_SECS = 24 * 60 * 60; |
30 | 29 |
|
31 | 30 | const tasks = []; |
32 | 31 | const schedule = (f, pause) => tasks.push(setTimeout(f, pause)); |
|
78 | 77 | }) |
79 | 78 | .map(([u, i]) => { |
80 | 79 | const s = searxngRedirectorStats[u.hostname]; |
81 | | - const localOkRate = (s && s.ttl > currentTime()) ? (s.ok + 1) / (s.failures + 1) : 1; |
82 | | - const key = [localOkRate, i?.uptime?.uptimeDay, i?.uptime?.uptimeMonth, 1 / i?.engines?.google?.error_rate, 1 / i?.engines?.duckduckgo?.error_rate]; |
| 80 | + const localOkRate = s ? (s.ok.count + 1) / (s.failure.count + 1) : 1; |
| 81 | + const localOkUpdate = s ? s.ok.updated : 0; |
| 82 | + const localFailureUpdate = s ? s.failure.updated : Infinity; |
| 83 | + const key = [localOkUpdate, 1 / localFailureUpdate, localOkRate, i?.uptime?.uptimeDay, i?.uptime?.uptimeMonth, 1 / i?.engines?.google?.error_rate, 1 / i?.engines?.duckduckgo?.error_rate]; |
83 | 84 | return [u, key]; |
84 | 85 | }) |
85 | 86 | .sort(([_a, a], [_b, b]) => { |
|
161 | 162 | window.stop(); |
162 | 163 | if (i > 0) { |
163 | 164 | const searxngRedirectorStats = JSON.parse(localStorage.getItem(STATS_KEY) || '{}'); |
164 | | - const stats = searxngRedirectorStats[new URL(shuffledInstances[i - 1]).hostname] || { ok: 0, failures: 0, ttl: 0 }; |
165 | | - stats.failures++; |
166 | | - stats.ttl = currentTime() + STATS_TTL_SECS; |
167 | | - |
168 | | - const newValue = Object.fromEntries(Object.entries(searxngRedirectorStats) |
169 | | - .filter(([_k, v]) => v.ttl > currentTime())); |
170 | | - console.log('updating SearXNG redirector stats', newValue); |
171 | | - localStorage.setItem(STATS_KEY, JSON.stringify(newValue)); |
| 165 | + const stats = searxngRedirectorStats[new URL(shuffledInstances[i - 1]).hostname] || { ok: { count: 0, updated: 0 }, failure: { count: 0, updated: 0 } }; |
| 166 | + stats.failure.count++; |
| 167 | + stats.failure.updated = currentTime(); |
| 168 | + |
| 169 | + console.log('updating SearXNG redirector stats', searxngRedirectorStats); |
| 170 | + localStorage.setItem(STATS_KEY, JSON.stringify(searxngRedirectorStats)); |
172 | 171 | } |
173 | 172 |
|
174 | 173 | const retryTargetUrl = new URL(targetUrl.toString()); |
|
0 commit comments