From c4ef9aa838ae4462cd7d086916c7abd9ea1e8080 Mon Sep 17 00:00:00 2001 From: Petrik Date: Tue, 2 Jun 2026 19:14:01 +0200 Subject: [PATCH] [sinatra] Return database results with symbols instead of strings Reuse symbols instead of creating new strings everytime. --- frameworks/sinatra/app.rb | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/frameworks/sinatra/app.rb b/frameworks/sinatra/app.rb index 79f535cef..a8344679e 100644 --- a/frameworks/sinatra/app.rb +++ b/frameworks/sinatra/app.rb @@ -110,14 +110,14 @@ class App < Sinatra::Base items = rows.map do |row| { - id: row['id'], - name: row['name'], - category: row['category'], - price: row['price'], - quantity: row['quantity'], - active: row['active'] == 1, - tags: JSON.parse(row['tags']), - rating: { score: row['rating_score'], count: row['rating_count'] } + id: row[:id], + name: row[:name], + category: row[:category], + price: row[:price], + quantity: row[:quantity], + active: row[:active] == 1, + tags: JSON.parse(row[:tags]), + rating: { score: row[:rating_score], count: row[:rating_count] } } end render_json JSON.generate(items: items, count: items.length) @@ -141,6 +141,7 @@ def self.get_async_db max_connections = ENV.fetch('MAX_THREADS', 4).to_i + ENV.fetch("MAX_IO_THREADS", 10).to_i ConnectionPool.new(size: max_connections, timeout: 5) do db = PG.connect(ENV['DATABASE_URL']) + db.field_name_type = :symbol db.prepare('select', PG_QUERY) db end