SShortSingh.
Back to feed

Django 6.1's FETCH_PEERS cuts N+1 query loops from 2,001 queries to just 2

0
·2 views

Django 6.1, released on 5 August 2026, introduced a queryset-level setting called fetch_mode with a FETCH_PEERS option designed to automatically batch foreign key lookups without requiring explicit select_related() or prefetch_related() calls. In benchmark tests using 2,000 book records across 50 authors on a local Postgres 17 instance, the default N+1 approach fired 2,001 queries and took 1,144.6 ms, while FETCH_PEERS reduced that to just 2 queries and 13.1 ms — nearly matching select_related performance. The feature works by issuing a single WHERE id IN (...) batch query on first access, functioning like an on-demand prefetch_related(), and also handles deferred fields beyond just foreign keys. However, testing revealed a documented limitation: FETCH_PEERS does not apply to reverse foreign key managers, meaning a loop over author.books.all() still produces the same number of queries regardless of the fetch_mode setting on the parent queryset.

Read the full story at DEV Community

This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)

Log in to join the discussion and vote.

Log in

Related stories

0
ProgrammingDEV Community ·

Unity Tool Lets Developers Scan All Prefabs for Missing Scripts Before Build

Missing scripts in Unity prefabs often go undetected during development, surfacing only after a script is renamed, deleted, or affected by a merge conflict. Unity flags these broken references in the Inspector as 'Missing (Mono Script)', indicating a serialized component whose backing script can no longer be resolved. A developer on DEV Community has shared an Editor utility called MissingScriptScanner.cs that automates detection by scanning every prefab asset in a project using PrefabUtility.LoadPrefabContents. The tool reports affected prefab paths and a total count of missing scripts directly in the Unity Console via a Tools menu command. While a missing script does not always cause an immediate crash, it can silently strip critical logic such as collision, AI, or animation behaviour from a prefab.

0
ProgrammingDEV Community ·

Langfuse fills the observability gap left by traditional APM tools for AI agents

Conventional observability platforms like Grafana and Datadog excel at monitoring infrastructure and HTTP performance but cannot detect AI-specific failures such as hallucinations, wrong tool selection, or poor response quality. These semantic and reasoning-level issues leave no trace in standard metrics, making it nearly impossible to diagnose why an AI agent underperformed in a specific interaction. Langfuse is an open-source LLM engineering platform that addresses this blind spot through tracing, prompt management, evaluation, and experimentation features. Unlike general APM tools, it treats AI applications as continuously evolving systems that improve through iterative feedback loops driven by user signals and prompt version comparisons. The platform also solves the problem of hardcoded prompts by centralizing them with native versioning and environment-based deployment controls, removing the need for full code deployment cycles on every prompt adjustment.

0
ProgrammingDEV Community ·

How to Build a RAG System on AWS Using Terraform, Bedrock, S3, and OpenSearch

A technical guide published at the AWS Builder Center demonstrates how to implement a Retrieval-Augmented Generation (RAG) system entirely on AWS using Terraform as the infrastructure-as-code tool. The setup uses Amazon S3 as the document source, Amazon Bedrock Knowledge Bases to manage the ingestion pipeline, and Amazon OpenSearch Serverless as the vector database for storing and searching embeddings. During ingestion, Bedrock splits uploaded documents into chunks, converts them into vector embeddings using Amazon Titan Text Embeddings v2, and stores the results in OpenSearch Serverless with KNN similarity search powered by the HNSW algorithm and FAISS engine. At query time, a user's question is converted into an embedding, matched against stored vectors via cosine similarity search, and the retrieved context is passed to a large language model to generate a grounded answer with source citations. A Streamlit-based UI ties the workflow together, allowing users to upload documents, trigger knowledge base syncs, and submit natural-language queries interactively.

0
ProgrammingDEV Community ·

Developer Builds Local-First Multi-Agent Platform Using Strands, Ollama, and MCP Gateway

A developer has built a local-first agent platform in Python that allows a single AI agent to access travel, finance, and entertainment capabilities without being directly coupled to each tool's implementation. The architecture uses Strands Agents for orchestration, Ollama for running a local language model, and the Model Context Protocol (MCP) to define a clean tool contract between the agent and domain servers. A central MCP gateway sits between the agent and multiple focused domain servers, hiding backend topology and making it easier to add or update individual domains independently. The design enforces three key constraints: the model runs locally, the agent connects to one stable tool endpoint, and each domain owns its own small MCP server. A FastAPI backend and Streamlit interface handle user interaction, while agent profiles are managed through a central registry that separates agent behavior from tool implementation.