I Have this dashboard(report) which basically performs a heavy sql query and display its results on a table grid, pretty standard stuff.
However, sometimes, the query is way to heavy, due to large volume of data and sql complexity, and the browser just hangs until the user gets an error.
I have no n+1 queries, and tried adding pagination, but I am still facing this issue.
What would be the best approach on this? Using a background job?
Is there a way to perform this query on the background, to prevent the request from failing?
I tried implementing a sidekiq worker, but I am not sure if I can get the results back from the worker, after the job is completed.
@results = ActiveRecord::Base
.connection
.select_all(query)
.map do |record|
Hashie::Mash.new(record)
end
query
contains the SQL query on a string.
Any insights?