Add missing index on 'submissions.created_at' #559
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 memoryand times out regularly.
This unindexed field (
submissions.created_at
) isn'tactually 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.