fix: eliminate redundant DB queries in read_resource and invoke_resource#2718
Merged
crivetimihai merged 2 commits intomainfrom Feb 5, 2026
Merged
fix: eliminate redundant DB queries in read_resource and invoke_resource#2718crivetimihai merged 2 commits intomainfrom
crivetimihai merged 2 commits intomainfrom
Conversation
Steps 3-4 of load test RCA: reduce per-request query count from 6 to 2 for resource-by-ID requests. Step 3: After Q2 (db.get), check enabled in Python and guard Q3/Q4 with resource_db is None so they only run for URI-only lookups. Step 4: Add joinedload(DbResource.gateway) to Q2, pass pre-fetched resource_obj and gateway_obj to invoke_resource() to skip Q5/Q6. Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
b02cae9 to
5044c23
Compare
kcostell06
pushed a commit
to kcostell06/mcp-context-forge
that referenced
this pull request
Feb 24, 2026
…rce (IBM#2718) * fix: eliminate redundant DB queries in read_resource and invoke_resource Steps 3-4 of load test RCA: reduce per-request query count from 6 to 2 for resource-by-ID requests. Step 3: After Q2 (db.get), check enabled in Python and guard Q3/Q4 with resource_db is None so they only run for URI-only lookups. Step 4: Add joinedload(DbResource.gateway) to Q2, pass pre-fetched resource_obj and gateway_obj to invoke_resource() to skip Q5/Q6. Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> * lint Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> --------- Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
joinedload(DbResource.gateway)on the initialdb.get()call so the gateway relationship is eager-loaded in a single query instead of a separate lazy-loadresource_objandgateway_objtoinvoke_resource()via new optional kwargs, skipping the internal re-fetch queries (Q5/Q6)resource_db is Noneso they only run for URI-only requests (not when resource was already found by ID)enabledstatus in Python after Q2 instead of issuing a separate filtered queryTest plan
pytest tests/unit/mcpgateway/services/test_resource_service.py -xpytest tests/unit/mcpgateway/services/test_resource_service_plugins.py -xread_resource(db, resource_id=...)returns correct contentread_resource(db, resource_uri=...)still works (URI-only path unchanged)ResourceNotFoundError