[{"data":1,"prerenderedAt":4036},["ShallowReactive",2],{"navigation":3,"/performance-and-optimization":1016,"/performance-and-optimization-surround":4031},[4,54,89,123,165,211,253,331,389,439,462,488,514,540,578,624,650,672,702,736,774,800,850,856,862,868,874,928],{"title":5,"path":6,"stem":7,"children":8},"Introduction and Foundations","/introduction-and-foundations","01.introduction-and-foundations/01.index",[9,10,14,18,22,26,30,34,38,42,46,50],{"title":5,"path":6,"stem":7},{"title":11,"path":12,"stem":13},"What is Django","/introduction-and-foundations/what-is-django","01.introduction-and-foundations/02.what-is-django",{"title":15,"path":16,"stem":17},"Key Concepts and Philosophy","/introduction-and-foundations/key-concepts-and-philosophy","01.introduction-and-foundations/03.key-concepts-and-philosophy",{"title":19,"path":20,"stem":21},"MVC vs MVT: Understanding Django's Architecture","/introduction-and-foundations/mvc-vs-mvt","01.introduction-and-foundations/04.mvc-vs-mvt",{"title":23,"path":24,"stem":25},"Project Structure Overview","/introduction-and-foundations/project-structure-overview","01.introduction-and-foundations/05.project-structure-overview",{"title":27,"path":28,"stem":29},"Installing Django","/introduction-and-foundations/installing-django","01.introduction-and-foundations/06.installing-django",{"title":31,"path":32,"stem":33},"Creating Your First Django Project","/introduction-and-foundations/creating-first-project","01.introduction-and-foundations/07.creating-first-project",{"title":35,"path":36,"stem":37},"Creating Your First Django App","/introduction-and-foundations/creating-first-app","01.introduction-and-foundations/08.creating-first-app",{"title":39,"path":40,"stem":41},"Your First Django \"Hello World\"","/introduction-and-foundations/hello-world","01.introduction-and-foundations/09.hello-world",{"title":43,"path":44,"stem":45},"Django Quick Start Guide","/introduction-and-foundations/quick-start-guide","01.introduction-and-foundations/10.quick-start-guide",{"title":47,"path":48,"stem":49},"How Django Handles Requests","/introduction-and-foundations/how-django-handles-requests","01.introduction-and-foundations/11.how-django-handles-requests",{"title":51,"path":52,"stem":53},"Django Settings","/introduction-and-foundations/django-settings","01.introduction-and-foundations/12.django-settings",{"title":55,"path":56,"stem":57,"children":58},"The Development Environment","/development-environment","02.development-environment/1.index",[59,61,65,69,73,77,81,85],{"title":60,"path":56,"stem":57},"Development Environment",{"title":62,"path":63,"stem":64},"Recommended Tooling for Django Development","/development-environment/recommended-tooling","02.development-environment/2.recommended-tooling",{"title":66,"path":67,"stem":68},"Virtual Environments","/development-environment/virtual-environments","02.development-environment/3.virtual-environments",{"title":70,"path":71,"stem":72},"Django Admin and Management Commands","/development-environment/admin-and-management-commands","02.development-environment/4.admin-and-management-commands",{"title":74,"path":75,"stem":76},"Django Project Settings","/development-environment/project-settings","02.development-environment/5.project-settings",{"title":78,"path":79,"stem":80},"Managing Django Environments: Local, Staging, and Production","/development-environment/environments-local-staging-production","02.development-environment/6.environments-local-staging-production",{"title":82,"path":83,"stem":84},"Running Django Development Server","/development-environment/running-development-server","02.development-environment/7.running-development-server",{"title":86,"path":87,"stem":88},"Working with Django Shell","/development-environment/working-with-shell","02.development-environment/8.working-with-shell",{"title":90,"path":91,"stem":92,"children":93},"Templates and Presentation Layer","/templates-and-presentation","03.templates-and-presentation/1.index",[94,95,99,103,107,111,115,119],{"title":90,"path":91,"stem":92},{"title":96,"path":97,"stem":98},"Introduction to Django Templates","/templates-and-presentation/introduction-to-templates","03.templates-and-presentation/2.introduction-to-templates",{"title":100,"path":101,"stem":102},"The Django Template Language","/templates-and-presentation/django-template-language","03.templates-and-presentation/3.django-template-language",{"title":104,"path":105,"stem":106},"Template Inheritance","/templates-and-presentation/template-inheritance","03.templates-and-presentation/4.template-inheritance",{"title":108,"path":109,"stem":110},"Built-in Template Tags and Filters","/templates-and-presentation/built-in-template-tags-and-filters","03.templates-and-presentation/5.built-in-template-tags-and-filters",{"title":112,"path":113,"stem":114},"Including Static Files","/templates-and-presentation/including-static-files","03.templates-and-presentation/6.including-static-files",{"title":116,"path":117,"stem":118},"Working with Media Files","/templates-and-presentation/working-with-media-files","03.templates-and-presentation/7.working-with-media-files",{"title":120,"path":121,"stem":122},"Using Alternative Template Engines","/templates-and-presentation/using-alternative-template-engines","03.templates-and-presentation/8.using-alternative-template-engines",{"title":124,"path":125,"stem":126,"children":127},"URLs and Views","/urls-and-views","04.urls-and-views/01.index",[128,129,133,137,141,145,149,153,157,161],{"title":124,"path":125,"stem":126},{"title":130,"path":131,"stem":132},"The URL Dispatcher","/urls-and-views/the-url-dispatcher","04.urls-and-views/02.the-url-dispatcher",{"title":134,"path":135,"stem":136},"Writing Function-Based Views","/urls-and-views/writing-function-based-views","04.urls-and-views/03.writing-function-based-views",{"title":138,"path":139,"stem":140},"View Decorators","/urls-and-views/view-decorators","04.urls-and-views/04.view-decorators",{"title":142,"path":143,"stem":144},"Rendering Responses","/urls-and-views/rendering-responses","04.urls-and-views/05.rendering-responses",{"title":146,"path":147,"stem":148},"Redirects","/urls-and-views/redirects","04.urls-and-views/06.redirects",{"title":150,"path":151,"stem":152},"Handling HTTP Methods","/urls-and-views/handling-http-methods","04.urls-and-views/07.handling-http-methods",{"title":154,"path":155,"stem":156},"Conditional View Processing","/urls-and-views/conditional-view-processing","04.urls-and-views/08.conditional-view-processing",{"title":158,"path":159,"stem":160},"File Uploads","/urls-and-views/file-uploads","04.urls-and-views/09.file-uploads",{"title":162,"path":163,"stem":164},"Using Django Shortcut Functions","/urls-and-views/using-django-shortcut-functions","04.urls-and-views/10.using-django-shortcut-functions",{"title":166,"path":167,"stem":168,"children":169},"Class Based Views","/class-based-views","05.class-based-views/01.index",[170,171,175,179,183,187,191,195,199,203,207],{"title":166,"path":167,"stem":168},{"title":172,"path":173,"stem":174},"Introduction to Class-Based Views","/class-based-views/introduction-to-class-based-views","05.class-based-views/02.introduction-to-class-based-views",{"title":176,"path":177,"stem":178},"Common Base Classes","/class-based-views/common-base-classes","05.class-based-views/03.common-base-classes",{"title":180,"path":181,"stem":182},"Built-in Generic Views","/class-based-views/built-in-generic-views","05.class-based-views/04.built-in-generic-views",{"title":184,"path":185,"stem":186},"Views for CRUD Operations","/class-based-views/views-for-crud-operations","05.class-based-views/05.views-for-crud-operations",{"title":188,"path":189,"stem":190},"Handling Forms with Class-Based Views","/class-based-views/handling-forms-with-class-based-views","05.class-based-views/06.handling-forms-with-class-based-views",{"title":192,"path":193,"stem":194},"Using Mixins","/class-based-views/using-mixins","05.class-based-views/07.using-mixins",{"title":196,"path":197,"stem":198},"URL Configuration with Class-Based Views","/class-based-views/url-configuration-with-class-based-views","05.class-based-views/08.url-configuration-with-class-based-views",{"title":200,"path":201,"stem":202},"Subclassing Generic Views","/class-based-views/subclassing-generic-views","05.class-based-views/09.subclassing-generic-views",{"title":204,"path":205,"stem":206},"Asynchronous Class-Based Views","/class-based-views/asynchronous-class-based-views","05.class-based-views/10.asynchronous-class-based-views",{"title":208,"path":209,"stem":210},"Pagination","/class-based-views/pagination","05.class-based-views/11.pagination",{"title":212,"path":213,"stem":214,"children":215},"Forms and User Input","/forms-and-user-input","06.forms-and-user-input/01.index",[216,217,221,225,229,233,237,241,245,249],{"title":212,"path":213,"stem":214},{"title":218,"path":219,"stem":220},"Understanding HTML Forms","/forms-and-user-input/understanding-html-forms","06.forms-and-user-input/02.understanding-html-forms",{"title":222,"path":223,"stem":224},"Django's Role in Form Handling","/forms-and-user-input/djangos-role-in-form-handling","06.forms-and-user-input/03.djangos-role-in-form-handling",{"title":226,"path":227,"stem":228},"Creating Forms with Forms API","/forms-and-user-input/creating-forms-with-forms-api","06.forms-and-user-input/04.creating-forms-with-forms-api",{"title":230,"path":231,"stem":232},"Form Validation","/forms-and-user-input/form-validation","06.forms-and-user-input/05.form-validation",{"title":234,"path":235,"stem":236},"Built-in Fields and Widgets","/forms-and-user-input/built-in-fields-and-widgets","06.forms-and-user-input/06.built-in-fields-and-widgets",{"title":238,"path":239,"stem":240},"Form Rendering in Templates","/forms-and-user-input/form-rendering-in-templates","06.forms-and-user-input/07.form-rendering-in-templates",{"title":242,"path":243,"stem":244},"Model Forms","/forms-and-user-input/model-forms","06.forms-and-user-input/08.model-forms",{"title":246,"path":247,"stem":248},"Advanced Form Techniques","/forms-and-user-input/advanced-form-techniques","06.forms-and-user-input/09.advanced-form-techniques",{"title":250,"path":251,"stem":252},"Security Considerations for Forms","/forms-and-user-input/security-considerations-for-forms","06.forms-and-user-input/10.security-considerations-for-forms",{"title":254,"path":255,"stem":256,"children":257},"Models and Databases","/models-and-databases","07.models-and-databases/01.index",[258,259,263,267,271,275,279,283,287,291,295,299,303,307,311,315,319,323,327],{"title":254,"path":255,"stem":256},{"title":260,"path":261,"stem":262},"Understanding Django Models","/models-and-databases/understanding-django-models","07.models-and-databases/02.understanding-django-models",{"title":264,"path":265,"stem":266},"Defining Fields","/models-and-databases/defining-fields","07.models-and-databases/03.defining-fields",{"title":268,"path":269,"stem":270},"Relationships and Foreign Keys","/models-and-databases/relationships-and-foreign-keys","07.models-and-databases/04.relationships-and-foreign-keys",{"title":272,"path":273,"stem":274},"Examples of Relationship Patterns","/models-and-databases/examples-of-relationship-patterns","07.models-and-databases/05.examples-of-relationship-patterns",{"title":276,"path":277,"stem":278},"Making Queries","/models-and-databases/making-queries","07.models-and-databases/06.making-queries",{"title":280,"path":281,"stem":282},"Filtering, Ordering, and Slicing","/models-and-databases/filtering-ordering-slicing","07.models-and-databases/07.filtering-ordering-slicing",{"title":284,"path":285,"stem":286},"Managers and QuerySets","/models-and-databases/managers-and-querysets","07.models-and-databases/08.managers-and-querysets",{"title":288,"path":289,"stem":290},"Aggregation","/models-and-databases/aggregation","07.models-and-databases/09.aggregation",{"title":292,"path":293,"stem":294},"Search","/models-and-databases/search","07.models-and-databases/10.search",{"title":296,"path":297,"stem":298},"Raw SQL Queries","/models-and-databases/raw-sql-queries","07.models-and-databases/11.raw-sql-queries",{"title":300,"path":301,"stem":302},"Transactions","/models-and-databases/transactions","07.models-and-databases/12.transactions",{"title":304,"path":305,"stem":306},"Multiple Databases","/models-and-databases/multiple-databases","07.models-and-databases/13.multiple-databases",{"title":308,"path":309,"stem":310},"Tablespaces","/models-and-databases/tablespaces","07.models-and-databases/14.tablespaces",{"title":312,"path":313,"stem":314},"Composite Primary Keys","/models-and-databases/composite-primary-keys","07.models-and-databases/15.composite-primary-keys",{"title":316,"path":317,"stem":318},"Database Instrumentation","/models-and-databases/database-instrumentation","07.models-and-databases/16.database-instrumentation",{"title":320,"path":321,"stem":322},"Database Optimization","/models-and-databases/database-optimization","07.models-and-databases/17.database-optimization",{"title":324,"path":325,"stem":326},"Fixtures","/models-and-databases/fixtures","07.models-and-databases/18.fixtures",{"title":328,"path":329,"stem":330},"Signals","/models-and-databases/signals","07.models-and-databases/19.signals",{"title":332,"path":333,"stem":334,"children":335},"Migrations","/migrations","08.migrations/01.index",[336,337,341,345,349,353,357,361,365,369,373,377,381,385],{"title":332,"path":333,"stem":334},{"title":338,"path":339,"stem":340},"How Migrations Work","/migrations/how-migrations-work","08.migrations/02.how-migrations-work",{"title":342,"path":343,"stem":344},"Management Commands","/migrations/management-commands","08.migrations/03.management-commands",{"title":346,"path":347,"stem":348},"Dependencies and Workflow","/migrations/dependencies-and-workflow","08.migrations/04.dependencies-and-workflow",{"title":350,"path":351,"stem":352},"Transaction Handling","/migrations/transaction-handling","08.migrations/05.transaction-handling",{"title":354,"path":355,"stem":356},"Adding Migrations to Apps","/migrations/adding-migrations-to-apps","08.migrations/06.adding-migrations-to-apps",{"title":358,"path":359,"stem":360},"Reversing Migrations","/migrations/reversing-migrations","08.migrations/07.reversing-migrations",{"title":362,"path":363,"stem":364},"Historical Models","/migrations/historical-models","08.migrations/08.historical-models",{"title":366,"path":367,"stem":368},"Considerations When Removing Fields","/migrations/considerations-when-removing-fields","08.migrations/09.considerations-when-removing-fields",{"title":370,"path":371,"stem":372},"Data Migrations","/migrations/data-migrations","08.migrations/10.data-migrations",{"title":374,"path":375,"stem":376},"Squashing Migrations","/migrations/squashing-migrations","08.migrations/11.squashing-migrations",{"title":378,"path":379,"stem":380},"Serializing Values","/migrations/serializing-values","08.migrations/12.serializing-values",{"title":382,"path":383,"stem":384},"Supporting Multiple Django Versions","/migrations/supporting-multiple-django-versions","08.migrations/13.supporting-multiple-django-versions",{"title":386,"path":387,"stem":388},"Django Serialization Framework","/migrations/django-serialization-framework","08.migrations/14.django-serialization-framework",{"title":390,"path":391,"stem":392,"children":393},"Authentication and Authorization","/authentication-and-authorization","09.authentication-and-authorization/01.index",[394,395,399,403,407,411,415,419,423,427,431,435],{"title":390,"path":391,"stem":392},{"title":396,"path":397,"stem":398},"Overview of Django's Authentication System","/authentication-and-authorization/overview-of-django-authentication-system","09.authentication-and-authorization/02.overview-of-django-authentication-system",{"title":400,"path":401,"stem":402},"Users and Groups","/authentication-and-authorization/users-and-groups","09.authentication-and-authorization/03.users-and-groups",{"title":404,"path":405,"stem":406},"Permissions","/authentication-and-authorization/permissions","09.authentication-and-authorization/04.permissions",{"title":408,"path":409,"stem":410},"Password Management","/authentication-and-authorization/password-management","09.authentication-and-authorization/05.password-management",{"title":412,"path":413,"stem":414},"Authentication Views","/authentication-and-authorization/authentication-views","09.authentication-and-authorization/06.authentication-views",{"title":416,"path":417,"stem":418},"Login and Logout","/authentication-and-authorization/login-and-logout","09.authentication-and-authorization/07.login-and-logout",{"title":420,"path":421,"stem":422},"Custom User Models","/authentication-and-authorization/custom-user-models","09.authentication-and-authorization/08.custom-user-models",{"title":424,"path":425,"stem":426},"Middleware for Authentication","/authentication-and-authorization/middleware-for-authentication","09.authentication-and-authorization/09.middleware-for-authentication",{"title":428,"path":429,"stem":430},"Authorization in Views and Templates","/authentication-and-authorization/authorization-in-views-and-templates","09.authentication-and-authorization/10.authorization-in-views-and-templates",{"title":432,"path":433,"stem":434},"Integrating Social Authentication","/authentication-and-authorization/integrating-social-authentication","09.authentication-and-authorization/11.integrating-social-authentication",{"title":436,"path":437,"stem":438},"Security Best Practices","/authentication-and-authorization/security-best-practices","09.authentication-and-authorization/12.security-best-practices",{"title":440,"path":441,"stem":442,"children":443},"Sessions, Cookies, and State","/sessions-cookies-state","10.sessions-cookies-state/01.index",[444,446,450,454,458],{"title":445,"path":441,"stem":442},"Sessions, Cookies, and State Management",{"title":447,"path":448,"stem":449},"Introduction to Sessions","/sessions-cookies-state/introduction-to-sessions","10.sessions-cookies-state/02.introduction-to-sessions",{"title":451,"path":452,"stem":453},"Working with Cookies","/sessions-cookies-state/working-with-cookies","10.sessions-cookies-state/03.working-with-cookies",{"title":455,"path":456,"stem":457},"Server-Side Session Storage Options","/sessions-cookies-state/server-side-session-storage-options","10.sessions-cookies-state/04.server-side-session-storage-options",{"title":459,"path":460,"stem":461},"Session Security","/sessions-cookies-state/session-security","10.sessions-cookies-state/05.session-security",{"title":463,"path":464,"stem":465,"children":466},"Working with Files","/working-with-files","11.working-with-files/01.index",[467,468,472,476,480,484],{"title":463,"path":464,"stem":465},{"title":469,"path":470,"stem":471},"Files in Models","/working-with-files/files-in-models","11.working-with-files/02.files-in-models",{"title":473,"path":474,"stem":475},"The File Object","/working-with-files/the-file-object","11.working-with-files/03.the-file-object",{"title":477,"path":478,"stem":479},"Storage Backends","/working-with-files/storage-backends","11.working-with-files/04.storage-backends",{"title":481,"path":482,"stem":483},"Using Cloud Storage Providers","/working-with-files/using-cloud-storage-providers","11.working-with-files/05.using-cloud-storage-providers",{"title":485,"path":486,"stem":487},"Managing Media in Production","/working-with-files/managing-media-in-production","11.working-with-files/06.managing-media-in-production",{"title":489,"path":490,"stem":491,"children":492},"Admin Site","/admin-site","12.admin-site/01.index",[493,494,498,502,506,510],{"title":489,"path":490,"stem":491},{"title":495,"path":496,"stem":497},"Enabling the Admin","/admin-site/enabling-the-admin","12.admin-site/02.enabling-the-admin",{"title":499,"path":500,"stem":501},"Registering Models","/admin-site/registering-models","12.admin-site/03.registering-models",{"title":503,"path":504,"stem":505},"Customizing Admin Display","/admin-site/customizing-admin-display","12.admin-site/04.customizing-admin-display",{"title":507,"path":508,"stem":509},"Admin Actions","/admin-site/admin-actions","12.admin-site/05.admin-actions",{"title":511,"path":512,"stem":513},"Admin Security Best Practices","/admin-site/admin-security-best-practices","12.admin-site/06.admin-security-best-practices",{"title":515,"path":516,"stem":517,"children":518},"Middleware","/middleware","13.middleware/01.index",[519,520,524,528,532,536],{"title":515,"path":516,"stem":517},{"title":521,"path":522,"stem":523},"Middleware Overview","/middleware/middleware-overview","13.middleware/02.middleware-overview",{"title":525,"path":526,"stem":527},"Built-in Middleware","/middleware/built-in-middleware","13.middleware/03.built-in-middleware",{"title":529,"path":530,"stem":531},"Creating Custom Middleware","/middleware/creating-custom-middleware","13.middleware/04.creating-custom-middleware",{"title":533,"path":534,"stem":535},"Middleware Ordering","/middleware/middleware-ordering","13.middleware/05.middleware-ordering",{"title":537,"path":538,"stem":539},"Performance and Debugging","/middleware/performance-and-debugging","13.middleware/06.performance-and-debugging",{"title":541,"path":542,"stem":543,"children":544},"Security","/security","14.security/01.index",[545,546,550,554,558,562,566,570,574],{"title":541,"path":542,"stem":543},{"title":547,"path":548,"stem":549},"Django Security Philosophy","/security/django-security-philosophy","14.security/02.django-security-philosophy",{"title":551,"path":552,"stem":553},"Cross Site Request Forgery","/security/cross-site-request-forgery","14.security/03.cross-site-request-forgery",{"title":555,"path":556,"stem":557},"Cross Site Scripting","/security/cross-site-scripting","14.security/04.cross-site-scripting",{"title":559,"path":560,"stem":561},"SQL Injection Protection","/security/sql-injection-protection","14.security/05.sql-injection-protection",{"title":563,"path":564,"stem":565},"Clickjacking Protection","/security/clickjacking-protection","14.security/06.clickjacking-protection",{"title":567,"path":568,"stem":569},"HTTPS Setup and HSTS","/security/https-setup-and-hsts","14.security/07.https-setup-and-hsts",{"title":571,"path":572,"stem":573},"Password Storage and Cryptography","/security/password-storage-and-cryptography","14.security/08.password-storage-and-cryptography",{"title":575,"path":576,"stem":577},"Secure Deployment Checklist","/security/secure-deployment-checklist","14.security/09.secure-deployment-checklist",{"title":579,"path":580,"stem":581,"children":582},"Testing","/testing","15.testing/01.index",[583,584,588,592,596,600,604,608,612,616,620],{"title":579,"path":580,"stem":581},{"title":585,"path":586,"stem":587},"Introduction to Django Testing","/testing/introduction-to-django-testing","15.testing/02.introduction-to-django-testing",{"title":589,"path":590,"stem":591},"Writing and Running Tests","/testing/writing-and-running-tests","15.testing/03.writing-and-running-tests",{"title":593,"path":594,"stem":595},"Test Tools","/testing/test-tools","15.testing/04.test-tools",{"title":597,"path":598,"stem":599},"Testing Models","/testing/testing-models","15.testing/05.testing-models",{"title":601,"path":602,"stem":603},"Testing Views","/testing/testing-views","15.testing/06.testing-views",{"title":605,"path":606,"stem":607},"Testing Forms","/testing/testing-forms","15.testing/07.testing-forms",{"title":609,"path":610,"stem":611},"Testing Templates","/testing/testing-templates","15.testing/08.testing-templates",{"title":613,"path":614,"stem":615},"Testing Authentication","/testing/testing-authentication","15.testing/09.testing-authentication",{"title":617,"path":618,"stem":619},"Advanced Testing Topics","/testing/advanced-testing-topics","15.testing/10.advanced-testing-topics",{"title":621,"path":622,"stem":623},"Performance Testing","/testing/performance-testing","15.testing/11.performance-testing",{"title":625,"path":626,"stem":627,"children":628},"Static Assets and Frontend Integration","/static-assets-and-frontend-integration","16.static-assets-and-frontend-integration/01.index",[629,630,634,638,642,646],{"title":625,"path":626,"stem":627},{"title":631,"path":632,"stem":633},"Working with Static Files","/static-assets-and-frontend-integration/working-with-static-files","16.static-assets-and-frontend-integration/02.working-with-static-files",{"title":635,"path":636,"stem":637},"Integrating CSS and JavaScript","/static-assets-and-frontend-integration/integrating-css-and-javascript","16.static-assets-and-frontend-integration/03.integrating-css-and-javascript",{"title":639,"path":640,"stem":641},"Using Build Tools like Vite or Webpack","/static-assets-and-frontend-integration/using-build-tools-like-vite-or-webpack","16.static-assets-and-frontend-integration/04.using-build-tools-like-vite-or-webpack",{"title":643,"path":644,"stem":645},"Using React or Vue with Django","/static-assets-and-frontend-integration/using-react-or-vue-with-django","16.static-assets-and-frontend-integration/05.using-react-or-vue-with-django",{"title":647,"path":648,"stem":649},"Managing CORS","/static-assets-and-frontend-integration/managing-cors","16.static-assets-and-frontend-integration/06.managing-cors",{"title":651,"path":652,"stem":653,"children":654},"Internationalization and Localization","/internationalization-and-localization","17.internationalization-and-localization/01.index",[655,656,660,664,668],{"title":651,"path":652,"stem":653},{"title":657,"path":658,"stem":659},"Enabling Translation","/internationalization-and-localization/enabling-translation","17.internationalization-and-localization/02.enabling-translation",{"title":661,"path":662,"stem":663},"Translating Text in Code and Templates","/internationalization-and-localization/translating-text-in-code-and-templates","17.internationalization-and-localization/03.translating-text-in-code-and-templates",{"title":665,"path":666,"stem":667},"Timezone Support","/internationalization-and-localization/timezone-support","17.internationalization-and-localization/04.timezone-support",{"title":669,"path":670,"stem":671},"Locale Middleware","/internationalization-and-localization/locale-middleware","17.internationalization-and-localization/05.locale-middleware",{"title":673,"path":674,"stem":675,"children":676},"Caching","/caching","18.caching/01.index",[677,678,682,686,690,694,698],{"title":673,"path":674,"stem":675},{"title":679,"path":680,"stem":681},"Introduction to Caching","/caching/introduction-to-caching","18.caching/02.introduction-to-caching",{"title":683,"path":684,"stem":685},"Cache Backends","/caching/cache-backends","18.caching/03.cache-backends",{"title":687,"path":688,"stem":689},"Per View Caching","/caching/per-view-caching","18.caching/04.per-view-caching",{"title":691,"path":692,"stem":693},"Low Level Cache API","/caching/low-level-cache-api","18.caching/05.low-level-cache-api",{"title":695,"path":696,"stem":697},"Template Fragment Caching","/caching/template-fragment-caching","18.caching/06.template-fragment-caching",{"title":699,"path":700,"stem":701},"Deployment Level Caching Patterns","/caching/deployment-level-caching-patterns","18.caching/07.deployment-level-caching-patterns",{"title":703,"path":704,"stem":705,"children":706},"Asynchronous Django","/asynchronous-django","19.asynchronous-django/01.index",[707,708,712,716,720,724,728,732],{"title":703,"path":704,"stem":705},{"title":709,"path":710,"stem":711},"Introduction to ASGI","/asynchronous-django/introduction-to-asgi","19.asynchronous-django/02.introduction-to-asgi",{"title":713,"path":714,"stem":715},"Async Views","/asynchronous-django/async-views","19.asynchronous-django/03.async-views",{"title":717,"path":718,"stem":719},"Async ORM Status","/asynchronous-django/async-orm-status","19.asynchronous-django/04.async-orm-status",{"title":721,"path":722,"stem":723},"WebSockets with Channels","/asynchronous-django/websockets-with-channels","19.asynchronous-django/05.websockets-with-channels",{"title":725,"path":726,"stem":727},"Background Tasks with Celery or RQ","/asynchronous-django/background-tasks-with-celery-or-rq","19.asynchronous-django/06.background-tasks-with-celery-or-rq",{"title":729,"path":730,"stem":731},"Asynchronous Support","/asynchronous-django/asynchronous-support","19.asynchronous-django/07.asynchronous-support",{"title":733,"path":734,"stem":735},"Django's Tasks Framework","/asynchronous-django/django-tasks-framework","19.asynchronous-django/08.django-tasks-framework",{"title":737,"path":738,"stem":739,"children":740},"Deployment","/deployment","20.deployment/01.index",[741,742,746,750,754,758,762,766,770],{"title":737,"path":738,"stem":739},{"title":743,"path":744,"stem":745},"Preparing for Production","/deployment/preparing-for-production","20.deployment/02.preparing-for-production",{"title":747,"path":748,"stem":749},"Using WSGI and ASGI Servers","/deployment/using-wsgi-and-asgi-servers","20.deployment/03.using-wsgi-and-asgi-servers",{"title":751,"path":752,"stem":753},"Deploying on Linux Servers","/deployment/deploying-on-linux-servers","20.deployment/04.deploying-on-linux-servers",{"title":755,"path":756,"stem":757},"Using Docker","/deployment/using-docker","20.deployment/05.using-docker",{"title":759,"path":760,"stem":761},"Cloud Deployment Guides","/deployment/cloud-deployment-guides","20.deployment/06.cloud-deployment-guides",{"title":763,"path":764,"stem":765},"Scaling and Load Balancing","/deployment/scaling-and-load-balancing","20.deployment/07.scaling-and-load-balancing",{"title":767,"path":768,"stem":769},"Monitoring and Logging","/deployment/monitoring-and-logging","20.deployment/08.monitoring-and-logging",{"title":771,"path":772,"stem":773},"Backup Strategies","/deployment/backup-strategies","20.deployment/09.backup-strategies",{"title":775,"path":776,"stem":777,"children":778},"Performance and Optimization","/performance-and-optimization","21.performance-and-optimization/01.index",[779,780,784,788,792,796],{"title":775,"path":776,"stem":777},{"title":781,"path":782,"stem":783},"Query Optimization","/performance-and-optimization/query-optimization","21.performance-and-optimization/02.query-optimization",{"title":785,"path":786,"stem":787},"Template Rendering Optimization","/performance-and-optimization/template-rendering-optimization","21.performance-and-optimization/03.template-rendering-optimization",{"title":789,"path":790,"stem":791},"Using Select Related and Prefetch Related","/performance-and-optimization/using-select-related-and-prefetch-related","21.performance-and-optimization/04.using-select-related-and-prefetch-related",{"title":793,"path":794,"stem":795},"Caching Strategies","/performance-and-optimization/caching-strategies","21.performance-and-optimization/05.caching-strategies",{"title":797,"path":798,"stem":799},"Profiling Django Apps","/performance-and-optimization/profiling-django-apps","21.performance-and-optimization/06.profiling-django-apps",{"title":801,"path":802,"stem":803,"children":804},"Advanced and Expert Topics","/advanced-and-expert-topics","22.advanced-and-expert-topics/01.index",[805,806,810,814,818,822,826,830,834,838,842,846],{"title":801,"path":802,"stem":803},{"title":807,"path":808,"stem":809},"System Architecture Patterns","/advanced-and-expert-topics/system-architecture-patterns","22.advanced-and-expert-topics/02.system-architecture-patterns",{"title":811,"path":812,"stem":813},"Domain Driven Design with Django","/advanced-and-expert-topics/domain-driven-design-with-django","22.advanced-and-expert-topics/03.domain-driven-design-with-django",{"title":815,"path":816,"stem":817},"Building Large Scale Django Projects","/advanced-and-expert-topics/building-large-scale-django-projects","22.advanced-and-expert-topics/04.building-large-scale-django-projects",{"title":819,"path":820,"stem":821},"Plugin Architectures for Django Apps","/advanced-and-expert-topics/plugin-architectures-for-django-apps","22.advanced-and-expert-topics/05.plugin-architectures-for-django-apps",{"title":823,"path":824,"stem":825},"Extending Django's Core","/advanced-and-expert-topics/extending-djangos-core","22.advanced-and-expert-topics/06.extending-djangos-core",{"title":827,"path":828,"stem":829},"Custom ORM Expressions","/advanced-and-expert-topics/custom-orm-expressions","22.advanced-and-expert-topics/07.custom-orm-expressions",{"title":831,"path":832,"stem":833},"Custom Management Commands","/advanced-and-expert-topics/custom-management-commands","22.advanced-and-expert-topics/08.custom-management-commands",{"title":835,"path":836,"stem":837},"Working with Signals","/advanced-and-expert-topics/working-with-signals","22.advanced-and-expert-topics/09.working-with-signals",{"title":839,"path":840,"stem":841},"Building Reusable Django Packages","/advanced-and-expert-topics/building-reusable-django-packages","22.advanced-and-expert-topics/10.building-reusable-django-packages",{"title":843,"path":844,"stem":845},"Integrating Microservices","/advanced-and-expert-topics/integrating-microservices","22.advanced-and-expert-topics/11.integrating-microservices",{"title":847,"path":848,"stem":849},"Advanced Security Hardening","/advanced-and-expert-topics/advanced-security-hardening","22.advanced-and-expert-topics/12.advanced-security-hardening",{"title":851,"path":852,"stem":853,"children":854},"Logging in Django","/logging-in-django","23.logging-in-django/01.index",[855],{"title":851,"path":852,"stem":853},{"title":857,"path":858,"stem":859,"children":860},"FAQ and Troubleshooting","/faq-and-troubleshooting","24.faq-and-troubleshooting/01.index",[861],{"title":857,"path":858,"stem":859},{"title":863,"path":864,"stem":865,"children":866},"External Packages and Ecosystem","/external-packages-and-ecosystem","25.external-packages-and-ecosystem/01.index",[867],{"title":863,"path":864,"stem":865},{"title":869,"path":870,"stem":871,"children":872},"Django Internals and Contributing","/django-internals-and-contributing","26.django-internals-and-contributing/01.index",[873],{"title":869,"path":870,"stem":871},{"title":875,"path":876,"stem":877,"children":878},"Microservices with Django","/microservices-with-django","27.microservices-with-django/01.index",[879,880,884,888,892,896,900,904,908,912,916,920,924],{"title":875,"path":876,"stem":877},{"title":881,"path":882,"stem":883},"What Is a Microservice?","/microservices-with-django/what-is-a-microservice","27.microservices-with-django/02.what-is-a-microservice",{"title":885,"path":886,"stem":887},"Introducing the Django Microservices Architecture","/microservices-with-django/django-microservices-architecture","27.microservices-with-django/03.django-microservices-architecture",{"title":889,"path":890,"stem":891},"Setting Up the Development and Runtime Environment","/microservices-with-django/development-environment","27.microservices-with-django/04.development-environment",{"title":893,"path":894,"stem":895},"Cloud-native Data Processing with MongoDB","/microservices-with-django/cloud-native-data-processing","27.microservices-with-django/05.cloud-native-data-processing",{"title":897,"path":898,"stem":899},"Creating RESTful APIs for Microservices","/microservices-with-django/restful-apis","27.microservices-with-django/06.restful-apis",{"title":901,"path":902,"stem":903},"Orchestrating Microservices with Celery and RabbitMQ","/microservices-with-django/orchestrating-celery-rabbitmq","27.microservices-with-django/07.orchestrating-celery-rabbitmq",{"title":905,"path":906,"stem":907},"Testing Microservices","/microservices-with-django/testing-microservices","27.microservices-with-django/08.testing-microservices",{"title":909,"path":910,"stem":911},"Deploying Microservices","/microservices-with-django/deploying-microservices","27.microservices-with-django/09.deploying-microservices",{"title":913,"path":914,"stem":915},"Securing Microservices","/microservices-with-django/securing-microservices","27.microservices-with-django/10.securing-microservices",{"title":917,"path":918,"stem":919},"Improving Microservices Performance with Caching","/microservices-with-django/performance-caching","27.microservices-with-django/11.performance-caching",{"title":921,"path":922,"stem":923},"Best Practices","/microservices-with-django/best-practices","27.microservices-with-django/12.best-practices",{"title":925,"path":926,"stem":927},"Transforming a Monolithic Web App into a Microservice version","/microservices-with-django/monolith-to-microservices","27.microservices-with-django/13.monolith-to-microservices",{"title":929,"path":930,"stem":931,"children":932},"Releases","/releases","releases",[933,936,940,944,948,952,956,960,964,968,972,976,980,984,988,992,996,1000,1004,1008,1012],{"title":934,"path":930,"stem":935},"Django Releases","releases/index",{"title":937,"path":938,"stem":939},"Django 5.1.10 release notes","/releases/5.1.10","releases/5.1.10",{"title":941,"path":942,"stem":943},"Django 5.1.11 release notes","/releases/5.1.11","releases/5.1.11",{"title":945,"path":946,"stem":947},"Django 5.1.12 release notes","/releases/5.1.12","releases/5.1.12",{"title":949,"path":950,"stem":951},"Django 5.1.13 release notes","/releases/5.1.13","releases/5.1.13",{"title":953,"path":954,"stem":955},"Django 5.1.14 release notes","/releases/5.1.14","releases/5.1.14",{"title":957,"path":958,"stem":959},"Django 5.1.15 release notes","/releases/5.1.15","releases/5.1.15",{"title":961,"path":962,"stem":963},"Django 5.2 release notes","/releases/5.2","releases/5.2",{"title":965,"path":966,"stem":967},"Django 5.2.1 release notes","/releases/5.2.1","releases/5.2.1",{"title":969,"path":970,"stem":971},"Django 5.2.10 release notes","/releases/5.2.10","releases/5.2.10",{"title":973,"path":974,"stem":975},"Django 5.2.2 release notes","/releases/5.2.2","releases/5.2.2",{"title":977,"path":978,"stem":979},"Django 5.2.3 release notes","/releases/5.2.3","releases/5.2.3",{"title":981,"path":982,"stem":983},"Django 5.2.4 release notes","/releases/5.2.4","releases/5.2.4",{"title":985,"path":986,"stem":987},"Django 5.2.5 release notes","/releases/5.2.5","releases/5.2.5",{"title":989,"path":990,"stem":991},"Django 5.2.6 release notes","/releases/5.2.6","releases/5.2.6",{"title":993,"path":994,"stem":995},"Django 5.2.7 release notes","/releases/5.2.7","releases/5.2.7",{"title":997,"path":998,"stem":999},"Django 5.2.8 release notes","/releases/5.2.8","releases/5.2.8",{"title":1001,"path":1002,"stem":1003},"Django 5.2.9 release notes","/releases/5.2.9","releases/5.2.9",{"title":1005,"path":1006,"stem":1007},"Django 6.0 release notes","/releases/6.0","releases/6.0",{"title":1009,"path":1010,"stem":1011},"Django 6.0.1 release notes","/releases/6.0.1","releases/6.0.1",{"title":1013,"path":1014,"stem":1015},"Django 6.1 release notes - UNDER DEVELOPMENT","/releases/6.1","releases/6.1",{"id":1017,"title":775,"body":1018,"description":1028,"extension":4026,"links":4027,"meta":4028,"navigation":1319,"path":776,"seo":4029,"stem":777,"__hash__":4030},"docs/21.performance-and-optimization/01.index.md",{"type":1019,"value":1020,"toc":3994},"minimark",[1021,1025,1029,1034,1037,1042,1048,1061,1066,1077,1082,1096,1101,1115,1120,1131,1135,1456,1460,1468,1472,1476,1479,1652,1656,1659,1664,1676,1681,1692,1697,1708,1713,1724,1728,1731,1736,1750,1755,1769,1774,1788,1792,1795,2057,2061,2065,2068,2085,2089,2092,2106,2110,2113,2127,2131,2134,2148,2152,2155,2169,2173,2176,2181,2186,2192,2197,2202,2206,2210,2215,2335,2340,2571,2575,2579,2850,2854,3213,3217,3221,3643,3646,3650,3977,3981,3984,3987,3990],[1022,1023,775],"h1",{"id":1024},"performance-and-optimization",[1026,1027,1028],"p",{},"Performance optimization is critical for building scalable Django applications that provide excellent user experiences. This comprehensive guide covers database query optimization, template rendering, caching strategies, profiling techniques, and advanced optimization patterns that transform slow applications into high-performance systems.",[1030,1031,1033],"h2",{"id":1032},"understanding-django-performance","Understanding Django Performance",[1026,1035,1036],{},"Django applications face performance challenges at multiple layers: database queries, template rendering, Python code execution, network latency, and resource utilization. Effective optimization requires understanding where bottlenecks occur and applying targeted solutions.",[1038,1039,1041],"h3",{"id":1040},"performance-metrics-that-matter","Performance Metrics That Matter",[1026,1043,1044],{},[1045,1046,1047],"strong",{},"Response Time",[1049,1050,1051,1055,1058],"ul",{},[1052,1053,1054],"li",{},"Time from request to response delivery",[1052,1056,1057],{},"Target: \u003C 200ms for most requests, \u003C 1s for complex operations",[1052,1059,1060],{},"Measured at application, database, and network levels",[1026,1062,1063],{},[1045,1064,1065],{},"Throughput",[1049,1067,1068,1071,1074],{},[1052,1069,1070],{},"Requests handled per second",[1052,1072,1073],{},"Target: Varies by application, typically 100-1000 req/s per server",[1052,1075,1076],{},"Limited by CPU, memory, and I/O capacity",[1026,1078,1079],{},[1045,1080,1081],{},"Database Performance",[1049,1083,1084,1087,1090,1093],{},[1052,1085,1086],{},"Query execution time",[1052,1088,1089],{},"Number of queries per request",[1052,1091,1092],{},"Connection pool utilization",[1052,1094,1095],{},"Target: \u003C 50ms per query, \u003C 10 queries per request",[1026,1097,1098],{},[1045,1099,1100],{},"Memory Usage",[1049,1102,1103,1106,1109,1112],{},[1052,1104,1105],{},"Application memory footprint",[1052,1107,1108],{},"Memory leaks and growth patterns",[1052,1110,1111],{},"Cache memory utilization",[1052,1113,1114],{},"Target: Stable memory usage under load",[1026,1116,1117],{},[1045,1118,1119],{},"CPU Utilization",[1049,1121,1122,1125,1128],{},[1052,1123,1124],{},"Processing efficiency",[1052,1126,1127],{},"Thread/process utilization",[1052,1129,1130],{},"Target: 60-80% under normal load",[1038,1132,1134],{"id":1133},"common-performance-bottlenecks","Common Performance Bottlenecks",[1136,1137,1142],"pre",{"className":1138,"code":1139,"language":1140,"meta":1141,"style":1141},"language-python shiki shiki-themes material-theme-lighter vitesse-light vitesse-dark","# N+1 Query Problem - The Most Common Issue\ndef slow_view(request):\n    # This generates 1 + N queries!\n    articles = Article.objects.all()  # 1 query\n    for article in articles:\n        print(article.author.name)  # N queries (one per article)\n    \n    return render(request, 'articles.html', {'articles': articles})\n\n# Solution: Use select_related\ndef fast_view(request):\n    # This generates only 1 query with JOIN\n    articles = Article.objects.select_related('author').all()\n    for article in articles:\n        print(article.author.name)  # No additional queries\n    \n    return render(request, 'articles.html', {'articles': articles})\n","python","",[1143,1144,1145,1154,1176,1182,1214,1233,1261,1267,1314,1321,1327,1341,1347,1381,1394,1416,1421],"code",{"__ignoreMap":1141},[1146,1147,1150],"span",{"class":1148,"line":1149},"line",1,[1146,1151,1153],{"class":1152},"s9Tkl","# N+1 Query Problem - The Most Common Issue\n",[1146,1155,1157,1161,1165,1169,1173],{"class":1148,"line":1156},2,[1146,1158,1160],{"class":1159},"s5Kfy","def",[1146,1162,1164],{"class":1163},"sljsM"," slow_view",[1146,1166,1168],{"class":1167},"soVBu","(",[1146,1170,1172],{"class":1171},"sCyAa","request",[1146,1174,1175],{"class":1167},"):\n",[1146,1177,1179],{"class":1148,"line":1178},3,[1146,1180,1181],{"class":1152},"    # This generates 1 + N queries!\n",[1146,1183,1185,1189,1192,1195,1198,1202,1204,1208,1211],{"class":1148,"line":1184},4,[1146,1186,1188],{"class":1187},"sftqT","    articles ",[1146,1190,1191],{"class":1167},"=",[1146,1193,1194],{"class":1187}," Article",[1146,1196,1197],{"class":1167},".",[1146,1199,1201],{"class":1200},"sBPpx","objects",[1146,1203,1197],{"class":1167},[1146,1205,1207],{"class":1206},"siWMO","all",[1146,1209,1210],{"class":1167},"()",[1146,1212,1213],{"class":1152},"  # 1 query\n",[1146,1215,1217,1221,1224,1227,1230],{"class":1148,"line":1216},5,[1146,1218,1220],{"class":1219},"siDh9","    for",[1146,1222,1223],{"class":1187}," article ",[1146,1225,1226],{"class":1219},"in",[1146,1228,1229],{"class":1187}," articles",[1146,1231,1232],{"class":1167},":\n",[1146,1234,1236,1240,1242,1245,1247,1250,1252,1255,1258],{"class":1148,"line":1235},6,[1146,1237,1239],{"class":1238},"sJdAF","        print",[1146,1241,1168],{"class":1167},[1146,1243,1244],{"class":1206},"article",[1146,1246,1197],{"class":1167},[1146,1248,1249],{"class":1200},"author",[1146,1251,1197],{"class":1167},[1146,1253,1254],{"class":1200},"name",[1146,1256,1257],{"class":1167},")",[1146,1259,1260],{"class":1152},"  # N queries (one per article)\n",[1146,1262,1264],{"class":1148,"line":1263},7,[1146,1265,1266],{"class":1187},"    \n",[1146,1268,1270,1273,1276,1278,1280,1283,1287,1291,1294,1296,1299,1301,1304,1306,1309,1311],{"class":1148,"line":1269},8,[1146,1271,1272],{"class":1219},"    return",[1146,1274,1275],{"class":1206}," render",[1146,1277,1168],{"class":1167},[1146,1279,1172],{"class":1206},[1146,1281,1282],{"class":1167},",",[1146,1284,1286],{"class":1285},"sbYkP"," '",[1146,1288,1290],{"class":1289},"sTbE_","articles.html",[1146,1292,1293],{"class":1285},"'",[1146,1295,1282],{"class":1167},[1146,1297,1298],{"class":1167}," {",[1146,1300,1293],{"class":1285},[1146,1302,1303],{"class":1289},"articles",[1146,1305,1293],{"class":1285},[1146,1307,1308],{"class":1167},":",[1146,1310,1229],{"class":1206},[1146,1312,1313],{"class":1167},"})\n",[1146,1315,1317],{"class":1148,"line":1316},9,[1146,1318,1320],{"emptyLinePlaceholder":1319},true,"\n",[1146,1322,1324],{"class":1148,"line":1323},10,[1146,1325,1326],{"class":1152},"# Solution: Use select_related\n",[1146,1328,1330,1332,1335,1337,1339],{"class":1148,"line":1329},11,[1146,1331,1160],{"class":1159},[1146,1333,1334],{"class":1163}," fast_view",[1146,1336,1168],{"class":1167},[1146,1338,1172],{"class":1171},[1146,1340,1175],{"class":1167},[1146,1342,1344],{"class":1148,"line":1343},12,[1146,1345,1346],{"class":1152},"    # This generates only 1 query with JOIN\n",[1146,1348,1350,1352,1354,1356,1358,1360,1362,1365,1367,1369,1371,1373,1376,1378],{"class":1148,"line":1349},13,[1146,1351,1188],{"class":1187},[1146,1353,1191],{"class":1167},[1146,1355,1194],{"class":1187},[1146,1357,1197],{"class":1167},[1146,1359,1201],{"class":1200},[1146,1361,1197],{"class":1167},[1146,1363,1364],{"class":1206},"select_related",[1146,1366,1168],{"class":1167},[1146,1368,1293],{"class":1285},[1146,1370,1249],{"class":1289},[1146,1372,1293],{"class":1285},[1146,1374,1375],{"class":1167},").",[1146,1377,1207],{"class":1206},[1146,1379,1380],{"class":1167},"()\n",[1146,1382,1384,1386,1388,1390,1392],{"class":1148,"line":1383},14,[1146,1385,1220],{"class":1219},[1146,1387,1223],{"class":1187},[1146,1389,1226],{"class":1219},[1146,1391,1229],{"class":1187},[1146,1393,1232],{"class":1167},[1146,1395,1397,1399,1401,1403,1405,1407,1409,1411,1413],{"class":1148,"line":1396},15,[1146,1398,1239],{"class":1238},[1146,1400,1168],{"class":1167},[1146,1402,1244],{"class":1206},[1146,1404,1197],{"class":1167},[1146,1406,1249],{"class":1200},[1146,1408,1197],{"class":1167},[1146,1410,1254],{"class":1200},[1146,1412,1257],{"class":1167},[1146,1414,1415],{"class":1152},"  # No additional queries\n",[1146,1417,1419],{"class":1148,"line":1418},16,[1146,1420,1266],{"class":1187},[1146,1422,1424,1426,1428,1430,1432,1434,1436,1438,1440,1442,1444,1446,1448,1450,1452,1454],{"class":1148,"line":1423},17,[1146,1425,1272],{"class":1219},[1146,1427,1275],{"class":1206},[1146,1429,1168],{"class":1167},[1146,1431,1172],{"class":1206},[1146,1433,1282],{"class":1167},[1146,1435,1286],{"class":1285},[1146,1437,1290],{"class":1289},[1146,1439,1293],{"class":1285},[1146,1441,1282],{"class":1167},[1146,1443,1298],{"class":1167},[1146,1445,1293],{"class":1285},[1146,1447,1303],{"class":1289},[1146,1449,1293],{"class":1285},[1146,1451,1308],{"class":1167},[1146,1453,1229],{"class":1206},[1146,1455,1313],{"class":1167},[1038,1457,1459],{"id":1458},"performance-optimization-layers","Performance Optimization Layers",[1136,1461,1466],{"className":1462,"code":1464,"language":1465},[1463],"language-text","┌─────────────────────────────────────────────────────────────┐\n│                    Application Layer                        │\n│  • Code optimization                                        │\n│  • Algorithm efficiency                                     │\n│  • Memory management                                        │\n└─────────────────────────────────────────────────────────────┘\n                            ↓\n┌─────────────────────────────────────────────────────────────┐\n│                    Template Layer                           │\n│  • Template caching                                         │\n│  • Fragment caching                                         │\n│  • Template optimization                                    │\n└─────────────────────────────────────────────────────────────┘\n                            ↓\n┌─────────────────────────────────────────────────────────────┐\n│                    ORM/Database Layer                       │\n│  • Query optimization                                       │\n│  • Index optimization                                       │\n│  • Connection pooling                                       │\n└─────────────────────────────────────────────────────────────┘\n                            ↓\n┌─────────────────────────────────────────────────────────────┐\n│                    Caching Layer                            │\n│  • Query result caching                                     │\n│  • View caching                                             │\n│  • Session caching                                          │\n└─────────────────────────────────────────────────────────────┘\n                            ↓\n┌─────────────────────────────────────────────────────────────┐\n│                    Infrastructure Layer                     │\n│  • Load balancing                                           │\n│  • CDN for static files                                     │\n│  • Database replication                                     │\n└─────────────────────────────────────────────────────────────┘\n","text",[1143,1467,1464],{"__ignoreMap":1141},[1030,1469,1471],{"id":1470},"performance-optimization-workflow","Performance Optimization Workflow",[1038,1473,1475],{"id":1474},"_1-measure-first","1. Measure First",[1026,1477,1478],{},"Never optimize without measuring. Use profiling tools to identify actual bottlenecks:",[1136,1480,1482],{"className":1138,"code":1481,"language":1140,"meta":1141,"style":1141},"# Django Debug Toolbar - Essential for development\nINSTALLED_APPS = [\n    # ...\n    'debug_toolbar',\n]\n\nMIDDLEWARE = [\n    'debug_toolbar.middleware.DebugToolbarMiddleware',\n    # ...\n]\n\nINTERNAL_IPS = ['127.0.0.1']\n\n# django-silk - Production-ready profiling\nINSTALLED_APPS = [\n    # ...\n    'silk',\n]\n\nMIDDLEWARE = [\n    'silk.middleware.SilkyMiddleware',\n    # ...\n]\n",[1143,1483,1484,1489,1501,1506,1519,1524,1528,1537,1548,1552,1556,1560,1579,1583,1588,1596,1600,1611,1616,1621,1630,1642,1647],{"__ignoreMap":1141},[1146,1485,1486],{"class":1148,"line":1149},[1146,1487,1488],{"class":1152},"# Django Debug Toolbar - Essential for development\n",[1146,1490,1491,1495,1498],{"class":1148,"line":1156},[1146,1492,1494],{"class":1493},"se3Ec","INSTALLED_APPS",[1146,1496,1497],{"class":1167}," =",[1146,1499,1500],{"class":1167}," [\n",[1146,1502,1503],{"class":1148,"line":1178},[1146,1504,1505],{"class":1152},"    # ...\n",[1146,1507,1508,1511,1514,1516],{"class":1148,"line":1184},[1146,1509,1510],{"class":1285},"    '",[1146,1512,1513],{"class":1289},"debug_toolbar",[1146,1515,1293],{"class":1285},[1146,1517,1518],{"class":1167},",\n",[1146,1520,1521],{"class":1148,"line":1216},[1146,1522,1523],{"class":1167},"]\n",[1146,1525,1526],{"class":1148,"line":1235},[1146,1527,1320],{"emptyLinePlaceholder":1319},[1146,1529,1530,1533,1535],{"class":1148,"line":1263},[1146,1531,1532],{"class":1493},"MIDDLEWARE",[1146,1534,1497],{"class":1167},[1146,1536,1500],{"class":1167},[1146,1538,1539,1541,1544,1546],{"class":1148,"line":1269},[1146,1540,1510],{"class":1285},[1146,1542,1543],{"class":1289},"debug_toolbar.middleware.DebugToolbarMiddleware",[1146,1545,1293],{"class":1285},[1146,1547,1518],{"class":1167},[1146,1549,1550],{"class":1148,"line":1316},[1146,1551,1505],{"class":1152},[1146,1553,1554],{"class":1148,"line":1323},[1146,1555,1523],{"class":1167},[1146,1557,1558],{"class":1148,"line":1329},[1146,1559,1320],{"emptyLinePlaceholder":1319},[1146,1561,1562,1565,1567,1570,1572,1575,1577],{"class":1148,"line":1343},[1146,1563,1564],{"class":1493},"INTERNAL_IPS",[1146,1566,1497],{"class":1167},[1146,1568,1569],{"class":1167}," [",[1146,1571,1293],{"class":1285},[1146,1573,1574],{"class":1289},"127.0.0.1",[1146,1576,1293],{"class":1285},[1146,1578,1523],{"class":1167},[1146,1580,1581],{"class":1148,"line":1349},[1146,1582,1320],{"emptyLinePlaceholder":1319},[1146,1584,1585],{"class":1148,"line":1383},[1146,1586,1587],{"class":1152},"# django-silk - Production-ready profiling\n",[1146,1589,1590,1592,1594],{"class":1148,"line":1396},[1146,1591,1494],{"class":1493},[1146,1593,1497],{"class":1167},[1146,1595,1500],{"class":1167},[1146,1597,1598],{"class":1148,"line":1418},[1146,1599,1505],{"class":1152},[1146,1601,1602,1604,1607,1609],{"class":1148,"line":1423},[1146,1603,1510],{"class":1285},[1146,1605,1606],{"class":1289},"silk",[1146,1608,1293],{"class":1285},[1146,1610,1518],{"class":1167},[1146,1612,1614],{"class":1148,"line":1613},18,[1146,1615,1523],{"class":1167},[1146,1617,1619],{"class":1148,"line":1618},19,[1146,1620,1320],{"emptyLinePlaceholder":1319},[1146,1622,1624,1626,1628],{"class":1148,"line":1623},20,[1146,1625,1532],{"class":1493},[1146,1627,1497],{"class":1167},[1146,1629,1500],{"class":1167},[1146,1631,1633,1635,1638,1640],{"class":1148,"line":1632},21,[1146,1634,1510],{"class":1285},[1146,1636,1637],{"class":1289},"silk.middleware.SilkyMiddleware",[1146,1639,1293],{"class":1285},[1146,1641,1518],{"class":1167},[1146,1643,1645],{"class":1148,"line":1644},22,[1146,1646,1505],{"class":1152},[1146,1648,1650],{"class":1148,"line":1649},23,[1146,1651,1523],{"class":1167},[1038,1653,1655],{"id":1654},"_2-identify-bottlenecks","2. Identify Bottlenecks",[1026,1657,1658],{},"Common areas to investigate:",[1026,1660,1661],{},[1045,1662,1663],{},"Database Queries",[1049,1665,1666,1668,1670,1673],{},[1052,1667,1089],{},[1052,1669,1086],{},[1052,1671,1672],{},"Missing indexes",[1052,1674,1675],{},"N+1 query problems",[1026,1677,1678],{},[1045,1679,1680],{},"Template Rendering",[1049,1682,1683,1686,1689],{},[1052,1684,1685],{},"Template complexity",[1052,1687,1688],{},"Number of template tags",[1052,1690,1691],{},"Context data size",[1026,1693,1694],{},[1045,1695,1696],{},"Python Code",[1049,1698,1699,1702,1705],{},[1052,1700,1701],{},"Inefficient algorithms",[1052,1703,1704],{},"Unnecessary computations",[1052,1706,1707],{},"Memory allocations",[1026,1709,1710],{},[1045,1711,1712],{},"External Services",[1049,1714,1715,1718,1721],{},[1052,1716,1717],{},"API calls",[1052,1719,1720],{},"File I/O operations",[1052,1722,1723],{},"Network requests",[1038,1725,1727],{"id":1726},"_3-apply-optimizations","3. Apply Optimizations",[1026,1729,1730],{},"Prioritize optimizations by impact:",[1026,1732,1733],{},[1045,1734,1735],{},"High Impact, Low Effort",[1049,1737,1738,1741,1744,1747],{},[1052,1739,1740],{},"Add database indexes",[1052,1742,1743],{},"Use select_related/prefetch_related",[1052,1745,1746],{},"Enable query result caching",[1052,1748,1749],{},"Optimize template queries",[1026,1751,1752],{},[1045,1753,1754],{},"High Impact, Medium Effort",[1049,1756,1757,1760,1763,1766],{},[1052,1758,1759],{},"Implement view caching",[1052,1761,1762],{},"Add Redis for session storage",[1052,1764,1765],{},"Optimize database queries",[1052,1767,1768],{},"Use CDN for static files",[1026,1770,1771],{},[1045,1772,1773],{},"High Impact, High Effort",[1049,1775,1776,1779,1782,1785],{},[1052,1777,1778],{},"Database schema redesign",[1052,1780,1781],{},"Application architecture changes",[1052,1783,1784],{},"Implement async processing",[1052,1786,1787],{},"Add read replicas",[1038,1789,1791],{"id":1790},"_4-verify-improvements","4. Verify Improvements",[1026,1793,1794],{},"Measure performance after each optimization:",[1136,1796,1798],{"className":1138,"code":1797,"language":1140,"meta":1141,"style":1141},"import time\nfrom functools import wraps\n\ndef measure_performance(func):\n    \"\"\"Decorator to measure function execution time\"\"\"\n    @wraps(func)\n    def wrapper(*args, **kwargs):\n        start_time = time.time()\n        result = func(*args, **kwargs)\n        end_time = time.time()\n        \n        print(f\"{func.__name__} took {end_time - start_time:.4f} seconds\")\n        return result\n    \n    return wrapper\n\n@measure_performance\ndef expensive_operation():\n    # Your code here\n    pass\n",[1143,1799,1800,1808,1821,1825,1839,1852,1867,1894,1911,1935,1950,1955,2006,2014,2018,2025,2029,2037,2047,2052],{"__ignoreMap":1141},[1146,1801,1802,1805],{"class":1148,"line":1149},[1146,1803,1804],{"class":1219},"import",[1146,1806,1807],{"class":1187}," time\n",[1146,1809,1810,1813,1816,1818],{"class":1148,"line":1156},[1146,1811,1812],{"class":1219},"from",[1146,1814,1815],{"class":1187}," functools ",[1146,1817,1804],{"class":1219},[1146,1819,1820],{"class":1187}," wraps\n",[1146,1822,1823],{"class":1148,"line":1178},[1146,1824,1320],{"emptyLinePlaceholder":1319},[1146,1826,1827,1829,1832,1834,1837],{"class":1148,"line":1184},[1146,1828,1160],{"class":1159},[1146,1830,1831],{"class":1163}," measure_performance",[1146,1833,1168],{"class":1167},[1146,1835,1836],{"class":1171},"func",[1146,1838,1175],{"class":1167},[1146,1840,1841,1845,1849],{"class":1148,"line":1216},[1146,1842,1844],{"class":1843},"sm7ve","    \"\"\"",[1146,1846,1848],{"class":1847},"sVyVU","Decorator to measure function execution time",[1146,1850,1851],{"class":1843},"\"\"\"\n",[1146,1853,1854,1857,1860,1862,1864],{"class":1148,"line":1235},[1146,1855,1856],{"class":1167},"    @",[1146,1858,1859],{"class":1163},"wraps",[1146,1861,1168],{"class":1167},[1146,1863,1836],{"class":1206},[1146,1865,1866],{"class":1167},")\n",[1146,1868,1869,1872,1875,1877,1881,1884,1886,1889,1892],{"class":1148,"line":1263},[1146,1870,1871],{"class":1159},"    def",[1146,1873,1874],{"class":1163}," wrapper",[1146,1876,1168],{"class":1167},[1146,1878,1880],{"class":1879},"sVsLi","*",[1146,1882,1883],{"class":1171},"args",[1146,1885,1282],{"class":1167},[1146,1887,1888],{"class":1879}," **",[1146,1890,1891],{"class":1171},"kwargs",[1146,1893,1175],{"class":1167},[1146,1895,1896,1899,1901,1904,1906,1909],{"class":1148,"line":1269},[1146,1897,1898],{"class":1187},"        start_time ",[1146,1900,1191],{"class":1167},[1146,1902,1903],{"class":1187}," time",[1146,1905,1197],{"class":1167},[1146,1907,1908],{"class":1206},"time",[1146,1910,1380],{"class":1167},[1146,1912,1913,1916,1918,1921,1923,1925,1927,1929,1931,1933],{"class":1148,"line":1316},[1146,1914,1915],{"class":1187},"        result ",[1146,1917,1191],{"class":1167},[1146,1919,1920],{"class":1206}," func",[1146,1922,1168],{"class":1167},[1146,1924,1880],{"class":1879},[1146,1926,1883],{"class":1206},[1146,1928,1282],{"class":1167},[1146,1930,1888],{"class":1879},[1146,1932,1891],{"class":1206},[1146,1934,1866],{"class":1167},[1146,1936,1937,1940,1942,1944,1946,1948],{"class":1148,"line":1323},[1146,1938,1939],{"class":1187},"        end_time ",[1146,1941,1191],{"class":1167},[1146,1943,1903],{"class":1187},[1146,1945,1197],{"class":1167},[1146,1947,1908],{"class":1206},[1146,1949,1380],{"class":1167},[1146,1951,1952],{"class":1148,"line":1329},[1146,1953,1954],{"class":1187},"        \n",[1146,1956,1957,1959,1961,1964,1967,1971,1973,1975,1979,1982,1985,1987,1990,1993,1996,1999,2001,2004],{"class":1148,"line":1343},[1146,1958,1239],{"class":1238},[1146,1960,1168],{"class":1167},[1146,1962,1963],{"class":1159},"f",[1146,1965,1966],{"class":1289},"\"",[1146,1968,1970],{"class":1969},"s3h35","{",[1146,1972,1836],{"class":1206},[1146,1974,1197],{"class":1167},[1146,1976,1978],{"class":1977},"s131V","__name__",[1146,1980,1981],{"class":1969},"}",[1146,1983,1984],{"class":1289}," took ",[1146,1986,1970],{"class":1969},[1146,1988,1989],{"class":1206},"end_time ",[1146,1991,1992],{"class":1879},"-",[1146,1994,1995],{"class":1206}," start_time",[1146,1997,1998],{"class":1159},":.4f",[1146,2000,1981],{"class":1969},[1146,2002,2003],{"class":1289}," seconds\"",[1146,2005,1866],{"class":1167},[1146,2007,2008,2011],{"class":1148,"line":1349},[1146,2009,2010],{"class":1219},"        return",[1146,2012,2013],{"class":1187}," result\n",[1146,2015,2016],{"class":1148,"line":1383},[1146,2017,1266],{"class":1187},[1146,2019,2020,2022],{"class":1148,"line":1396},[1146,2021,1272],{"class":1219},[1146,2023,2024],{"class":1187}," wrapper\n",[1146,2026,2027],{"class":1148,"line":1418},[1146,2028,1320],{"emptyLinePlaceholder":1319},[1146,2030,2031,2034],{"class":1148,"line":1423},[1146,2032,2033],{"class":1167},"@",[1146,2035,2036],{"class":1163},"measure_performance\n",[1146,2038,2039,2041,2044],{"class":1148,"line":1613},[1146,2040,1160],{"class":1159},[1146,2042,2043],{"class":1163}," expensive_operation",[1146,2045,2046],{"class":1167},"():\n",[1146,2048,2049],{"class":1148,"line":1618},[1146,2050,2051],{"class":1152},"    # Your code here\n",[1146,2053,2054],{"class":1148,"line":1623},[1146,2055,2056],{"class":1219},"    pass\n",[1030,2058,2060],{"id":2059},"performance-optimization-principles","Performance Optimization Principles",[1038,2062,2064],{"id":2063},"_1-database-optimization-first","1. Database Optimization First",[1026,2066,2067],{},"Database queries are typically the biggest bottleneck:",[1049,2069,2070,2073,2076,2079,2082],{},[1052,2071,2072],{},"Minimize number of queries",[1052,2074,2075],{},"Optimize query complexity",[1052,2077,2078],{},"Add appropriate indexes",[1052,2080,2081],{},"Use database-level aggregations",[1052,2083,2084],{},"Implement connection pooling",[1038,2086,2088],{"id":2087},"_2-cache-aggressively","2. Cache Aggressively",[1026,2090,2091],{},"Caching eliminates repeated work:",[1049,2093,2094,2097,2100,2103],{},[1052,2095,2096],{},"Cache database query results",[1052,2098,2099],{},"Cache rendered templates",[1052,2101,2102],{},"Cache expensive computations",[1052,2104,2105],{},"Use appropriate cache invalidation",[1038,2107,2109],{"id":2108},"_3-optimize-template-rendering","3. Optimize Template Rendering",[1026,2111,2112],{},"Templates can be surprisingly slow:",[1049,2114,2115,2118,2121,2124],{},[1052,2116,2117],{},"Minimize template logic",[1052,2119,2120],{},"Cache template fragments",[1052,2122,2123],{},"Reduce context data size",[1052,2125,2126],{},"Use template inheritance efficiently",[1038,2128,2130],{"id":2129},"_4-async-for-io-operations","4. Async for I/O Operations",[1026,2132,2133],{},"Use async views for I/O-bound operations:",[1049,2135,2136,2139,2142,2145],{},[1052,2137,2138],{},"External API calls",[1052,2140,2141],{},"File operations",[1052,2143,2144],{},"Multiple database queries",[1052,2146,2147],{},"Long-running tasks",[1038,2149,2151],{"id":2150},"_5-profile-continuously","5. Profile Continuously",[1026,2153,2154],{},"Make profiling part of development:",[1049,2156,2157,2160,2163,2166],{},[1052,2158,2159],{},"Profile during development",[1052,2161,2162],{},"Monitor production performance",[1052,2164,2165],{},"Set performance budgets",[1052,2167,2168],{},"Track performance metrics",[1030,2170,2172],{"id":2171},"what-youll-learn","What You'll Learn",[1026,2174,2175],{},"This comprehensive performance guide covers:",[1026,2177,2178,2180],{},[1045,2179,781],{},": Master Django ORM optimization techniques, understand query execution plans, implement efficient database access patterns, and eliminate N+1 queries.",[1026,2182,2183,2185],{},[1045,2184,785],{},": Optimize template performance, implement template caching, reduce template complexity, and improve rendering speed.",[1026,2187,2188,2191],{},[1045,2189,2190],{},"Select Related and Prefetch Related",": Deep dive into Django's query optimization tools, understand when to use each, and implement complex prefetching strategies.",[1026,2193,2194,2196],{},[1045,2195,793],{},": Implement multi-level caching, use Redis effectively, cache invalidation patterns, and cache warming techniques.",[1026,2198,2199,2201],{},[1045,2200,797],{},": Use profiling tools effectively, identify performance bottlenecks, analyze query performance, and implement continuous performance monitoring.",[1030,2203,2205],{"id":2204},"real-world-performance-improvements","Real-World Performance Improvements",[1038,2207,2209],{"id":2208},"case-study-e-commerce-product-listing","Case Study: E-commerce Product Listing",[1026,2211,2212],{},[1045,2213,2214],{},"Before Optimization",[1136,2216,2218],{"className":1138,"code":2217,"language":1140,"meta":1141,"style":1141},"def product_list(request):\n    # 1 query for products\n    products = Product.objects.all()[:50]\n    \n    # N queries for categories (one per product)\n    # N queries for images (one per product)\n    # N queries for reviews (one per product)\n    # Total: 1 + 50 + 50 + 50 = 151 queries\n    # Response time: 2.5 seconds\n    \n    return render(request, 'products/list.html', {'products': products})\n",[1143,2219,2220,2233,2238,2265,2269,2274,2279,2284,2289,2294,2298],{"__ignoreMap":1141},[1146,2221,2222,2224,2227,2229,2231],{"class":1148,"line":1149},[1146,2223,1160],{"class":1159},[1146,2225,2226],{"class":1163}," product_list",[1146,2228,1168],{"class":1167},[1146,2230,1172],{"class":1171},[1146,2232,1175],{"class":1167},[1146,2234,2235],{"class":1148,"line":1156},[1146,2236,2237],{"class":1152},"    # 1 query for products\n",[1146,2239,2240,2243,2245,2248,2250,2252,2254,2256,2259,2263],{"class":1148,"line":1178},[1146,2241,2242],{"class":1187},"    products ",[1146,2244,1191],{"class":1167},[1146,2246,2247],{"class":1187}," Product",[1146,2249,1197],{"class":1167},[1146,2251,1201],{"class":1200},[1146,2253,1197],{"class":1167},[1146,2255,1207],{"class":1206},[1146,2257,2258],{"class":1167},"()[:",[1146,2260,2262],{"class":2261},"s7CZa","50",[1146,2264,1523],{"class":1167},[1146,2266,2267],{"class":1148,"line":1184},[1146,2268,1266],{"class":1187},[1146,2270,2271],{"class":1148,"line":1216},[1146,2272,2273],{"class":1152},"    # N queries for categories (one per product)\n",[1146,2275,2276],{"class":1148,"line":1235},[1146,2277,2278],{"class":1152},"    # N queries for images (one per product)\n",[1146,2280,2281],{"class":1148,"line":1263},[1146,2282,2283],{"class":1152},"    # N queries for reviews (one per product)\n",[1146,2285,2286],{"class":1148,"line":1269},[1146,2287,2288],{"class":1152},"    # Total: 1 + 50 + 50 + 50 = 151 queries\n",[1146,2290,2291],{"class":1148,"line":1316},[1146,2292,2293],{"class":1152},"    # Response time: 2.5 seconds\n",[1146,2295,2296],{"class":1148,"line":1323},[1146,2297,1266],{"class":1187},[1146,2299,2300,2302,2304,2306,2308,2310,2312,2315,2317,2319,2321,2323,2326,2328,2330,2333],{"class":1148,"line":1329},[1146,2301,1272],{"class":1219},[1146,2303,1275],{"class":1206},[1146,2305,1168],{"class":1167},[1146,2307,1172],{"class":1206},[1146,2309,1282],{"class":1167},[1146,2311,1286],{"class":1285},[1146,2313,2314],{"class":1289},"products/list.html",[1146,2316,1293],{"class":1285},[1146,2318,1282],{"class":1167},[1146,2320,1298],{"class":1167},[1146,2322,1293],{"class":1285},[1146,2324,2325],{"class":1289},"products",[1146,2327,1293],{"class":1285},[1146,2329,1308],{"class":1167},[1146,2331,2332],{"class":1206}," products",[1146,2334,1313],{"class":1167},[1026,2336,2337],{},[1045,2338,2339],{},"After Optimization",[1136,2341,2343],{"className":1138,"code":2342,"language":1140,"meta":1141,"style":1141},"def product_list(request):\n    # 1 query with JOINs and prefetching\n    products = Product.objects.select_related(\n        'category'\n    ).prefetch_related(\n        'images',\n        Prefetch('reviews', queryset=Review.objects.filter(is_approved=True))\n    ).only(\n        'id', 'name', 'price', 'category__name'\n    )[:50]\n    \n    # Total: 3 queries (products, images, reviews)\n    # Response time: 0.15 seconds\n    # Improvement: 94% faster, 98% fewer queries\n    \n    return render(request, 'products/list.html', {'products': products})\n",[1143,2344,2345,2357,2362,2381,2392,2402,2413,2461,2470,2505,2514,2518,2523,2528,2533,2537],{"__ignoreMap":1141},[1146,2346,2347,2349,2351,2353,2355],{"class":1148,"line":1149},[1146,2348,1160],{"class":1159},[1146,2350,2226],{"class":1163},[1146,2352,1168],{"class":1167},[1146,2354,1172],{"class":1171},[1146,2356,1175],{"class":1167},[1146,2358,2359],{"class":1148,"line":1156},[1146,2360,2361],{"class":1152},"    # 1 query with JOINs and prefetching\n",[1146,2363,2364,2366,2368,2370,2372,2374,2376,2378],{"class":1148,"line":1178},[1146,2365,2242],{"class":1187},[1146,2367,1191],{"class":1167},[1146,2369,2247],{"class":1187},[1146,2371,1197],{"class":1167},[1146,2373,1201],{"class":1200},[1146,2375,1197],{"class":1167},[1146,2377,1364],{"class":1206},[1146,2379,2380],{"class":1167},"(\n",[1146,2382,2383,2386,2389],{"class":1148,"line":1184},[1146,2384,2385],{"class":1285},"        '",[1146,2387,2388],{"class":1289},"category",[1146,2390,2391],{"class":1285},"'\n",[1146,2393,2394,2397,2400],{"class":1148,"line":1216},[1146,2395,2396],{"class":1167},"    ).",[1146,2398,2399],{"class":1206},"prefetch_related",[1146,2401,2380],{"class":1167},[1146,2403,2404,2406,2409,2411],{"class":1148,"line":1235},[1146,2405,2385],{"class":1285},[1146,2407,2408],{"class":1289},"images",[1146,2410,1293],{"class":1285},[1146,2412,1518],{"class":1167},[1146,2414,2415,2418,2420,2422,2425,2427,2429,2433,2435,2438,2440,2442,2444,2447,2449,2452,2454,2458],{"class":1148,"line":1263},[1146,2416,2417],{"class":1206},"        Prefetch",[1146,2419,1168],{"class":1167},[1146,2421,1293],{"class":1285},[1146,2423,2424],{"class":1289},"reviews",[1146,2426,1293],{"class":1285},[1146,2428,1282],{"class":1167},[1146,2430,2432],{"class":2431},"sqOPj"," queryset",[1146,2434,1191],{"class":1167},[1146,2436,2437],{"class":1206},"Review",[1146,2439,1197],{"class":1167},[1146,2441,1201],{"class":1200},[1146,2443,1197],{"class":1167},[1146,2445,2446],{"class":1206},"filter",[1146,2448,1168],{"class":1167},[1146,2450,2451],{"class":2431},"is_approved",[1146,2453,1191],{"class":1167},[1146,2455,2457],{"class":2456},"s8XtY","True",[1146,2459,2460],{"class":1167},"))\n",[1146,2462,2463,2465,2468],{"class":1148,"line":1269},[1146,2464,2396],{"class":1167},[1146,2466,2467],{"class":1206},"only",[1146,2469,2380],{"class":1167},[1146,2471,2472,2474,2477,2479,2481,2483,2485,2487,2489,2491,2494,2496,2498,2500,2503],{"class":1148,"line":1316},[1146,2473,2385],{"class":1285},[1146,2475,2476],{"class":1289},"id",[1146,2478,1293],{"class":1285},[1146,2480,1282],{"class":1167},[1146,2482,1286],{"class":1285},[1146,2484,1254],{"class":1289},[1146,2486,1293],{"class":1285},[1146,2488,1282],{"class":1167},[1146,2490,1286],{"class":1285},[1146,2492,2493],{"class":1289},"price",[1146,2495,1293],{"class":1285},[1146,2497,1282],{"class":1167},[1146,2499,1286],{"class":1285},[1146,2501,2502],{"class":1289},"category__name",[1146,2504,2391],{"class":1285},[1146,2506,2507,2510,2512],{"class":1148,"line":1323},[1146,2508,2509],{"class":1167},"    )[:",[1146,2511,2262],{"class":2261},[1146,2513,1523],{"class":1167},[1146,2515,2516],{"class":1148,"line":1329},[1146,2517,1266],{"class":1187},[1146,2519,2520],{"class":1148,"line":1343},[1146,2521,2522],{"class":1152},"    # Total: 3 queries (products, images, reviews)\n",[1146,2524,2525],{"class":1148,"line":1349},[1146,2526,2527],{"class":1152},"    # Response time: 0.15 seconds\n",[1146,2529,2530],{"class":1148,"line":1383},[1146,2531,2532],{"class":1152},"    # Improvement: 94% faster, 98% fewer queries\n",[1146,2534,2535],{"class":1148,"line":1396},[1146,2536,1266],{"class":1187},[1146,2538,2539,2541,2543,2545,2547,2549,2551,2553,2555,2557,2559,2561,2563,2565,2567,2569],{"class":1148,"line":1418},[1146,2540,1272],{"class":1219},[1146,2542,1275],{"class":1206},[1146,2544,1168],{"class":1167},[1146,2546,1172],{"class":1206},[1146,2548,1282],{"class":1167},[1146,2550,1286],{"class":1285},[1146,2552,2314],{"class":1289},[1146,2554,1293],{"class":1285},[1146,2556,1282],{"class":1167},[1146,2558,1298],{"class":1167},[1146,2560,1293],{"class":1285},[1146,2562,2325],{"class":1289},[1146,2564,1293],{"class":1285},[1146,2566,1308],{"class":1167},[1146,2568,2332],{"class":1206},[1146,2570,1313],{"class":1167},[1038,2572,2574],{"id":2573},"case-study-dashboard-with-statistics","Case Study: Dashboard with Statistics",[1026,2576,2577],{},[1045,2578,2214],{},[1136,2580,2582],{"className":1138,"code":2581,"language":1140,"meta":1141,"style":1141},"def dashboard(request):\n    # Multiple database queries\n    total_users = User.objects.count()  # Query 1\n    active_users = User.objects.filter(is_active=True).count()  # Query 2\n    total_orders = Order.objects.count()  # Query 3\n    revenue = Order.objects.aggregate(Sum('total'))['total__sum']  # Query 4\n    \n    # Response time: 1.2 seconds\n    \n    context = {\n        'total_users': total_users,\n        'active_users': active_users,\n        'total_orders': total_orders,\n        'revenue': revenue,\n    }\n    return render(request, 'dashboard.html', context)\n",[1143,2583,2584,2597,2602,2626,2661,2684,2732,2736,2741,2745,2755,2771,2787,2803,2819,2824],{"__ignoreMap":1141},[1146,2585,2586,2588,2591,2593,2595],{"class":1148,"line":1149},[1146,2587,1160],{"class":1159},[1146,2589,2590],{"class":1163}," dashboard",[1146,2592,1168],{"class":1167},[1146,2594,1172],{"class":1171},[1146,2596,1175],{"class":1167},[1146,2598,2599],{"class":1148,"line":1156},[1146,2600,2601],{"class":1152},"    # Multiple database queries\n",[1146,2603,2604,2607,2609,2612,2614,2616,2618,2621,2623],{"class":1148,"line":1178},[1146,2605,2606],{"class":1187},"    total_users ",[1146,2608,1191],{"class":1167},[1146,2610,2611],{"class":1187}," User",[1146,2613,1197],{"class":1167},[1146,2615,1201],{"class":1200},[1146,2617,1197],{"class":1167},[1146,2619,2620],{"class":1206},"count",[1146,2622,1210],{"class":1167},[1146,2624,2625],{"class":1152},"  # Query 1\n",[1146,2627,2628,2631,2633,2635,2637,2639,2641,2643,2645,2648,2650,2652,2654,2656,2658],{"class":1148,"line":1184},[1146,2629,2630],{"class":1187},"    active_users ",[1146,2632,1191],{"class":1167},[1146,2634,2611],{"class":1187},[1146,2636,1197],{"class":1167},[1146,2638,1201],{"class":1200},[1146,2640,1197],{"class":1167},[1146,2642,2446],{"class":1206},[1146,2644,1168],{"class":1167},[1146,2646,2647],{"class":2431},"is_active",[1146,2649,1191],{"class":1167},[1146,2651,2457],{"class":2456},[1146,2653,1375],{"class":1167},[1146,2655,2620],{"class":1206},[1146,2657,1210],{"class":1167},[1146,2659,2660],{"class":1152},"  # Query 2\n",[1146,2662,2663,2666,2668,2671,2673,2675,2677,2679,2681],{"class":1148,"line":1216},[1146,2664,2665],{"class":1187},"    total_orders ",[1146,2667,1191],{"class":1167},[1146,2669,2670],{"class":1187}," Order",[1146,2672,1197],{"class":1167},[1146,2674,1201],{"class":1200},[1146,2676,1197],{"class":1167},[1146,2678,2620],{"class":1206},[1146,2680,1210],{"class":1167},[1146,2682,2683],{"class":1152},"  # Query 3\n",[1146,2685,2686,2689,2691,2693,2695,2697,2699,2702,2704,2707,2709,2711,2714,2716,2719,2721,2724,2726,2729],{"class":1148,"line":1235},[1146,2687,2688],{"class":1187},"    revenue ",[1146,2690,1191],{"class":1167},[1146,2692,2670],{"class":1187},[1146,2694,1197],{"class":1167},[1146,2696,1201],{"class":1200},[1146,2698,1197],{"class":1167},[1146,2700,2701],{"class":1206},"aggregate",[1146,2703,1168],{"class":1167},[1146,2705,2706],{"class":1206},"Sum",[1146,2708,1168],{"class":1167},[1146,2710,1293],{"class":1285},[1146,2712,2713],{"class":1289},"total",[1146,2715,1293],{"class":1285},[1146,2717,2718],{"class":1167},"))[",[1146,2720,1293],{"class":1285},[1146,2722,2723],{"class":1289},"total__sum",[1146,2725,1293],{"class":1285},[1146,2727,2728],{"class":1167},"]",[1146,2730,2731],{"class":1152},"  # Query 4\n",[1146,2733,2734],{"class":1148,"line":1263},[1146,2735,1266],{"class":1187},[1146,2737,2738],{"class":1148,"line":1269},[1146,2739,2740],{"class":1152},"    # Response time: 1.2 seconds\n",[1146,2742,2743],{"class":1148,"line":1316},[1146,2744,1266],{"class":1187},[1146,2746,2747,2750,2752],{"class":1148,"line":1323},[1146,2748,2749],{"class":1187},"    context ",[1146,2751,1191],{"class":1167},[1146,2753,2754],{"class":1167}," {\n",[1146,2756,2757,2759,2762,2764,2766,2769],{"class":1148,"line":1329},[1146,2758,2385],{"class":1285},[1146,2760,2761],{"class":1289},"total_users",[1146,2763,1293],{"class":1285},[1146,2765,1308],{"class":1167},[1146,2767,2768],{"class":1187}," total_users",[1146,2770,1518],{"class":1167},[1146,2772,2773,2775,2778,2780,2782,2785],{"class":1148,"line":1343},[1146,2774,2385],{"class":1285},[1146,2776,2777],{"class":1289},"active_users",[1146,2779,1293],{"class":1285},[1146,2781,1308],{"class":1167},[1146,2783,2784],{"class":1187}," active_users",[1146,2786,1518],{"class":1167},[1146,2788,2789,2791,2794,2796,2798,2801],{"class":1148,"line":1349},[1146,2790,2385],{"class":1285},[1146,2792,2793],{"class":1289},"total_orders",[1146,2795,1293],{"class":1285},[1146,2797,1308],{"class":1167},[1146,2799,2800],{"class":1187}," total_orders",[1146,2802,1518],{"class":1167},[1146,2804,2805,2807,2810,2812,2814,2817],{"class":1148,"line":1383},[1146,2806,2385],{"class":1285},[1146,2808,2809],{"class":1289},"revenue",[1146,2811,1293],{"class":1285},[1146,2813,1308],{"class":1167},[1146,2815,2816],{"class":1187}," revenue",[1146,2818,1518],{"class":1167},[1146,2820,2821],{"class":1148,"line":1396},[1146,2822,2823],{"class":1167},"    }\n",[1146,2825,2826,2828,2830,2832,2834,2836,2838,2841,2843,2845,2848],{"class":1148,"line":1418},[1146,2827,1272],{"class":1219},[1146,2829,1275],{"class":1206},[1146,2831,1168],{"class":1167},[1146,2833,1172],{"class":1206},[1146,2835,1282],{"class":1167},[1146,2837,1286],{"class":1285},[1146,2839,2840],{"class":1289},"dashboard.html",[1146,2842,1293],{"class":1285},[1146,2844,1282],{"class":1167},[1146,2846,2847],{"class":1206}," context",[1146,2849,1866],{"class":1167},[1026,2851,2852],{},[1045,2853,2339],{},[1136,2855,2857],{"className":1138,"code":2856,"language":1140,"meta":1141,"style":1141},"from django.core.cache import cache\n\ndef dashboard(request):\n    # Try to get from cache first\n    cache_key = 'dashboard_stats'\n    stats = cache.get(cache_key)\n    \n    if stats is None:\n        # Single optimized query with aggregations\n        stats = User.objects.aggregate(\n            total_users=Count('id'),\n            active_users=Count('id', filter=Q(is_active=True))\n        )\n        \n        order_stats = Order.objects.aggregate(\n            total_orders=Count('id'),\n            revenue=Sum('total')\n        )\n        \n        stats.update(order_stats)\n        \n        # Cache for 5 minutes\n        cache.set(cache_key, stats, 300)\n    \n    # Response time: 0.05 seconds (cached), 0.3 seconds (uncached)\n    # Improvement: 96% faster (cached), 75% faster (uncached)\n    \n    return render(request, 'dashboard.html', stats)\n",[1143,2858,2859,2881,2885,2897,2902,2916,2938,2942,2958,2963,2982,3003,3040,3045,3049,3068,3087,3106,3110,3114,3131,3135,3140,3166,3171,3177,3183,3188],{"__ignoreMap":1141},[1146,2860,2861,2863,2866,2868,2871,2873,2876,2878],{"class":1148,"line":1149},[1146,2862,1812],{"class":1219},[1146,2864,2865],{"class":1187}," django",[1146,2867,1197],{"class":1167},[1146,2869,2870],{"class":1187},"core",[1146,2872,1197],{"class":1167},[1146,2874,2875],{"class":1187},"cache ",[1146,2877,1804],{"class":1219},[1146,2879,2880],{"class":1187}," cache\n",[1146,2882,2883],{"class":1148,"line":1156},[1146,2884,1320],{"emptyLinePlaceholder":1319},[1146,2886,2887,2889,2891,2893,2895],{"class":1148,"line":1178},[1146,2888,1160],{"class":1159},[1146,2890,2590],{"class":1163},[1146,2892,1168],{"class":1167},[1146,2894,1172],{"class":1171},[1146,2896,1175],{"class":1167},[1146,2898,2899],{"class":1148,"line":1184},[1146,2900,2901],{"class":1152},"    # Try to get from cache first\n",[1146,2903,2904,2907,2909,2911,2914],{"class":1148,"line":1216},[1146,2905,2906],{"class":1187},"    cache_key ",[1146,2908,1191],{"class":1167},[1146,2910,1286],{"class":1285},[1146,2912,2913],{"class":1289},"dashboard_stats",[1146,2915,2391],{"class":1285},[1146,2917,2918,2921,2923,2926,2928,2931,2933,2936],{"class":1148,"line":1235},[1146,2919,2920],{"class":1187},"    stats ",[1146,2922,1191],{"class":1167},[1146,2924,2925],{"class":1187}," cache",[1146,2927,1197],{"class":1167},[1146,2929,2930],{"class":1206},"get",[1146,2932,1168],{"class":1167},[1146,2934,2935],{"class":1206},"cache_key",[1146,2937,1866],{"class":1167},[1146,2939,2940],{"class":1148,"line":1263},[1146,2941,1266],{"class":1187},[1146,2943,2944,2947,2950,2953,2956],{"class":1148,"line":1269},[1146,2945,2946],{"class":1219},"    if",[1146,2948,2949],{"class":1187}," stats ",[1146,2951,2952],{"class":1879},"is",[1146,2954,2955],{"class":2456}," None",[1146,2957,1232],{"class":1167},[1146,2959,2960],{"class":1148,"line":1316},[1146,2961,2962],{"class":1152},"        # Single optimized query with aggregations\n",[1146,2964,2965,2968,2970,2972,2974,2976,2978,2980],{"class":1148,"line":1323},[1146,2966,2967],{"class":1187},"        stats ",[1146,2969,1191],{"class":1167},[1146,2971,2611],{"class":1187},[1146,2973,1197],{"class":1167},[1146,2975,1201],{"class":1200},[1146,2977,1197],{"class":1167},[1146,2979,2701],{"class":1206},[1146,2981,2380],{"class":1167},[1146,2983,2984,2987,2989,2992,2994,2996,2998,3000],{"class":1148,"line":1329},[1146,2985,2986],{"class":2431},"            total_users",[1146,2988,1191],{"class":1167},[1146,2990,2991],{"class":1206},"Count",[1146,2993,1168],{"class":1167},[1146,2995,1293],{"class":1285},[1146,2997,2476],{"class":1289},[1146,2999,1293],{"class":1285},[1146,3001,3002],{"class":1167},"),\n",[1146,3004,3005,3008,3010,3012,3014,3016,3018,3020,3022,3025,3027,3030,3032,3034,3036,3038],{"class":1148,"line":1343},[1146,3006,3007],{"class":2431},"            active_users",[1146,3009,1191],{"class":1167},[1146,3011,2991],{"class":1206},[1146,3013,1168],{"class":1167},[1146,3015,1293],{"class":1285},[1146,3017,2476],{"class":1289},[1146,3019,1293],{"class":1285},[1146,3021,1282],{"class":1167},[1146,3023,3024],{"class":2431}," filter",[1146,3026,1191],{"class":1167},[1146,3028,3029],{"class":1206},"Q",[1146,3031,1168],{"class":1167},[1146,3033,2647],{"class":2431},[1146,3035,1191],{"class":1167},[1146,3037,2457],{"class":2456},[1146,3039,2460],{"class":1167},[1146,3041,3042],{"class":1148,"line":1349},[1146,3043,3044],{"class":1167},"        )\n",[1146,3046,3047],{"class":1148,"line":1383},[1146,3048,1954],{"class":1187},[1146,3050,3051,3054,3056,3058,3060,3062,3064,3066],{"class":1148,"line":1396},[1146,3052,3053],{"class":1187},"        order_stats ",[1146,3055,1191],{"class":1167},[1146,3057,2670],{"class":1187},[1146,3059,1197],{"class":1167},[1146,3061,1201],{"class":1200},[1146,3063,1197],{"class":1167},[1146,3065,2701],{"class":1206},[1146,3067,2380],{"class":1167},[1146,3069,3070,3073,3075,3077,3079,3081,3083,3085],{"class":1148,"line":1418},[1146,3071,3072],{"class":2431},"            total_orders",[1146,3074,1191],{"class":1167},[1146,3076,2991],{"class":1206},[1146,3078,1168],{"class":1167},[1146,3080,1293],{"class":1285},[1146,3082,2476],{"class":1289},[1146,3084,1293],{"class":1285},[1146,3086,3002],{"class":1167},[1146,3088,3089,3092,3094,3096,3098,3100,3102,3104],{"class":1148,"line":1423},[1146,3090,3091],{"class":2431},"            revenue",[1146,3093,1191],{"class":1167},[1146,3095,2706],{"class":1206},[1146,3097,1168],{"class":1167},[1146,3099,1293],{"class":1285},[1146,3101,2713],{"class":1289},[1146,3103,1293],{"class":1285},[1146,3105,1866],{"class":1167},[1146,3107,3108],{"class":1148,"line":1613},[1146,3109,3044],{"class":1167},[1146,3111,3112],{"class":1148,"line":1618},[1146,3113,1954],{"class":1187},[1146,3115,3116,3119,3121,3124,3126,3129],{"class":1148,"line":1623},[1146,3117,3118],{"class":1187},"        stats",[1146,3120,1197],{"class":1167},[1146,3122,3123],{"class":1206},"update",[1146,3125,1168],{"class":1167},[1146,3127,3128],{"class":1206},"order_stats",[1146,3130,1866],{"class":1167},[1146,3132,3133],{"class":1148,"line":1632},[1146,3134,1954],{"class":1187},[1146,3136,3137],{"class":1148,"line":1644},[1146,3138,3139],{"class":1152},"        # Cache for 5 minutes\n",[1146,3141,3142,3145,3147,3150,3152,3154,3156,3159,3161,3164],{"class":1148,"line":1649},[1146,3143,3144],{"class":1187},"        cache",[1146,3146,1197],{"class":1167},[1146,3148,3149],{"class":1206},"set",[1146,3151,1168],{"class":1167},[1146,3153,2935],{"class":1206},[1146,3155,1282],{"class":1167},[1146,3157,3158],{"class":1206}," stats",[1146,3160,1282],{"class":1167},[1146,3162,3163],{"class":2261}," 300",[1146,3165,1866],{"class":1167},[1146,3167,3169],{"class":1148,"line":3168},24,[1146,3170,1266],{"class":1187},[1146,3172,3174],{"class":1148,"line":3173},25,[1146,3175,3176],{"class":1152},"    # Response time: 0.05 seconds (cached), 0.3 seconds (uncached)\n",[1146,3178,3180],{"class":1148,"line":3179},26,[1146,3181,3182],{"class":1152},"    # Improvement: 96% faster (cached), 75% faster (uncached)\n",[1146,3184,3186],{"class":1148,"line":3185},27,[1146,3187,1266],{"class":1187},[1146,3189,3191,3193,3195,3197,3199,3201,3203,3205,3207,3209,3211],{"class":1148,"line":3190},28,[1146,3192,1272],{"class":1219},[1146,3194,1275],{"class":1206},[1146,3196,1168],{"class":1167},[1146,3198,1172],{"class":1206},[1146,3200,1282],{"class":1167},[1146,3202,1286],{"class":1285},[1146,3204,2840],{"class":1289},[1146,3206,1293],{"class":1285},[1146,3208,1282],{"class":1167},[1146,3210,3158],{"class":1206},[1146,3212,1866],{"class":1167},[1030,3214,3216],{"id":3215},"performance-monitoring","Performance Monitoring",[1038,3218,3220],{"id":3219},"key-metrics-to-track","Key Metrics to Track",[1136,3222,3224],{"className":1138,"code":3223,"language":1140,"meta":1141,"style":1141},"# Custom middleware for performance tracking\nimport time\nfrom django.db import connection\nfrom django.utils.deprecation import MiddlewareMixin\n\nclass PerformanceMonitoringMiddleware(MiddlewareMixin):\n    def process_request(self, request):\n        request.start_time = time.time()\n        request.initial_queries = len(connection.queries)\n    \n    def process_response(self, request, response):\n        if hasattr(request, 'start_time'):\n            # Calculate metrics\n            duration = time.time() - request.start_time\n            num_queries = len(connection.queries) - request.initial_queries\n            \n            # Add headers for monitoring\n            response['X-Response-Time'] = f'{duration:.3f}s'\n            response['X-DB-Queries'] = str(num_queries)\n            \n            # Log slow requests\n            if duration > 1.0:\n                logger.warning(\n                    f'Slow request: {request.path} took {duration:.3f}s '\n                    f'with {num_queries} queries'\n                )\n        \n        return response\n",[1143,3225,3226,3231,3237,3253,3274,3278,3295,3315,3335,3361,3365,3387,3409,3414,3439,3467,3472,3477,3514,3542,3546,3551,3567,3579,3611,3627,3632,3636],{"__ignoreMap":1141},[1146,3227,3228],{"class":1148,"line":1149},[1146,3229,3230],{"class":1152},"# Custom middleware for performance tracking\n",[1146,3232,3233,3235],{"class":1148,"line":1156},[1146,3234,1804],{"class":1219},[1146,3236,1807],{"class":1187},[1146,3238,3239,3241,3243,3245,3248,3250],{"class":1148,"line":1178},[1146,3240,1812],{"class":1219},[1146,3242,2865],{"class":1187},[1146,3244,1197],{"class":1167},[1146,3246,3247],{"class":1187},"db ",[1146,3249,1804],{"class":1219},[1146,3251,3252],{"class":1187}," connection\n",[1146,3254,3255,3257,3259,3261,3264,3266,3269,3271],{"class":1148,"line":1184},[1146,3256,1812],{"class":1219},[1146,3258,2865],{"class":1187},[1146,3260,1197],{"class":1167},[1146,3262,3263],{"class":1187},"utils",[1146,3265,1197],{"class":1167},[1146,3267,3268],{"class":1187},"deprecation ",[1146,3270,1804],{"class":1219},[1146,3272,3273],{"class":1187}," MiddlewareMixin\n",[1146,3275,3276],{"class":1148,"line":1216},[1146,3277,1320],{"emptyLinePlaceholder":1319},[1146,3279,3280,3283,3287,3289,3293],{"class":1148,"line":1235},[1146,3281,3282],{"class":1159},"class",[1146,3284,3286],{"class":3285},"sD-vU"," PerformanceMonitoringMiddleware",[1146,3288,1168],{"class":1167},[1146,3290,3292],{"class":3291},"sYn-s","MiddlewareMixin",[1146,3294,1175],{"class":1167},[1146,3296,3297,3299,3302,3304,3308,3310,3313],{"class":1148,"line":1263},[1146,3298,1871],{"class":1159},[1146,3300,3301],{"class":1163}," process_request",[1146,3303,1168],{"class":1167},[1146,3305,3307],{"class":3306},"sRjD_","self",[1146,3309,1282],{"class":1167},[1146,3311,3312],{"class":1171}," request",[1146,3314,1175],{"class":1167},[1146,3316,3317,3320,3322,3325,3327,3329,3331,3333],{"class":1148,"line":1269},[1146,3318,3319],{"class":1187},"        request",[1146,3321,1197],{"class":1167},[1146,3323,3324],{"class":1200},"start_time",[1146,3326,1497],{"class":1167},[1146,3328,1903],{"class":1187},[1146,3330,1197],{"class":1167},[1146,3332,1908],{"class":1206},[1146,3334,1380],{"class":1167},[1146,3336,3337,3339,3341,3344,3346,3349,3351,3354,3356,3359],{"class":1148,"line":1316},[1146,3338,3319],{"class":1187},[1146,3340,1197],{"class":1167},[1146,3342,3343],{"class":1200},"initial_queries",[1146,3345,1497],{"class":1167},[1146,3347,3348],{"class":1238}," len",[1146,3350,1168],{"class":1167},[1146,3352,3353],{"class":1206},"connection",[1146,3355,1197],{"class":1167},[1146,3357,3358],{"class":1200},"queries",[1146,3360,1866],{"class":1167},[1146,3362,3363],{"class":1148,"line":1323},[1146,3364,1266],{"class":1187},[1146,3366,3367,3369,3372,3374,3376,3378,3380,3382,3385],{"class":1148,"line":1329},[1146,3368,1871],{"class":1159},[1146,3370,3371],{"class":1163}," process_response",[1146,3373,1168],{"class":1167},[1146,3375,3307],{"class":3306},[1146,3377,1282],{"class":1167},[1146,3379,3312],{"class":1171},[1146,3381,1282],{"class":1167},[1146,3383,3384],{"class":1171}," response",[1146,3386,1175],{"class":1167},[1146,3388,3389,3392,3395,3397,3399,3401,3403,3405,3407],{"class":1148,"line":1343},[1146,3390,3391],{"class":1219},"        if",[1146,3393,3394],{"class":1238}," hasattr",[1146,3396,1168],{"class":1167},[1146,3398,1172],{"class":1206},[1146,3400,1282],{"class":1167},[1146,3402,1286],{"class":1285},[1146,3404,3324],{"class":1289},[1146,3406,1293],{"class":1285},[1146,3408,1175],{"class":1167},[1146,3410,3411],{"class":1148,"line":1349},[1146,3412,3413],{"class":1152},"            # Calculate metrics\n",[1146,3415,3416,3419,3421,3423,3425,3427,3429,3432,3434,3436],{"class":1148,"line":1383},[1146,3417,3418],{"class":1187},"            duration ",[1146,3420,1191],{"class":1167},[1146,3422,1903],{"class":1187},[1146,3424,1197],{"class":1167},[1146,3426,1908],{"class":1206},[1146,3428,1210],{"class":1167},[1146,3430,3431],{"class":1879}," -",[1146,3433,3312],{"class":1187},[1146,3435,1197],{"class":1167},[1146,3437,3438],{"class":1200},"start_time\n",[1146,3440,3441,3444,3446,3448,3450,3452,3454,3456,3458,3460,3462,3464],{"class":1148,"line":1396},[1146,3442,3443],{"class":1187},"            num_queries ",[1146,3445,1191],{"class":1167},[1146,3447,3348],{"class":1238},[1146,3449,1168],{"class":1167},[1146,3451,3353],{"class":1206},[1146,3453,1197],{"class":1167},[1146,3455,3358],{"class":1200},[1146,3457,1257],{"class":1167},[1146,3459,3431],{"class":1879},[1146,3461,3312],{"class":1187},[1146,3463,1197],{"class":1167},[1146,3465,3466],{"class":1200},"initial_queries\n",[1146,3468,3469],{"class":1148,"line":1418},[1146,3470,3471],{"class":1187},"            \n",[1146,3473,3474],{"class":1148,"line":1423},[1146,3475,3476],{"class":1152},"            # Add headers for monitoring\n",[1146,3478,3479,3482,3485,3487,3490,3492,3494,3496,3499,3501,3503,3506,3509,3511],{"class":1148,"line":1613},[1146,3480,3481],{"class":1187},"            response",[1146,3483,3484],{"class":1167},"[",[1146,3486,1293],{"class":1285},[1146,3488,3489],{"class":1289},"X-Response-Time",[1146,3491,1293],{"class":1285},[1146,3493,2728],{"class":1167},[1146,3495,1497],{"class":1167},[1146,3497,3498],{"class":1159}," f",[1146,3500,1293],{"class":1289},[1146,3502,1970],{"class":1969},[1146,3504,3505],{"class":1187},"duration",[1146,3507,3508],{"class":1159},":.3f",[1146,3510,1981],{"class":1969},[1146,3512,3513],{"class":1289},"s'\n",[1146,3515,3516,3518,3520,3522,3525,3527,3529,3531,3535,3537,3540],{"class":1148,"line":1618},[1146,3517,3481],{"class":1187},[1146,3519,3484],{"class":1167},[1146,3521,1293],{"class":1285},[1146,3523,3524],{"class":1289},"X-DB-Queries",[1146,3526,1293],{"class":1285},[1146,3528,2728],{"class":1167},[1146,3530,1497],{"class":1167},[1146,3532,3534],{"class":3533},"sa2tF"," str",[1146,3536,1168],{"class":1167},[1146,3538,3539],{"class":1206},"num_queries",[1146,3541,1866],{"class":1167},[1146,3543,3544],{"class":1148,"line":1623},[1146,3545,3471],{"class":1187},[1146,3547,3548],{"class":1148,"line":1632},[1146,3549,3550],{"class":1152},"            # Log slow requests\n",[1146,3552,3553,3556,3559,3562,3565],{"class":1148,"line":1644},[1146,3554,3555],{"class":1219},"            if",[1146,3557,3558],{"class":1187}," duration ",[1146,3560,3561],{"class":1879},">",[1146,3563,3564],{"class":2261}," 1.0",[1146,3566,1232],{"class":1167},[1146,3568,3569,3572,3574,3577],{"class":1148,"line":1649},[1146,3570,3571],{"class":1187},"                logger",[1146,3573,1197],{"class":1167},[1146,3575,3576],{"class":1206},"warning",[1146,3578,2380],{"class":1167},[1146,3580,3581,3584,3587,3589,3591,3593,3596,3598,3600,3602,3604,3606,3608],{"class":1148,"line":3168},[1146,3582,3583],{"class":1159},"                    f",[1146,3585,3586],{"class":1289},"'Slow request: ",[1146,3588,1970],{"class":1969},[1146,3590,1172],{"class":1206},[1146,3592,1197],{"class":1167},[1146,3594,3595],{"class":1200},"path",[1146,3597,1981],{"class":1969},[1146,3599,1984],{"class":1289},[1146,3601,1970],{"class":1969},[1146,3603,3505],{"class":1206},[1146,3605,3508],{"class":1159},[1146,3607,1981],{"class":1969},[1146,3609,3610],{"class":1289},"s '\n",[1146,3612,3613,3615,3618,3620,3622,3624],{"class":1148,"line":3173},[1146,3614,3583],{"class":1159},[1146,3616,3617],{"class":1289},"'with ",[1146,3619,1970],{"class":1969},[1146,3621,3539],{"class":1206},[1146,3623,1981],{"class":1969},[1146,3625,3626],{"class":1289}," queries'\n",[1146,3628,3629],{"class":1148,"line":3179},[1146,3630,3631],{"class":1167},"                )\n",[1146,3633,3634],{"class":1148,"line":3185},[1146,3635,1954],{"class":1187},[1146,3637,3638,3640],{"class":1148,"line":3190},[1146,3639,2010],{"class":1219},[1146,3641,3642],{"class":1187}," response\n",[1030,3644,621],{"id":3645},"performance-testing",[1038,3647,3649],{"id":3648},"load-testing-with-locust","Load Testing with Locust",[1136,3651,3653],{"className":1138,"code":3652,"language":1140,"meta":1141,"style":1141},"# locustfile.py\nfrom locust import HttpUser, task, between\n\nclass DjangoUser(HttpUser):\n    wait_time = between(1, 3)\n    \n    @task(3)\n    def view_homepage(self):\n        self.client.get(\"/\")\n    \n    @task(2)\n    def view_product_list(self):\n        self.client.get(\"/products/\")\n    \n    @task(1)\n    def view_product_detail(self):\n        self.client.get(\"/products/1/\")\n    \n    def on_start(self):\n        # Login if needed\n        self.client.post(\"/login/\", {\n            \"username\": \"testuser\",\n            \"password\": \"testpass\"\n        })\n",[1143,3654,3655,3660,3682,3686,3700,3722,3726,3740,3753,3778,3782,3795,3808,3831,3835,3847,3860,3883,3887,3900,3905,3931,3953,3972],{"__ignoreMap":1141},[1146,3656,3657],{"class":1148,"line":1149},[1146,3658,3659],{"class":1152},"# locustfile.py\n",[1146,3661,3662,3664,3667,3669,3672,3674,3677,3679],{"class":1148,"line":1156},[1146,3663,1812],{"class":1219},[1146,3665,3666],{"class":1187}," locust ",[1146,3668,1804],{"class":1219},[1146,3670,3671],{"class":1187}," HttpUser",[1146,3673,1282],{"class":1167},[1146,3675,3676],{"class":1187}," task",[1146,3678,1282],{"class":1167},[1146,3680,3681],{"class":1187}," between\n",[1146,3683,3684],{"class":1148,"line":1178},[1146,3685,1320],{"emptyLinePlaceholder":1319},[1146,3687,3688,3690,3693,3695,3698],{"class":1148,"line":1184},[1146,3689,3282],{"class":1159},[1146,3691,3692],{"class":3285}," DjangoUser",[1146,3694,1168],{"class":1167},[1146,3696,3697],{"class":3291},"HttpUser",[1146,3699,1175],{"class":1167},[1146,3701,3702,3705,3707,3710,3712,3715,3717,3720],{"class":1148,"line":1216},[1146,3703,3704],{"class":1187},"    wait_time ",[1146,3706,1191],{"class":1167},[1146,3708,3709],{"class":1206}," between",[1146,3711,1168],{"class":1167},[1146,3713,3714],{"class":2261},"1",[1146,3716,1282],{"class":1167},[1146,3718,3719],{"class":2261}," 3",[1146,3721,1866],{"class":1167},[1146,3723,3724],{"class":1148,"line":1235},[1146,3725,1266],{"class":1187},[1146,3727,3728,3730,3733,3735,3738],{"class":1148,"line":1263},[1146,3729,1856],{"class":1167},[1146,3731,3732],{"class":1163},"task",[1146,3734,1168],{"class":1167},[1146,3736,3737],{"class":2261},"3",[1146,3739,1866],{"class":1167},[1146,3741,3742,3744,3747,3749,3751],{"class":1148,"line":1269},[1146,3743,1871],{"class":1159},[1146,3745,3746],{"class":1163}," view_homepage",[1146,3748,1168],{"class":1167},[1146,3750,3307],{"class":3306},[1146,3752,1175],{"class":1167},[1146,3754,3755,3758,3760,3763,3765,3767,3769,3771,3774,3776],{"class":1148,"line":1316},[1146,3756,3757],{"class":1493},"        self",[1146,3759,1197],{"class":1167},[1146,3761,3762],{"class":1200},"client",[1146,3764,1197],{"class":1167},[1146,3766,2930],{"class":1206},[1146,3768,1168],{"class":1167},[1146,3770,1966],{"class":1285},[1146,3772,3773],{"class":1289},"/",[1146,3775,1966],{"class":1285},[1146,3777,1866],{"class":1167},[1146,3779,3780],{"class":1148,"line":1323},[1146,3781,1266],{"class":1187},[1146,3783,3784,3786,3788,3790,3793],{"class":1148,"line":1329},[1146,3785,1856],{"class":1167},[1146,3787,3732],{"class":1163},[1146,3789,1168],{"class":1167},[1146,3791,3792],{"class":2261},"2",[1146,3794,1866],{"class":1167},[1146,3796,3797,3799,3802,3804,3806],{"class":1148,"line":1343},[1146,3798,1871],{"class":1159},[1146,3800,3801],{"class":1163}," view_product_list",[1146,3803,1168],{"class":1167},[1146,3805,3307],{"class":3306},[1146,3807,1175],{"class":1167},[1146,3809,3810,3812,3814,3816,3818,3820,3822,3824,3827,3829],{"class":1148,"line":1349},[1146,3811,3757],{"class":1493},[1146,3813,1197],{"class":1167},[1146,3815,3762],{"class":1200},[1146,3817,1197],{"class":1167},[1146,3819,2930],{"class":1206},[1146,3821,1168],{"class":1167},[1146,3823,1966],{"class":1285},[1146,3825,3826],{"class":1289},"/products/",[1146,3828,1966],{"class":1285},[1146,3830,1866],{"class":1167},[1146,3832,3833],{"class":1148,"line":1383},[1146,3834,1266],{"class":1187},[1146,3836,3837,3839,3841,3843,3845],{"class":1148,"line":1396},[1146,3838,1856],{"class":1167},[1146,3840,3732],{"class":1163},[1146,3842,1168],{"class":1167},[1146,3844,3714],{"class":2261},[1146,3846,1866],{"class":1167},[1146,3848,3849,3851,3854,3856,3858],{"class":1148,"line":1418},[1146,3850,1871],{"class":1159},[1146,3852,3853],{"class":1163}," view_product_detail",[1146,3855,1168],{"class":1167},[1146,3857,3307],{"class":3306},[1146,3859,1175],{"class":1167},[1146,3861,3862,3864,3866,3868,3870,3872,3874,3876,3879,3881],{"class":1148,"line":1423},[1146,3863,3757],{"class":1493},[1146,3865,1197],{"class":1167},[1146,3867,3762],{"class":1200},[1146,3869,1197],{"class":1167},[1146,3871,2930],{"class":1206},[1146,3873,1168],{"class":1167},[1146,3875,1966],{"class":1285},[1146,3877,3878],{"class":1289},"/products/1/",[1146,3880,1966],{"class":1285},[1146,3882,1866],{"class":1167},[1146,3884,3885],{"class":1148,"line":1613},[1146,3886,1266],{"class":1187},[1146,3888,3889,3891,3894,3896,3898],{"class":1148,"line":1618},[1146,3890,1871],{"class":1159},[1146,3892,3893],{"class":1163}," on_start",[1146,3895,1168],{"class":1167},[1146,3897,3307],{"class":3306},[1146,3899,1175],{"class":1167},[1146,3901,3902],{"class":1148,"line":1623},[1146,3903,3904],{"class":1152},"        # Login if needed\n",[1146,3906,3907,3909,3911,3913,3915,3918,3920,3922,3925,3927,3929],{"class":1148,"line":1632},[1146,3908,3757],{"class":1493},[1146,3910,1197],{"class":1167},[1146,3912,3762],{"class":1200},[1146,3914,1197],{"class":1167},[1146,3916,3917],{"class":1206},"post",[1146,3919,1168],{"class":1167},[1146,3921,1966],{"class":1285},[1146,3923,3924],{"class":1289},"/login/",[1146,3926,1966],{"class":1285},[1146,3928,1282],{"class":1167},[1146,3930,2754],{"class":1167},[1146,3932,3933,3936,3939,3941,3943,3946,3949,3951],{"class":1148,"line":1644},[1146,3934,3935],{"class":1285},"            \"",[1146,3937,3938],{"class":1289},"username",[1146,3940,1966],{"class":1285},[1146,3942,1308],{"class":1167},[1146,3944,3945],{"class":1285}," \"",[1146,3947,3948],{"class":1289},"testuser",[1146,3950,1966],{"class":1285},[1146,3952,1518],{"class":1167},[1146,3954,3955,3957,3960,3962,3964,3966,3969],{"class":1148,"line":1649},[1146,3956,3935],{"class":1285},[1146,3958,3959],{"class":1289},"password",[1146,3961,1966],{"class":1285},[1146,3963,1308],{"class":1167},[1146,3965,3945],{"class":1285},[1146,3967,3968],{"class":1289},"testpass",[1146,3970,3971],{"class":1285},"\"\n",[1146,3973,3974],{"class":1148,"line":3168},[1146,3975,3976],{"class":1167},"        })\n",[1030,3978,3980],{"id":3979},"next-steps","Next Steps",[1026,3982,3983],{},"Ready to optimize your Django application? Start with query optimization to eliminate N+1 queries and reduce database load. Then implement caching strategies to avoid repeated work. Use profiling tools to identify remaining bottlenecks and apply targeted optimizations.",[1026,3985,3986],{},"Each chapter provides practical techniques, real-world examples, and measurable improvements that transform slow Django applications into high-performance systems capable of handling thousands of concurrent users.",[1026,3988,3989],{},"The journey from a slow application to a high-performance system requires systematic optimization, continuous monitoring, and data-driven decision making. This guide provides the knowledge and tools needed to build Django applications that scale efficiently and provide excellent user experiences.",[3991,3992,3993],"style",{},"html pre.shiki code .s9Tkl, html code.shiki .s9Tkl{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#A0ADA0;--shiki-default-font-style:inherit;--shiki-dark:#758575DD;--shiki-dark-font-style:inherit}html pre.shiki code .s5Kfy, html code.shiki .s5Kfy{--shiki-light:#9C3EDA;--shiki-default:#AB5959;--shiki-dark:#CB7676}html pre.shiki code .sljsM, html code.shiki .sljsM{--shiki-light:#6182B8;--shiki-default:#59873A;--shiki-dark:#80A665}html pre.shiki code .soVBu, html code.shiki .soVBu{--shiki-light:#39ADB5;--shiki-default:#999999;--shiki-dark:#666666}html pre.shiki code .sCyAa, html code.shiki .sCyAa{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#393A34;--shiki-default-font-style:inherit;--shiki-dark:#DBD7CAEE;--shiki-dark-font-style:inherit}html pre.shiki code .sftqT, html code.shiki .sftqT{--shiki-light:#90A4AE;--shiki-default:#393A34;--shiki-dark:#DBD7CAEE}html pre.shiki code .sBPpx, html code.shiki .sBPpx{--shiki-light:#E53935;--shiki-default:#393A34;--shiki-dark:#DBD7CAEE}html pre.shiki code .siWMO, html code.shiki .siWMO{--shiki-light:#6182B8;--shiki-default:#393A34;--shiki-dark:#DBD7CAEE}html pre.shiki code .siDh9, html code.shiki .siDh9{--shiki-light:#39ADB5;--shiki-light-font-style:italic;--shiki-default:#1E754F;--shiki-default-font-style:inherit;--shiki-dark:#4D9375;--shiki-dark-font-style:inherit}html pre.shiki code .sJdAF, html code.shiki .sJdAF{--shiki-light:#6182B8;--shiki-default:#998418;--shiki-dark:#B8A965}html pre.shiki code .sbYkP, html code.shiki .sbYkP{--shiki-light:#39ADB5;--shiki-default:#B5695977;--shiki-dark:#C98A7D77}html pre.shiki code .sTbE_, html code.shiki .sTbE_{--shiki-light:#91B859;--shiki-default:#B56959;--shiki-dark:#C98A7D}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .se3Ec, html code.shiki .se3Ec{--shiki-light:#90A4AE;--shiki-default:#A65E2B;--shiki-dark:#C99076}html pre.shiki code .sm7ve, html code.shiki .sm7ve{--shiki-light:#39ADB5;--shiki-light-font-style:italic;--shiki-default:#B5695977;--shiki-default-font-style:inherit;--shiki-dark:#C98A7D77;--shiki-dark-font-style:inherit}html pre.shiki code .sVyVU, html code.shiki .sVyVU{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#B56959;--shiki-default-font-style:inherit;--shiki-dark:#C98A7D;--shiki-dark-font-style:inherit}html pre.shiki code .sVsLi, html code.shiki .sVsLi{--shiki-light:#39ADB5;--shiki-default:#AB5959;--shiki-dark:#CB7676}html pre.shiki code .s3h35, html code.shiki .s3h35{--shiki-light:#F76D47;--shiki-default:#A65E2B;--shiki-dark:#C99076}html pre.shiki code .s131V, html code.shiki .s131V{--shiki-light:#90A4AE;--shiki-default:#998418;--shiki-dark:#B8A965}html pre.shiki code .s7CZa, html code.shiki .s7CZa{--shiki-light:#F76D47;--shiki-default:#2F798A;--shiki-dark:#4C9A91}html pre.shiki code .sqOPj, html code.shiki .sqOPj{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#B07D48;--shiki-default-font-style:inherit;--shiki-dark:#BD976A;--shiki-dark-font-style:inherit}html pre.shiki code .s8XtY, html code.shiki .s8XtY{--shiki-light:#39ADB5;--shiki-default:#1E754F;--shiki-dark:#4D9375}html pre.shiki code .sD-vU, html code.shiki .sD-vU{--shiki-light:#E2931D;--shiki-default:#2E8F82;--shiki-dark:#5DA994}html pre.shiki code .sYn-s, html code.shiki .sYn-s{--shiki-light:#E2931D;--shiki-default:#59873A;--shiki-dark:#80A665}html pre.shiki code .sRjD_, html code.shiki .sRjD_{--shiki-light:#E53935;--shiki-light-font-style:italic;--shiki-default:#393A34;--shiki-default-font-style:inherit;--shiki-dark:#DBD7CAEE;--shiki-dark-font-style:inherit}html pre.shiki code .sa2tF, html code.shiki .sa2tF{--shiki-light:#E2931D;--shiki-default:#998418;--shiki-dark:#B8A965}",{"title":1141,"searchDepth":1149,"depth":1156,"links":3995},[3996,4001,4007,4014,4015,4019,4022,4025],{"id":1032,"depth":1156,"text":1033,"children":3997},[3998,3999,4000],{"id":1040,"depth":1178,"text":1041},{"id":1133,"depth":1178,"text":1134},{"id":1458,"depth":1178,"text":1459},{"id":1470,"depth":1156,"text":1471,"children":4002},[4003,4004,4005,4006],{"id":1474,"depth":1178,"text":1475},{"id":1654,"depth":1178,"text":1655},{"id":1726,"depth":1178,"text":1727},{"id":1790,"depth":1178,"text":1791},{"id":2059,"depth":1156,"text":2060,"children":4008},[4009,4010,4011,4012,4013],{"id":2063,"depth":1178,"text":2064},{"id":2087,"depth":1178,"text":2088},{"id":2108,"depth":1178,"text":2109},{"id":2129,"depth":1178,"text":2130},{"id":2150,"depth":1178,"text":2151},{"id":2171,"depth":1156,"text":2172},{"id":2204,"depth":1156,"text":2205,"children":4016},[4017,4018],{"id":2208,"depth":1178,"text":2209},{"id":2573,"depth":1178,"text":2574},{"id":3215,"depth":1156,"text":3216,"children":4020},[4021],{"id":3219,"depth":1178,"text":3220},{"id":3645,"depth":1156,"text":621,"children":4023},[4024],{"id":3648,"depth":1178,"text":3649},{"id":3979,"depth":1156,"text":3980},"md",null,{},{"title":775,"description":1028},"rokb_wcfm9Z1lQvUXAvgDXbfLBByaf5j_XSP-P0UPHo",[4032,4034],{"title":771,"path":772,"stem":773,"description":4033,"children":-1},"Comprehensive backup strategies are critical for Django applications to ensure data protection, disaster recovery, and business continuity. This chapter covers database backups, file system backups, automated backup procedures, disaster recovery planning, and backup testing strategies.",{"title":781,"path":782,"stem":783,"description":4035,"children":-1},"Database queries are often the primary performance bottleneck in Django applications. This chapter covers comprehensive query optimization techniques, from eliminating N+1 queries to implementing advanced database optimization strategies that can improve application performance by orders of magnitude.",1772474955245]