jazzband / django-constance

Dynamic Django settings.
https://django-constance.readthedocs.io
BSD 3-Clause "New" or "Revised" License
1.66k stars 307 forks source link

Repeating queries when constance is installed #504

Closed ericswpark closed 1 year ago

ericswpark commented 1 year ago

Describe the problem

Sentry is reporting that constance is performing a n + 1 query whenever the main page of my website loads. Strangely the main page does not use any configuration values from constance (as far as I can tell).

Repeating query

SELECT "constance_config"."id", "constance_config"."key", "constance_config"."value" FROM "constance_config" WHERE "constance_config"."key" = %s LIMIT 21
N+1 Query SELECT constance_config id, constance_config key, constance_config value FROM constance_config WHERE c

System configuration

sergei-iurchenko commented 1 year ago

Use can use django-debug-toolbar to find the source of the query

ericswpark commented 1 year ago

Apparently the main page uses some configuration values which I forgot about, which was revealed with django-debug-toolbar (thanks @sergei-iurchenko !) I've decided to leave them as the page is cached so it's not such a performance concern.