Skip to content

Commit 04ced3d

Browse files
committed
Update
1 parent 74cc486 commit 04ced3d

1 file changed

Lines changed: 11 additions & 12 deletions

File tree

searxng.html

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@
2323
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']
2424
const LANGUAGES = ['en'];
2525
const TIMEOUT = 5000;
26-
const ATTEMPTS = 10;
26+
const ATTEMPTS = 5;
2727
const CUSTOM_PARAMS = ['attempts', 'languages', 'fast', 'instances', 'timeout'];
2828
const STATS_KEY = 'searxngRedirectorStats';
29-
const STATS_TTL_SECS = 24 * 60 * 60;
3029

3130
const tasks = [];
3231
const schedule = (f, pause) => tasks.push(setTimeout(f, pause));
@@ -78,8 +77,10 @@
7877
})
7978
.map(([u, i]) => {
8079
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];
8384
return [u, key];
8485
})
8586
.sort(([_a, a], [_b, b]) => {
@@ -161,14 +162,12 @@
161162
window.stop();
162163
if (i > 0) {
163164
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));
172171
}
173172

174173
const retryTargetUrl = new URL(targetUrl.toString());

0 commit comments

Comments
 (0)