Skip to content

perf: deduplicate OG data fetches across document cards#831

Open
ved015 wants to merge 7 commits intosupermemoryai:mainfrom
ved015:perf/deduplicate-og-fetches
Open

perf: deduplicate OG data fetches across document cards#831
ved015 wants to merge 7 commits intosupermemoryai:mainfrom
ved015:perf/deduplicate-og-fetches

Conversation

@ved015
Copy link
Copy Markdown
Contributor

@ved015 ved015 commented Apr 6, 2026

Summary

Added module level cache (Map) and in-flight request deduplication for /api/og fetches in DocumentCard
Multiple cards with the same URL now share a single fetch instead of each firing independently
Subsequent renders instantly resolve from cache with zero network calls

Why

Each DocumentCard independently fetches OG metadata on mount. With 100 cards in a grid, this fires up to 100 parallel requests to /api/og many of which may be for the same URL. No caching, no deduplication.

Performance

  • Network requests reduced by ~50-90%
  • Eliminates redundant /api/og calls on re-renders and scroll-back
  • Zero new dependencies uses a plain Map for both cache and in-flight tracking

@MaheshtheDev @Dhravya please have a look

@graphite-app graphite-app bot requested a review from Dhravya April 6, 2026 07:46
@entelligence-ai-pr-reviews
Copy link
Copy Markdown

entelligence-ai-pr-reviews bot commented Apr 6, 2026

EntelligenceAI PR Summary

Adds OG data fetch deduplication and caching to memories-grid.tsx to avoid redundant /api/og requests across multiple DocumentCard instances sharing the same URL.

  • Introduced ogCache (Map) to store resolved OG data per URL
  • Introduced ogInflight (Map) to track in-flight requests and deduplicate concurrent fetches
  • Extracted fetchOgData utility function encapsulating cache lookup, deduplication logic, and fetch execution
  • Refactored DocumentCard useEffect to call fetchOgData(...).then(setOgData).finally(...), removing the previous inline fetch chain

Confidence Score: 5/5 - Safe to Merge

Safe to merge — this PR introduces a focused, well-scoped guard in fetchOgData within apps/web/components/memories-grid.tsx that prevents empty OG metadata objects (missing both title and image) from being persisted in ogCache. The change is conservative by design: it throws an Error('Empty metadata') to reject and skip caching of useless responses, which is the correct pattern for cache integrity. No review comments were generated, and the heuristic analysis found zero issues at any severity level across the single changed file.

Key Findings:

  • The guard condition correctly checks for absence of both title and image before throwing, which aligns with the minimum useful OG metadata contract and avoids false positives where only one field is present.
  • Throwing an error to prevent cache insertion is the idiomatic pattern in this codebase — it propagates cleanly without silently storing corrupt state in ogCache.
  • Change is tightly scoped to a single file and a single function (fetchOgData), minimizing blast radius and making the diff easy to reason about in isolation.
  • No pre-existing unresolved issues were identified, and automated review found zero concerns at any severity level.
Files requiring special attention
  • apps/web/components/memories-grid.tsx

@entelligence-ai-pr-reviews
Copy link
Copy Markdown

Walkthrough

Introduces a module-level caching and request deduplication layer for Open Graph data fetching in the memories grid. A new fetchOgData utility function backed by ogCache and ogInflight Maps prevents redundant /api/og network requests when multiple DocumentCard instances reference the same URL. The DocumentCard component's useEffect is refactored to delegate to this shared utility.

Changes

File(s) Summary
apps/web/components/memories-grid.tsx Added module-level ogCache and ogInflight Maps and a fetchOgData utility function for OG data fetch deduplication and caching; refactored DocumentCard's useEffect to use fetchOgData instead of an inline fetch chain.

🔗 Cross-Repository Impact Analysis

Enable automatic detection of breaking changes across your dependent repositories. → Set up now

Learn more about Cross-Repository Analysis

What It Does

  • Automatically identifies repositories that depend on this code
  • Analyzes potential breaking changes across your entire codebase
  • Provides risk assessment before merging to prevent cross-repo issues

How to Enable

  1. Visit Settings → Code Management
  2. Configure repository dependencies
  3. Future PRs will automatically include cross-repo impact analysis!

Benefits

  • 🛡️ Prevent breaking changes across repositories
  • 🔍 Catch integration issues before they reach production
  • 📊 Better visibility into your multi-repo architecture

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