f-klubben / stregsystemet

The very public stregsystem repo
Other
38 stars 49 forks source link

Improve slow queries #105

Open VirtualSatai opened 6 years ago

VirtualSatai commented 6 years ago

We have some slow queries, most of them are when the query hit the sales table, since it's quite big. We have removed all raw SQL in favour of using Django ORM to ease portability. Most of the methods containing these queries are unit tested for correctness, but maybe not all (yet!).

Currently the production environment uses MySQL 5.7.19, this is probably not the fastest and/or best option, we only run it since it was what was running previously. @DelusionalLogic and I have done limited informal testing using MariaDB, which was much faster for every query we tested. Also tested PostgreSQL which is even faster! But MariaDB should be pretty much a drop-in replacement.

jones-g commented 6 years ago

As far as I know the recommended database for Django today is Postgres so if we at all could move to that backend that would be preferable.

Pal0r commented 6 years ago

Before you migrate providers, running some profiles of your views would be helpful in finding the bloated query. I can see a few pretty slow queries in the stregreport.views file. A cProfile using prod data would show which is the worst offender.