Optimized Queries
Best practices for efficient ShotGrid queries
Optimized Queries
ShotGrid MCP Server provides several techniques for optimizing queries to the ShotGrid API. This page covers best practices and patterns for writing efficient queries that minimize API calls and improve performance.
Field Hopping
Field hopping (also known as dot notation) allows you to retrieve data from related entities in a single query, reducing the number of API calls needed.
Basic Field Hopping
This query retrieves shots and their related sequence information in a single API call, rather than requiring separate calls to fetch the sequence data.
Multi-level Field Hopping
You can hop through multiple levels of relationships:
Field Hopping in Filters
Field hopping can also be used in filters to create more precise queries:
Implementing a Field Hopping Tool
Here’s a complete example of a tool that uses field hopping to efficiently retrieve related data:
Batch Operations
Batch operations allow you to perform multiple operations in a single API call, significantly reducing the number of network round-trips.
Batch Creation
Create multiple entities in a single call:
Mixed Batch Operations
Perform different types of operations in a single call:
Example usage:
Efficient Filtering
Proper filtering is crucial for performance, especially when dealing with large datasets.
Compound Filters
Use compound filters to narrow down results efficiently:
Using in
Filters
The in
filter operator is more efficient than multiple separate queries:
Pagination
For large result sets, use pagination to retrieve data in manageable chunks:
Optimized Find One
When you only need a single entity, use find_one
instead of find
:
Selective Field Retrieval
Only request the fields you actually need:
Caching Strategies
Implement caching for frequently accessed data:
For simpler caching needs, you can use Python’s built-in lru_cache
:
Best Practices Summary
- Use Field Hopping: Retrieve related entity data in a single query.
- Batch Operations: Combine multiple operations into a single API call.
- Efficient Filtering: Use compound filters and the
in
operator. - Pagination: Use pagination for large result sets.
- Find One: Use
find_one
when you only need a single entity. - Selective Fields: Only request the fields you actually need.
- Caching: Implement caching for frequently accessed data.
- Limit Results: Always use limits to avoid retrieving unnecessary data.
- Avoid N+1 Queries: Don’t make a separate query for each item in a list.
- Use Async Tools: For complex operations, use async tools to avoid blocking.
By following these patterns, you can significantly improve the performance of your ShotGrid MCP Server and provide a better experience for your users.