Skip to content

Inject db session to custom connector template registry cache query#7387

Open
Linker44 wants to merge 2 commits intomainfrom
inject_db_session_to_connector_registry
Open

Inject db session to custom connector template registry cache query#7387
Linker44 wants to merge 2 commits intomainfrom
inject_db_session_to_connector_registry

Conversation

@Linker44
Copy link
Contributor

@Linker44 Linker44 commented Feb 13, 2026

Ticket []

Description Of Changes

With autoclose_db_session is too expensive to be running every endpoint call. This pr makes db an optional param for injection and recycles db sessions running on fastapi to avoid the need of creating a new one.

Code Changes

  • added db as a parameter for cache comparison.
  • db is now passed in through endpoint calls to the connector registry

Steps to Confirm

Pre-Merge Checklist

  • Issue requirements met
  • All CI pipelines succeeded
  • CHANGELOG.md updated
    • Add a db-migration This indicates that a change includes a database migration label to the entry if your change includes a DB migration
    • Add a high-risk This issue suggests changes that have a high-probability of breaking existing code label to the entry if your change includes a high-risk change (i.e. potential for performance impact or unexpected regression) that should be flagged
    • Updates unreleased work already in Changelog, no new entry necessary
  • UX feedback:
    • All UX related changes have been reviewed by a designer
    • No UX review needed
  • Followup issues:
    • Followup issues created
    • No followup issues
  • Database migrations:
    • Ensure that your downrev is up to date with the latest revision on main
    • Ensure that your downgrade() migration is correct and works
      • If a downgrade migration is not possible for this change, please call this out in the PR description!
    • No migrations
  • Documentation:
    • Documentation complete, PR opened in fidesdocs
    • Documentation issue created in fidesdocs
    • If there are any new client scopes created as part of the pull request, remember to update public-facing documentation that references our scope registry
    • No documentation updates required

@Linker44 Linker44 self-assigned this Feb 13, 2026
@vercel
Copy link
Contributor

vercel bot commented Feb 13, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Actions Updated (UTC)
fides-plus-nightly Ignored Ignored Preview Feb 13, 2026 3:14pm
fides-privacy-center Ignored Ignored Feb 13, 2026 3:14pm

Request Review

@Linker44 Linker44 marked this pull request as ready for review February 13, 2026 15:14
@Linker44 Linker44 requested a review from a team as a code owner February 13, 2026 15:14
@Linker44 Linker44 requested review from johnewart and removed request for a team February 13, 2026 15:14
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 13, 2026

Greptile Overview

Greptile Summary

This PR optimizes database session management by allowing reuse of existing FastAPI sessions when checking cache staleness in the @db_timestamp_cached decorator. Previously, every endpoint call that accessed custom connector templates would create a new readonly session just to check MAX(updated_at) and COUNT(*), even when the endpoint already had an open session from FastAPI's dependency injection.

The changes thread an optional db parameter through the entire call chain:

  • Endpoints (connection_type_endpoints.py) inject the session via Depends(get_db)
  • Utility functions (connection_type.py) accept and forward the db parameter
  • The ConnectorRegistry (connector_registry_service.py) passes it to the cached loader
  • The @db_timestamp_cached decorator (db_timestamp_cache.py) consumes the db kwarg for its staleness check instead of creating a new session

The implementation is clean, well-documented, and includes comprehensive test coverage. The decorator properly strips the db kwarg before calling the wrapped function, ensuring it's only used for cache staleness checks. When no session is provided, the code falls back to the original behavior of creating a readonly autoclose session.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The changes are well-architected and follow a clear pattern: adding an optional parameter that threads through the call chain without modifying existing behavior when not provided. The implementation includes proper documentation, comprehensive test coverage for the new functionality, and maintains backward compatibility. All modified functions properly handle the optional db parameter with sensible defaults.
  • No files require special attention

Important Files Changed

Filename Overview
src/fides/api/util/db_timestamp_cache.py Enhanced to support optional db session injection, avoiding overhead of creating new sessions when caller already has one. Well documented and tested.
src/fides/api/service/connectors/saas/connector_registry_service.py Updated to thread db session parameter through all methods that access cached templates. Clean implementation with proper documentation.
src/fides/api/util/connection_type.py Added db parameter to all functions calling ConnectorRegistry methods. Properly threads session through the call chain.
src/fides/api/api/v1/endpoints/connection_type_endpoints.py Injected db session from FastAPI dependency and passed to utility functions. Follows best practices for endpoint design.
tests/ops/util/test_db_timestamp_cache.py Added comprehensive test coverage for new session reuse feature, including forwarding behavior and fallback scenarios.

Last reviewed commit: 10ca3fe

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

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