Skip to content

Refactor: eliminate duplicated stale-eviction logic and storage error handling#201

Merged
ormidales merged 2 commits into1.0.11from
copilot/sub-pr-200
Mar 26, 2026
Merged

Refactor: eliminate duplicated stale-eviction logic and storage error handling#201
ormidales merged 2 commits into1.0.11from
copilot/sub-pr-200

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 26, 2026

Two instances of duplicated logic identified in review: stale-entry eviction in trackInitialHost reinvented what cleanupStaleTrackedRequests already does, and the quota/storage error message selection was copy-pasted between addCurrentDomain and clearDomains.

background.js — delegate eviction to cleanupStaleTrackedRequests

Moved cleanupStaleTrackedRequests before trackInitialHost and replaced the inline TTL-check loop with a direct call. Oldest-inserted fallback only runs if the map remains at capacity after cleanup.

// Before: duplicated TTL loop inside trackInitialHost
const staleKeys = [];
for (const [key, entry] of initialHostByRequest) {
  if (now - entry.trackedAt > REQUEST_TRACK_TTL_MS) staleKeys.push(key);
}
if (staleKeys.length > 0) { /* delete each */ } else { /* evict oldest */ }

// After: single delegation
cleanupStaleTrackedRequests(now);
if (initialHostByRequest.size >= MAX_TRACKED_REQUESTS) {
  const evictKey = initialHostByRequest.keys().next().value;
  initialHostByRequest.delete(evictKey);
  redirectedRequestIds.delete(evictKey);
}

popup.js — extract getStorageErrorMessage helper

Encapsulates the quota-vs-generic error message selection. Both addCurrentDomain and clearDomains now call setStatus(getStorageErrorMessage(error), true).

const getStorageErrorMessage = (error) => {
  const errorMessage = typeof error?.message === "string" ? error.message : "";
  return /quota/i.test(errorMessage)
    ? browser.i18n.getMessage("statusQuotaError")
    : browser.i18n.getMessage("statusStorageError");
};

⚡ Quickly spin up Copilot coding agent tasks from anywhere on your macOS or Windows machine with Raycast.

…ract getStorageErrorMessage helper

Co-authored-by: ormidales <46538211+ormidales@users.noreply.github.com>
Agent-Logs-Url: https://github.com/ormidales/truepath/sessions/3be07f1c-7595-47e0-874c-7d833091e877
Copilot AI changed the title [WIP] Release v1.0.11 Refactor: eliminate duplicated stale-eviction logic and storage error handling Mar 26, 2026
Copilot AI requested a review from ormidales March 26, 2026 11:32
@ormidales ormidales added this to the v1.0.11 milestone Mar 26, 2026
@ormidales ormidales marked this pull request as ready for review March 26, 2026 11:33
Copilot AI review requested due to automatic review settings March 26, 2026 11:33
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors the extension to remove duplicated logic in two places: request-tracking eviction in the background script and storage/quota error message selection in the popup UI.

Changes:

  • background.js: Centralize TTL stale-entry eviction by delegating trackInitialHost capacity handling to cleanupStaleTrackedRequests.
  • popup.js: Extract a getStorageErrorMessage(error) helper and reuse it in both domain-add and clear-list storage write paths.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
background.js Refactors request tracking to reuse cleanupStaleTrackedRequests for TTL-based eviction before applying oldest-inserted fallback.
popup.js Introduces getStorageErrorMessage to dedupe quota-vs-generic storage error messaging across UI actions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ormidales ormidales merged commit 782f9e4 into 1.0.11 Mar 26, 2026
4 checks passed
@ormidales ormidales deleted the copilot/sub-pr-200 branch March 26, 2026 11:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants