CodeForAfrica / CodeForAfrica/sensors.AFRICA-api

Admin changelist N+1 query causes Gunicorn worker timeout on /admin/sensors/sensorlocation/

Open
#159 0 comments 0 reactions 1 assignee Claimed by @VinneyJ View on GitHub
Dominant language
Python
Stars
18
Forks
8
PR merge metrics
No merged PRs in 30d

Description

Labels: bug, performance, admin
Linked Sentry: SENSORSAFRICA-API-13Z — https://code-for-africa.sentry.io/issues/7569887953/
Environment: production

`/admin/sensors/sensorlocation/` triggers a per-row N+1 query pattern. A separate `COUNT(*) FROM sensors_sensordatavalue` plus a separate node lookup for each row in the changelist. With default `list_per_page` (~100), this fires 100+ sequential queries per page load, exceeding Gunicorn's worker timeout, which triggers a SIGABRT and `SystemExit: 1`.

## Root cause
`SensorLocationAdmin` (or a related inline) lacks `select_related`/`prefetch_related`/`annotate` in `get_queryset()`. Likely a `list_display` callable or `__str__` touching `sensordata_set.count()` per row.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.