Remove redunant updates - we dont need them

This commit is contained in:
Raven Scott
2025-12-21 04:46:58 -05:00
parent 93de490353
commit ba417d537d
2 changed files with 37 additions and 10 deletions
+5 -3
View File
@@ -301,13 +301,15 @@ async function checkAndBroadcastDomainChanges() {
}); });
} }
// Send update message with full state as fallback // Only send bulk update for changed domains (not added/removed, since those are handled individually)
if (changedDomains.length > 0) {
broadcastUpdate({ broadcastUpdate({
type: 'update', type: 'update',
data: currentState, data: currentState,
changedDomains: [...addedDomains.map(d => d.domain), ...changedDomains.map(d => d.domain)] changedDomains: changedDomains.map(d => d.domain)
}); });
} }
}
} catch (err) { } catch (err) {
sdk.log.error('peer.directory', `Error checking domain changes: ${err.message}`); sdk.log.error('peer.directory', `Error checking domain changes: ${err.message}`);
} }
@@ -377,7 +379,7 @@ function setupWebSocketHandlers() {
data: state data: state
}); });
} }
}, 30000); // Update every 30 seconds as fallback (event-driven updates handle most changes) }, 300000); // Update every 5 minutes as fallback (event-driven updates handle most changes)
} }
/** /**
+28 -3
View File
@@ -484,6 +484,30 @@
} }
}); });
// Check if domains are actually different before updating
function updateDomainsIfDifferent(newDomains) {
// Compare lengths first
if (newDomains.length !== allDomains.length) {
console.log(`Domain count changed: ${allDomains.length}${newDomains.length}`);
updateDomainsDynamically(newDomains);
return;
}
// Check if any domains are different
const currentDomains = new Set(allDomains.map(d => d.domain));
const newDomainSet = new Set(newDomains.map(d => d.domain));
const added = newDomains.filter(d => !currentDomains.has(d.domain));
const removed = Array.from(currentDomains).filter(domain => !newDomainSet.has(domain));
if (added.length > 0 || removed.length > 0) {
console.log(`Domain changes detected: +${added.length} -${removed.length}`);
updateDomainsDynamically(newDomains);
} else {
console.log('No domain changes detected, skipping update');
}
}
// Dynamic domain update function // Dynamic domain update function
function updateDomainsDynamically(newDomains) { function updateDomainsDynamically(newDomains) {
const searchQuery = document.getElementById('searchInput').value; const searchQuery = document.getElementById('searchInput').value;
@@ -745,11 +769,12 @@
} }
}); });
// Handle real-time updates // Handle real-time updates (bulk updates, less frequent)
window.wsClient.on('update', (data) => { window.wsClient.on('update', (data) => {
console.log('WebSocket update received:', data); console.log('WebSocket bulk update received:', data);
if (data.domains) { if (data.domains) {
updateDomainsDynamically(data.domains); // Only update if there are significant differences to avoid unnecessary re-renders
updateDomainsIfDifferent(data.domains);
} }
}); });