Skip to content

perf: accept optional storage in getUsableFallbackAccounts to avoid redundant disk reads#19

Open
iceteaSA wants to merge 1 commit into
cortexkit:mainfrom
iceteaSA:perf/storage-threading
Open

perf: accept optional storage in getUsableFallbackAccounts to avoid redundant disk reads#19
iceteaSA wants to merge 1 commit into
cortexkit:mainfrom
iceteaSA:perf/storage-threading

Conversation

@iceteaSA
Copy link
Copy Markdown

Summary

Adds an optional existingStorage parameter to FallbackAccountManager.getUsableFallbackAccounts(). Callers that already have storage loaded (e.g., the fetch handler which loads it at the start of every request) can pass it through to skip a redundant readFile + JSON.parse.

In the hot request path, loadAccounts() currently fires up to 3 times per request:

  1. In the main fetch handler
  2. Inside tryFallbackAccounts()
  3. Inside getUsableFallbackAccounts()

This change eliminates #3 when the caller provides storage.

API Change

// Before
async getUsableFallbackAccounts(): Promise<OAuthAccount[]>

// After (non-breaking)
async getUsableFallbackAccounts(existingStorage?: AccountStorage | null): Promise<OAuthAccount[]>

Uses !== undefined check (not falsy) because null is a valid "no storage file" state.

Testing

All existing tests pass. No behavior change — only avoids redundant disk I/O.

…edundant disk reads

In the hot request path, loadAccounts() (readFile + JSON.parse) can
fire multiple times per request. Callers that already have storage
loaded can now pass it to skip the redundant disk read.

Non-breaking: parameter is optional, existing callers unchanged.
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.

1 participant