feat: prefetch image related fields in event API#1154
feat: prefetch image related fields in event API#1154sentry[bot] wants to merge 1 commit intomainfrom
Conversation
a62b6e2 to
9a7addf
Compare
|
LINKEDEVENTS-API branch is deployed to platta: https://linkedevents-pr1154.api.dev.hel.ninja 🚀🚀🚀 |
|
LINKEDEVENTS-API branch is deployed to platta: https://linkedevents-pr1154.api.dev.hel.ninja 🚀🚀🚀 |
|
@sentry review |
There was a problem hiding this comment.
Pull request overview
This PR addresses an N+1 query problem in the EventSerializer by adding prefetch optimization for image-related fields when the include=images parameter is used in the event API.
Changes:
- Added
prefetch_relatedfor image foreign key relationships (created_by,data_source,last_modified_by,license,publisher) in the EventViewSet - Added comprehensive test coverage to verify the prefetch optimization prevents N+1 queries when listing multiple events with images
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| events/api.py | Adds prefetch_related optimization for image-related fields in the _optimize_include method |
| events/tests/test_event_get.py | Adds test to verify that query count remains constant when adding more events with images |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
9a7addf to
9a26aa7
Compare
|
LINKEDEVENTS-API branch is deployed to platta: https://linkedevents-pr1154.api.dev.hel.ninja 🚀🚀🚀 |
Refs: LINK-2490
9a26aa7 to
209d0ed
Compare
|



Fixes LINKEDEVENTS-4. The issue was that: EventSerializer's nested field access triggers N+1 queries due to incomplete prefetch_related in EventViewSet's queryset.
created_by,data_source,last_modified_by,license, andpublisherfor images when 'images' are included in the request.This fix was generated by Seer in Sentry, triggered automatically. 👁️ Run ID: 594568
Not quite right? Click here to continue debugging with Seer.