Use ActiveRecord connection middleware to avoid timeout