revert Remove redunant updates - we dont need them
This commit is contained in:
2025-12-21 04:51:50 -05:00
parent ba417d537d
commit 453e3e4154
2 changed files with 10 additions and 37 deletions
+3 -5
View File
@@ -301,15 +301,13 @@ async function checkAndBroadcastDomainChanges() {
}); });
} }
// Only send bulk update for changed domains (not added/removed, since those are handled individually) // Send update message with full state as fallback
if (changedDomains.length > 0) {
broadcastUpdate({ broadcastUpdate({
type: 'update', type: 'update',
data: currentState, data: currentState,
changedDomains: changedDomains.map(d => d.domain) changedDomains: [...addedDomains.map(d => d.domain), ...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}`);
} }
@@ -379,7 +377,7 @@ function setupWebSocketHandlers() {
data: state data: state
}); });
} }
}, 300000); // Update every 5 minutes as fallback (event-driven updates handle most changes) }, 30000); // Update every 30 seconds as fallback (event-driven updates handle most changes)
} }
/** /**
+3 -28
View File
@@ -484,30 +484,6 @@
} }
}); });
// 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;
@@ -769,12 +745,11 @@
} }
}); });
// Handle real-time updates (bulk updates, less frequent) // Handle real-time updates
window.wsClient.on('update', (data) => { window.wsClient.on('update', (data) => {
console.log('WebSocket bulk update received:', data); console.log('WebSocket update received:', data);
if (data.domains) { if (data.domains) {
// Only update if there are significant differences to avoid unnecessary re-renders updateDomainsDynamically(data.domains);
updateDomainsIfDifferent(data.domains);
} }
}); });