Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use pluck(:value).first to prevent ORDER BY in SQL query
The SQL queries to determine each promotions code or batches of codes count are currently the slowest queries on the promotions index page. In our application containing approximately 32 Million codes and counting they've significantly slowed down the page by approximately 80-100 seconds currently. This was caused by the SQL's ORDER BY clause trying to sort all the records as they were being counted which was not necessary. Then when calling `.first` to initialize the ActiveRecordR object it would add even further delay to the rendering approximately 5 seconds. By using `pluck(:code)` the ORDER BY statement is dropped, and we don't have to initialize a full ActiveRecord object either.
- Loading branch information