Skip to content

Commit 45d8266

Browse files
amitsingh-007claude
andcommitted
refactor: guard blob url lookup and trim comments
getBlobUrlFromOpenCache now short-circuits on a missing url instead of calling cache.match(undefined); persons without a cached image hit this. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 2d2ceb3 commit 45d8266

8 files changed

Lines changed: 12 additions & 25 deletions

File tree

apps/extension/src/entrypoints/popup/panels/BookmarksPanel/components/BookmarksPanel.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ function BookmarksPanel({ folderId, operation, bmUrl }: BMPanelQueryParams) {
4545
);
4646
const scrollAreaRef = useRef<HTMLDivElement>(null);
4747
const [searchText, setSearchText] = useState('');
48-
// This component re-renders on every row click (selected/cut state), so
49-
// without memoing, the whole list is re-filtered and getItemKey's identity
50-
// churns on each one
48+
// Re-renders on every row click, so memo to keep getItemKey identity stable
5149
const filteredContextBookmarks = useMemo(
5250
() => getFilteredContextBookmarks(contextBookmarks, searchText),
5351
[contextBookmarks, searchText]

apps/extension/src/entrypoints/popup/panels/HomePopup/utils/sync.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,7 @@ export const processPostLogin = async () => {
6363
// Sync remote firebase to storage
6464
await syncFirebaseToStorage();
6565
incrementProgress(SIGN_IN_TOTAL_STEPS);
66-
// Independent network-bound cache warms: person images come from personsItem,
67-
// favicons from bookmarksItem. addAllToCache shares one pLimit(20), so running
68-
// them together costs max() instead of sum() without raising peak concurrency.
66+
// Independent cache warms; addAllToCache shares one pLimit so concurrency is capped
6967
await Promise.all([cachePersonImagesInStorage(), cacheBookmarkFavicons()]);
7068
incrementProgress(SIGN_IN_TOTAL_STEPS);
7169
incrementProgress(SIGN_IN_TOTAL_STEPS);

apps/extension/tests/fixtures/background-fixture.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,7 @@ export const test = base.extend<
142142
}
143143
},
144144

145-
// Worker-scoped like every other shared fixture: background-navigation.spec
146-
// is describe.serial and each test calls ensureActiveState /
147-
// clearHistoryStartTime, so it is self-resetting and does not need a fresh
148-
// profile copy + Chromium launch per test.
145+
// Safe to share: the spec is describe.serial and each test resets its own state
149146
sharedBackground: [
150147
async ({}, use, testInfo) => {
151148
const { browserContext, userDataDir } = await createSharedContext({

apps/web/src/app/api/upload-file/utils.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ export const validateAndProccessFile = async (file: File) => {
1919
return null;
2020
}
2121

22-
// Buffer once and reuse: sniffing and compressing both need the bytes, and
23-
// this can be up to 5 MB
22+
// Buffer once: sniffing and compressing both need the bytes, up to 5 MB
2423
const buffer = Buffer.from(await file.arrayBuffer());
2524

2625
// Actual file type validation

apps/web/src/app/helpers/firebase/auth.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ export const googleSignOut = async () => signOut(auth);
3838
export const onAuthStateChange = (callback: (user: User | null) => void) =>
3939
onAuthStateChanged(auth, callback);
4040

41-
// No force-refresh: this runs before every tRPC request and the SDK already
42-
// refreshes within 5 mins of expiry, so forcing it added a securetoken round
43-
// trip to each call
41+
// No force-refresh: runs before every tRPC request and the SDK auto-refreshes near expiry
4442
export const getAuthIdToken = async () => auth.currentUser?.getIdToken();
4543

4644
export const emailAndPasswordSignIn = async (

packages/shared/src/components/Persons/hooks/usePerson.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,9 @@ const usePerson = () => {
3838
}
3939
const personImages = await getPersonImageUrls();
4040
if (!personImages) {
41-
// Matches resolvePersonImageFromUid: bail before touching CacheStorage
4241
return persons.map((person) => ({ ...person, imageUrl: '' }));
4342
}
44-
// Open the bucket once for the whole list rather than once per person
43+
// Open the bucket once for the whole list
4544
const cache = await getCacheObj(ECacheBucketKeys.person);
4645
return Promise.all(
4746
persons.map(async (person) => ({

packages/shared/src/components/Persons/hooks/useTaggedBookmarks.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ const useTaggedBookmarks = (personUid = '') => {
1616
return useSWR(
1717
personUid ? ['tagged-bookmarks', personUid] : null,
1818
async () => {
19-
// One read of the whole bookmarks object for the entire list. Resolving
20-
// each tagged url through useBookmark/usePerson would re-read and
21-
// re-parse it twice per bookmark.
19+
// One read for the whole list; the per-hash helpers re-read it twice per bookmark
2220
const bookmarks = await getBookmarks();
2321
if (!bookmarks?.urlList) {
2422
return [];

packages/shared/src/utils/cache.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ const getFromCache = async (cacheBucketKey: ECacheBucketKeys, url: string) => {
4747
return cache.match(url);
4848
};
4949

50-
/**
51-
* Takes an already-open Cache so callers resolving many urls can open the
52-
* bucket once instead of per url.
53-
*/
54-
export const getBlobUrlFromOpenCache = async (cache: Cache, url: string) => {
50+
/** Variant taking an already-open Cache, to open the bucket once for many urls. */
51+
export const getBlobUrlFromOpenCache = async (cache: Cache, url?: string) => {
52+
if (!url) {
53+
return '';
54+
}
5555
const response = await cache.match(url);
5656
const blob = await response?.blob();
5757
if (!blob) {

0 commit comments

Comments
 (0)