Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions frameworks/rails/app/controllers/benchmark_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ def db

min_val = (params[:min] || 10).to_f
max_val = (params[:max] || 50).to_f
conn = get_db
rows = conn.execute(DB_QUERY, [min_val, max_val])
rows = connection_pool.with do |conn|
conn.execute(DB_QUERY, [min_val, max_val])
end
items = rows.map do |r|
{
'id' => r['id'], 'name' => r['name'], 'category' => r['category'],
Expand All @@ -114,8 +115,8 @@ def not_found

private

def get_db
Thread.current[:rails_db] ||= begin
def connection_pool
$connection_pool ||= ConnectionPool.new(size: 4, timeout: 5) do
db = SQLite3::Database.new('/data/benchmark.db', readonly: true)
db.execute('PRAGMA mmap_size=268435456')
db.results_as_hash = true
Expand Down
Loading