Invoking a large set of SQL from a Rails 4 application

前端 未结 8 1046
有刺的猬
有刺的猬 2020-12-30 07:11

I have a Rails 4 application that I use in conjunction with sidekiq to run asynchronous jobs. One of the jobs I normally run outside of my Rails application is

8条回答
  •  醉话见心
    2020-12-30 07:50

    If you are running big SQL every time, i suggest you to create a sql view for it. It be boost the execution time. The other thing is, if possible try to split all those SQL query in such a way that it will be executed parallely instead of sequentially and then push it to sidekiq queue.

    You have to use ActiveRecord::Base.connection.execute or ModelClass.find_by_sql to run custom SQL.

    Also, put an eye on ROLLBACK transactions, you will find many places where you dont need such ROLLBACK feature. If you avoid that, the query will run faster but it is dangerous.

    Thanks all i can suggest.

提交回复
热议问题