Skip to content

Commit 21bf03c

Browse files
Merge pull request #9671 from p8/sinatra/ids-outside-connection
[ruby/sinatra] Get ids outside of database connection
2 parents b918ac4 + d0e486a commit 21bf03c

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

frameworks/Ruby/sinatra-sequel/hello_world.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,10 @@ def rand1
5454

5555
# Test type 3: Multiple database queries
5656
get '/queries' do
57+
ids = ALL_IDS.sample(bounded_queries)
5758
worlds =
5859
DB.synchronize do
59-
ALL_IDS.sample(bounded_queries).map do |id|
60+
ids.map do |id|
6061
World.with_pk(id)
6162
end
6263
end
@@ -79,9 +80,10 @@ def rand1
7980
# Test type 5: Database updates
8081
get '/updates' do
8182
worlds = nil
83+
ids = ALL_IDS.sample(bounded_queries)
8284
DB.synchronize do
8385
worlds =
84-
ALL_IDS.sample(bounded_queries).map do |id|
86+
ids.map do |id|
8587
world = World.with_pk(id)
8688
new_value = rand1
8789
new_value = rand1 while new_value == world.randomnumber

frameworks/Ruby/sinatra/hello_world.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,10 @@ def rand1
5959

6060
# Test type 3: Multiple database queries
6161
get '/queries' do
62+
ids = ALL_IDS.sample(bounded_queries)
6263
worlds =
6364
ActiveRecord::Base.with_connection do
64-
ALL_IDS.sample(bounded_queries).map do |id|
65+
ids.map do |id|
6566
World.find(id).attributes
6667
end
6768
end
@@ -86,8 +87,9 @@ def rand1
8687
# Test type 5: Database updates
8788
get '/updates' do
8889
worlds = nil
90+
ids = ALL_IDS.sample(bounded_queries)
8991
ActiveRecord::Base.with_connection do
90-
worlds = ALL_IDS.sample(bounded_queries).map do |id|
92+
worlds = ids.map do |id|
9193
world = World.find(id)
9294
new_value = rand1
9395
new_value = rand1 until new_value != world.randomNumber

0 commit comments

Comments
 (0)