Skip to content

Comments

feat: implement googleapis caching layer for Google Calendar API calls#22184

Closed
zomars wants to merge 3 commits intomainfrom
devin/googleapis-caching-layer-1751390665
Closed

feat: implement googleapis caching layer for Google Calendar API calls#22184
zomars wants to merge 3 commits intomainfrom
devin/googleapis-caching-layer-1751390665

Conversation

@zomars
Copy link
Contributor

@zomars zomars commented Jul 1, 2025

Implement googleapis caching layer for Google Calendar API calls

Summary

This PR implements a comprehensive caching layer for Google Calendar API calls to prevent rate limiting and improve performance. The implementation provides:

  • Framework-agnostic caching supporting both Next.js Edge Cache and Redis
  • Request signature-based deduplication with SHA-256 hashing for cache keys
  • Per-credential cache isolation to prevent data leakage between users
  • Support for read operations like events.list, events.get, freebusy.query, and calendarList.list
  • Optional integration through explicit dependency injection in the booking flow
  • Comprehensive documentation and testing infrastructure

The core implementation is located in packages/app-store/_utils/googleapis/ with minimal integration points in the booking flow. The cache manager is passed as an optional parameter through handleNewBookingEventManager → calendar integrations.

Review & Testing Checklist for Human

HIGH RISK - 5 critical items to verify:

  • End-to-end booking flow testing: Test the complete booking flow with cache manager enabled and disabled to ensure no regressions and that caching actually works
  • Cache isolation verification: Test with multiple users/credentials to verify that cached data is properly isolated and no data leakage occurs between different credentials
  • Framework compatibility: Verify both Next.js Edge Cache and Redis implementations work correctly (Redis implementation is largely untested)
  • Optional parameter handling: Test that the booking flow works correctly when googleApiCacheManager is undefined and when it's provided
  • Performance and rate limiting: Verify that the caching actually prevents rate limiting issues and doesn't introduce performance regressions

Recommended test plan:

  1. Create test bookings with different Google Calendar credentials
  2. Monitor cache hit/miss rates using the provided test scripts
  3. Verify that repeated identical API calls return cached results
  4. Test edge cases like cache expiration and concurrent requests
  5. Run the integration test script: node packages/app-store/_utils/googleapis/test-googleapis-cache-integration.js

Diagram

%%{ init : { "theme" : "default" }}%%
graph TD
    A["apps/web/pages/api/book/event.ts"]:::major-edit --> B["GoogleApiCacheFactory.createEdgeCacheManager()"]:::major-edit
    A --> C["handleNewBooking()"]:::minor-edit
    C --> D["packages/features/bookings/lib/handleNewBooking.ts"]:::minor-edit
    D --> E["EventManager()"]:::minor-edit
    E --> F["packages/lib/EventManager.ts"]:::minor-edit
    F --> G["Calendar integrations"]:::context
    
    B --> H["packages/app-store/_utils/googleapis/GoogleApiCacheFactory.ts"]:::major-edit
    H --> I["packages/app-store/_utils/googleapis/CachedFetchManager.ts"]:::major-edit
    I --> J["packages/app-store/_utils/googleapis/GoogleApiCache.ts"]:::major-edit
    I --> K["packages/app-store/_utils/googleapis/CacheClient.ts"]:::major-edit
    
    L["apps/api/v2/src/modules/googleapis-cache/"]:::major-edit --> M["NestJS Redis Integration"]:::major-edit
    
    N["packages/app-store/_utils/googleapis/TESTING.md"]:::major-edit
    O["packages/app-store/_utils/googleapis/README.md"]:::major-edit
    P["packages/app-store/_utils/googleapis/test-*.js"]:::major-edit

    subgraph Legend
        L1["Major Edit"]:::major-edit
        L2["Minor Edit"]:::minor-edit  
        L3["Context/No Edit"]:::context
    end

    classDef major-edit fill:#90EE90
    classDef minor-edit fill:#87CEEB
    classDef context fill:#FFFFFF
Loading

Notes

  • Based on PR feat: add framework-agnostic googleapis caching layer to prevent rate limiting #21933: This implementation replicates the core functionality from the original PR with updates for main branch compatibility
  • Link to Devin run: https://app.devin.ai/sessions/cf2a728395e14f7caed5503412b5a822
  • Requested by: @zomars
  • Framework design: Uses explicit dependency injection rather than framework auto-detection for better testability and control
  • Security consideration: Cache keys include credential ID to ensure proper isolation between users
  • Performance: 30-second default cache window with request deduplication to handle concurrent identical requests
  • Documentation: Comprehensive docs including architecture, integration guide, deployment instructions, and testing strategies

⚠️ Important: This is a significant change that hasn't been tested end-to-end. The caching layer adds complexity and touches multiple integration points. Thorough testing is essential before merging.

- Add framework-agnostic caching system supporting Next.js Edge Cache and Redis
- Implement request signature-based deduplication with 30-second default TTL
- Support read operations (events.list, events.get, freebusy.query, calendarList.list)
- Add per-credential cache isolation for security
- Include comprehensive documentation and testing infrastructure
- Integrate with booking flow through optional dependency injection
- Add NestJS module for Redis cache support in API v2

Based on PR #21933 with updates for main branch compatibility

Co-Authored-By: zomars@cal.com <zomars@me.com>
@devin-ai-integration
Copy link
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR that start with 'DevinAI'.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@vercel
Copy link

vercel bot commented Jul 1, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
cal ⬜️ Ignored (Inspect) Visit Preview Jul 1, 2025 6:43pm
cal-eu ⬜️ Ignored (Inspect) Visit Preview Jul 1, 2025 6:43pm

@keithwillcode keithwillcode added core area: core, team members only dba foundation labels Jul 1, 2025
@delve-auditor
Copy link

delve-auditor bot commented Jul 1, 2025

No security or compliance issues detected. Reviewed everything up to 5a637a0.

Security Overview
  • 🔎 Scanned files: 19 changed file(s)
Detected Code Changes
Change Type Relevant files
Enhancement ► googleapis-cache.module.ts
    Add NestJS module for Google API caching
► googleapis-cache.service.ts
    Implement Redis cache service
► GoogleApiCache.ts
    Core caching implementation
► CacheClient.ts
    Cache client implementations
► CachedCalendarClient.ts
    Google Calendar client wrapper
► cachedFetch.ts
    Cache fetch manager implementation
Configuration changes ► event.ts
    Add cache manager integration
► handleNewBooking.ts
    Add Google API cache manager parameter
► EventManager.ts
    Add cache manager options
Other ► Documentation files
    Add ARCHITECTURE.md
    Add DEPLOYMENT.md
    Add INTEGRATION.md
    Add README.md
    Add TESTING.md

Reply to this PR with @delve-auditor followed by a description of what change you want and we'll auto-submit a change to this PR to implement it.

Co-Authored-By: zomars@cal.com <zomars@me.com>
- Change crypto import from default to namespace import to fix ES5 compatibility
- Replace Array.from(Map.entries()) with forEach for ES5-compatible Map iteration
- Ensures GoogleApiCache compiles correctly with react-library.json ES5 target

Co-Authored-By: zomars@cal.com <zomars@me.com>
@github-actions
Copy link
Contributor

github-actions bot commented Jul 1, 2025

E2E results are ready!

@github-actions
Copy link
Contributor

This PR is being marked as stale due to inactivity.

@github-actions github-actions bot added the Stale label Jul 16, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 16, 2025

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@keithwillcode
Copy link
Contributor

Closing for now as work is continuing in #23675

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants