Query Performance Patterns
Content: Query Performance Patterns
User Intent
Operation
Performance Overview
TypeScript (Canonical)
import { Graphlit } from 'graphlit-client';
import { ContentTypes, ObservableTypes, SearchTypes } from 'graphlit-client/dist/generated/graphql-types';
const graphlit = new Graphlit();
// Efficient pagination
const page1 = await graphlit.queryContents({
search: "query",
limit: 50,
offset: 0
});
const page2 = await graphlit.queryContents({
search: "query",
limit: 50,
offset: 50
});
// Use indexed filters for speed
const fast = await graphlit.queryContents({
search: "machine learning",
types: [ContentTypes.File], // Indexed
creationDateRange: { from: '2024-01-01' }, // Indexed
collections: [{ id: 'collection-id' }] // Indexed
limit: 20 // Reasonable limit
});
// Narrow scope before querying
const scoped = await graphlit.queryContents({
types: [ContentTypes.Email],
feeds: [{ id: 'specific-feed' }], // Narrow to one feed
createdInLast: 'P7D' // Recent only
});Query Performance Characteristics
Fast Queries (<50ms)
Medium Queries (50-200ms)
Slow Queries (200ms+)
Pagination Best Practices
Offset-Based Pagination
Progressive Loading
Limit Best Practices
Caching Strategies
Client-Side Result Caching
Query Fingerprinting
Indexed vs Non-Indexed Fields
Indexed (Fast)
Non-Indexed (Slower)
Optimization Patterns
Pattern 1: Filter Before Search
Pattern 2: Use Appropriate Search Type
Pattern 3: Batch Operations
Pattern 4: Count vs Results
Pagination
Optimized query
Developer Hints
Measure Query Performance
Parallelize Independent Queries
Use Reasonable Limits
Common Issues & Solutions
Production Example
Last updated