How can I selectively override a django .count() method
- by Tom Viner
I'm using postGresSQL and my main table has about 20,000 rows. Sometimes count() methods can take ages or even timeout.
Mod.manager.filter(...).count()
I need to selectively override the count() method depending on what filter has been applied.
Just having a cache of results would be a great gain but I'd like to be able to say: if filter query is just {'enabled'=True} then return 20,000 without touching the db.
Note: I can't prevent the call to .count() as it's inside django's pagination, which always does a count.