Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add missing index on 'submissions.created_at'
In July 2018 it was noted that the `submissions.created_at` field ought to be indexed as it was now used in a query: #23 This is `Task#latest_submission` (f46dd46) which is used by the 'no_business' endpoint (`/v1/tasks/#{task.id}/no_business`) As the query selecting the most recent submission uses: `has_one :latest_submission, -> { order(created_at: :desc) }` I've opted for an index which is 'sorted' to suit. This work was requested in order to improve the problematic daily export procedure invoked via `DataWarehouseExport.generate!` which runs out of memory and times out regularly. This unindexed field (`submissions.created_at`) isn't actually involved in any of the 4 "extractions" which run. We believe that the 2 problem extractions are - `Export::Invoices::Extract` - `Export::Contracts::Extract` and that improvements to these may be brought about by adding the following indexes: - `tasks.updated_at` - `submissions.updated_at` - `submission_entries.updated_at` The following PR will add these indexes. But we actually believe that the main problem is Postgres memory: - the index on SubmissionEntry no longer fits in memory: we are going to look into increasing the memory allocation in Postgres - the `submission_entries.*` glob in the SELECT statement may include more data than is required: we will explore whether a sub-set of the SubmissionEntry fields can be returned by the DB Zendesk : https://dxw.zendesk.com/agent/tickets/10463 Trello : https://trello.com/c/GeaLyAWy/1162
- Loading branch information