Skip to content

Remove redundant interval-based distance updater#124

Merged
MrAlders0n merged 2 commits intodevfrom
copilot/remove-distance-updater-function
Dec 22, 2025
Merged

Remove redundant interval-based distance updater#124
MrAlders0n merged 2 commits intodevfrom
copilot/remove-distance-updater-function

Conversation

Copy link
Contributor

Copilot AI commented Dec 22, 2025

Distance calculations were running every 3 seconds via setInterval() in addition to GPS position updates, causing excessive debug noise and unnecessary Haversine calculations when GPS coordinates hadn't changed.

Changes

  • Removed interval-based polling: Deleted startDistanceUpdater() and stopDistanceUpdater() functions and their invocations
  • Removed state property: Deleted distanceUpdateTimer from state object
  • Retained GPS-triggered updates: Distance calculation via updateDistanceUi() remains in GPS watch callback, executing only on actual position changes
// GPS watch callback - sole distance update trigger
state.geoWatchId = navigator.geolocation.watchPosition(
  (pos) => {
    // ... update state.lastFix ...
    updateDistanceUi(); // Only runs when GPS coordinates actually change
  },
  // ...
);

Distance calculations now occur exclusively when GPS data changes, eliminating redundant 3-second timer overhead.

Original prompt

Problem

The Haversine distance calculation is running unnecessarily due to redundant update triggers. Currently, distance updates are triggered in two ways:

  1. Interval-based timer (startDistanceUpdater()) - Runs every 3 seconds and calls updateDistanceUi()getDistanceFromLastPing()calculateHaversineDistance()

  2. GPS position changes (startGeoWatch()) - Calls updateDistanceUi() when GPS coordinates are updated

This causes excessive debug console noise with "Calculating Haversine distance" messages appearing constantly, even when there's no actual GPS update.

Solution

Remove the interval-based distance updater entirely and rely solely on GPS-triggered updates. The GPS watch callback in startGeoWatch() already calls updateDistanceUi() on every position change, making the 3-second interval timer redundant.

Changes Required

In content/wardrive.js:

  1. Remove startDistanceUpdater() function (around lines 802-808):
function startDistanceUpdater() {
  if (state.distanceUpdateTimer) return;
  state.distanceUpdateTimer = setInterval(() => {
    updateDistanceUi();
  }, 3000);
}
  1. Remove stopDistanceUpdater() function (around lines 813-819):
function stopDistanceUpdater() {
  if (state.distanceUpdateTimer) {
    clearInterval(state.distanceUpdateTimer);
    state.distanceUpdateTimer = null;
  }
}
  1. Remove the call to startDistanceUpdater() in startGeoWatch() (around line 898):
startDistanceUpdater(); // Start the distance updater  <-- REMOVE THIS LINE
  1. Remove the call to stopDistanceUpdater() in stopGeoWatch() (around line 927):
stopDistanceUpdater(); // Stop the distance updater  <-- REMOVE THIS LINE
  1. Remove distanceUpdateTimer from the state object if it exists in the state initialization.

The GPS watch callback already handles distance updates appropriately:

state.geoWatchId = navigator.geolocation.watchPosition(
  (pos) => {
    // ... existing GPS handling code ...
    updateDistanceUi(); // Update distance when GPS position changes  <-- KEEP THIS
  },
  // ...
);

Expected Outcome

  • Haversine distance calculations will only run when GPS coordinates are actually updated
  • Reduced debug console noise
  • Slightly improved performance by eliminating unnecessary timer and calculations

This pull request was created from Copilot chat.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: MrAlders0n <55921894+MrAlders0n@users.noreply.github.com>
Copilot AI changed the title [WIP] Remove interval-based distance updater for GPS updates Remove redundant interval-based distance updater Dec 22, 2025
Copilot AI requested a review from MrAlders0n December 22, 2025 04:35
@MrAlders0n MrAlders0n marked this pull request as ready for review December 22, 2025 04:39
@MrAlders0n MrAlders0n merged commit bf37ab0 into dev Dec 22, 2025
@MrAlders0n MrAlders0n deleted the copilot/remove-distance-updater-function branch December 22, 2025 05:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants