Skip to content

Performance and error-handling improvements across shared services#3398

Merged
olgahaha merged 10 commits intomainfrom
copilot/improve-performance-error-handling
Apr 16, 2026
Merged

Performance and error-handling improvements across shared services#3398
olgahaha merged 10 commits intomainfrom
copilot/improve-performance-error-handling

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 2, 2026

Six medium-priority issues across shared services: unnecessary change detection cycles, repeated timestamp computation, TOCTOU race in preference initialization, mutex contention during large file writes, a silently swallowed auth error, and no upload recovery signal on reconnection.

Changes

  • CaptureTabComponent — Added ChangeDetectionStrategy.OnPush to avoid full tree checks on every proof update.

  • Proof.timestamp — Cached the converted value on first access via private _timestamp?: number. The threshold conversion was a hot path hit on every sort in large collections.

  • CapacitorStoragePreferences.initializeValue() — Wrapped check-and-set in mutex.runExclusive() to close the TOCTOU window where concurrent callers could both pass the subjects.has(key) guard.

  • MediaStore._write() — Moved base64ToBlob() outside the mutex. On native platform with large files (10+ MB), blob conversion was holding the lock and blocking concurrent reads.

  • DiaBackendAuthService.getToken() — Replaced broken new Promise(resolve => ...) pattern with pure async/await. The original called reject from lodash-es (not the Promise callback), so token-empty errors were silently swallowed. Also removed the now-unused reject lodash import.

    // Before: reject was lodash's array filter, not Promise.reject
    private async getToken() {
      return new Promise<string>(resolve => {
        this.preferences.getString(PrefKeys.TOKEN).then(token => {
          if (token.length !== 0) { resolve(token); }
          else { reject(new Error('...')); } // ← lodash reject, no-op here
        });
      });
    }
    
    // After
    private async getToken() {
      const token = await this.preferences.getString(PrefKeys.TOKEN);
      if (!token) throw new Error('Cannot get DIA backend token which is empty.');
      return token;
    }
  • NetworkService — Added reconnected$ observable (using pairwise + filter) that emits on false → true connectivity transitions, enabling consumers to trigger automatic upload recovery.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • download.cypress.io
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node index.js --exec install conf�� get --global it-cloneD1iQJU/node_modules/.bin/node core.hooksPath (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

…ervices

Agent-Logs-Url: https://github.com/numbersprotocol/capture-cam/sessions/1e4cc97a-7f48-42f9-b535-d2b5c78e7168

Co-authored-by: numbers-official <181934381+numbers-official@users.noreply.github.com>
Copilot AI changed the title [WIP] Improve performance and error-handling in shared services Performance and error-handling improvements across shared services Apr 2, 2026
Copilot AI requested a review from numbers-official April 2, 2026 21:53
@olgahaha olgahaha marked this pull request as ready for review April 16, 2026 07:53
@olgahaha olgahaha merged commit 953baf2 into main Apr 16, 2026
8 checks passed
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.

[Feature][Medium] Performance and error-handling improvements across shared services

3 participants