DNS Cache verbesser
This commit is contained in:
@@ -2,42 +2,77 @@
|
|||||||
DNS CACHE (mit TTL)
|
DNS CACHE (mit TTL)
|
||||||
========================= */
|
========================= */
|
||||||
|
|
||||||
|
// =========================
|
||||||
|
// DNS CACHE (minimal + robust)
|
||||||
|
// =========================
|
||||||
|
|
||||||
|
const DNS_CACHE_TTL = 300000 // 5 min für erfolgreiche Antworten
|
||||||
|
const DNS_ERROR_TTL = 5000 // 5 sek für Fehler
|
||||||
|
|
||||||
const dnsCache = {}
|
const dnsCache = {}
|
||||||
|
const pending = {}
|
||||||
|
|
||||||
|
function normalizeDomain(domain) {
|
||||||
|
return domain.trim().toLowerCase()
|
||||||
|
}
|
||||||
|
|
||||||
async function getDNS(domain){
|
async function getDNS(domain){
|
||||||
|
|
||||||
|
if(!domain) return []
|
||||||
|
|
||||||
|
const key = normalizeDomain(domain)
|
||||||
const now = Date.now()
|
const now = Date.now()
|
||||||
const TTL = 30000 // 30 Sekunden
|
|
||||||
|
|
||||||
if(dnsCache[domain] && (now - dnsCache[domain].time < TTL)){
|
const cached = dnsCache[key]
|
||||||
return dnsCache[domain].ips
|
|
||||||
|
// ✅ gültiger Cache
|
||||||
|
if(cached && (now - cached.time < cached.ttl)){
|
||||||
|
return cached.ips
|
||||||
}
|
}
|
||||||
|
|
||||||
try{
|
// ✅ laufende Anfrage wiederverwenden (dedupe)
|
||||||
|
if(pending[key]){
|
||||||
const res = await api(API + "/dns/" + domain, {}, { showError: false })
|
return pending[key]
|
||||||
const ips = res.ips || []
|
|
||||||
|
|
||||||
dnsCache[domain] = {
|
|
||||||
ips: ips,
|
|
||||||
time: now
|
|
||||||
}
|
|
||||||
|
|
||||||
return ips
|
|
||||||
|
|
||||||
}catch(e){
|
|
||||||
|
|
||||||
dnsCache[domain] = {
|
|
||||||
ips: [],
|
|
||||||
time: now
|
|
||||||
}
|
|
||||||
|
|
||||||
return []
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pending[key] = (async () => {
|
||||||
|
try{
|
||||||
|
const res = await api(
|
||||||
|
API + "/dns/" + encodeURIComponent(key),
|
||||||
|
{},
|
||||||
|
{ showError: false }
|
||||||
|
)
|
||||||
|
|
||||||
|
const ips = res?.ips || []
|
||||||
|
|
||||||
|
dnsCache[key] = {
|
||||||
|
ips,
|
||||||
|
time: Date.now(),
|
||||||
|
ttl: DNS_CACHE_TTL
|
||||||
|
}
|
||||||
|
|
||||||
|
return ips
|
||||||
|
|
||||||
|
}catch(e){
|
||||||
|
|
||||||
|
// ❗ Fehler nur kurz cachen
|
||||||
|
dnsCache[key] = {
|
||||||
|
ips: [],
|
||||||
|
time: Date.now(),
|
||||||
|
ttl: DNS_ERROR_TTL
|
||||||
|
}
|
||||||
|
|
||||||
|
return []
|
||||||
|
|
||||||
|
}finally{
|
||||||
|
delete pending[key]
|
||||||
|
}
|
||||||
|
})()
|
||||||
|
|
||||||
|
return pending[key]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function dnsStatusMarkup(expectedIp, ips){
|
function dnsStatusMarkup(expectedIp, ips){
|
||||||
|
|
||||||
if(!ips.length){
|
if(!ips.length){
|
||||||
|
|||||||
Reference in New Issue
Block a user