Cancel connection with Rails DB

I am writing an application that uses Server Side events with ActionController :: Live. It uses the puma application server. The method in the message controller remains alive while the user is connected, waiting for messages from Redis.

The problem is that I do not want to connect to Postgres using this method. After I open the application on six tabs, it has more than five connections, determined by the size of the pool in the config/database.yml file, and the application crashes.

In any case, in order to inform my application when this method is called, it does not need to connect to the database, since it does not have requests to call ActiveRecord?

+6
source share
1 answer

One possible way to do this is to use middleware. A good resource for setting up your own middleware is http://railscasts.com/episodes/151-rack-middleware?view=asciicast

However, I'm not sure if the problem you are facing is due to too many connections to Postgres. This is just a hunch, but I think your problem may be elsewhere.

+1
source

Source: https://habr.com/ru/post/947484/


All Articles