Skip to content

Commit

Permalink
Updates for caching samples ...
Browse files Browse the repository at this point in the history
  - Replace modify_team.html.erb with a simple `render :text` statement
  - Update all cache logging examples to show Rails 2.1 output
  - Update fixtures to remove declaration of record IDs wherever possible
  • Loading branch information
jasonrudolph committed Sep 22, 2008
1 parent d60e5d9 commit 2efece6
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 114 deletions.
4 changes: 4 additions & 0 deletions rails_samples/app/controllers/baseball_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ def show_team_cached
# codecite controllerquerycache
def modify_team
team = Team.find(params[:id])

team2 = Team.find(params[:id])
team2.name = "New Name"
team2.save

team3 = Team.find(params[:id])

render :text => "Modified"
end
# codecite controllerquerycache

Expand Down
1 change: 0 additions & 1 deletion rails_samples/app/views/baseball/modify_team.html.erb

This file was deleted.

133 changes: 66 additions & 67 deletions rails_samples/historical_logs/perf_cache.txt
Original file line number Diff line number Diff line change
@@ -1,88 +1,87 @@
# codecite nocache
Processing BaseballController#show_team_cached (for 127.0.0.1 at 2007-10-26 13:47:57) [GET]
Session ID: BAh7BiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNo%0ASGFzaHsABjoKQHVzZWR7AA%3D%3D--2f18f5b4601093f9163734981d5905979f0347b9
Parameters: {"action"=>"show_team_cached", "id"=>"1", "controller"=>"baseball"}
Team Columns (0.001908) SHOW FIELDS FROM teams
Team Load (0.000653) SELECT * FROM teams WHERE (teams.`id` = 1) 
Rendering baseball/show_team_cached
Player Load (0.000659) SELECT players.* FROM players INNER JOIN contracts ON players.id = contracts.player_id WHERE ((contracts.team_id = 1)) 
Player Columns (0.001318) SHOW FIELDS FROM players
Completed in 0.01918 (52 reqs/sec) | Rendering: 0.00911 (47%) | DB: 0.00454 (23%) | 200 OK [http://localhost/baseball/show_team_cached/1]
Processing BaseballController#show_team (for 127.0.0.1 at 2008-09-22 15:31:49) [GET]
Session ID: BAh7BiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNo
SGFzaHsABjoKQHVzZWR7AA==--5e49bdf6639fdc26f216483d87894b99e8190efc
Parameters: {"action"=>"show_team", "id"=>"1", "controller"=>"baseball"}
Team Columns (0.001362) SHOW FIELDS FROM `teams`
Team Load (0.002079) SELECT * FROM `teams` WHERE (`teams`.`id` = 1)
Rendering baseball/show_team
Player Load (0.000620) SELECT `players`.* FROM `players` INNER JOIN contracts ON players.id = contracts.player_id WHERE ((`contracts`.team_id = 1))
Player Columns (0.001569) SHOW FIELDS FROM `players`
Completed in 0.02851 (35 reqs/sec) | Rendering: 0.01756 (61%) | DB: 0.00563 (19%) | 200 OK [http://localhost/baseball/show_team/1]


Processing BaseballController#show_team_cached (for 127.0.0.1 at 2007-10-26 13:47:58) [GET]
Session ID: BAh7BiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNo%0ASGFzaHsABjoKQHVzZWR7AA%3D%3D--2f18f5b4601093f9163734981d5905979f0347b9
Parameters: {"action"=>"show_team_cached", "id"=>"1", "controller"=>"baseball"}
Team Columns (0.002220) SHOW FIELDS FROM teams
Team Load (0.000505) SELECT * FROM teams WHERE (teams.`id` = 1) 
Rendering baseball/show_team_cached
Player Load (0.000703) SELECT players.* FROM players INNER JOIN contracts ON players.id = contracts.player_id WHERE ((contracts.team_id = 1)) 
Player Columns (0.002214) SHOW FIELDS FROM players
Completed in 0.07678 (13 reqs/sec) | Rendering: 0.01308 (17%) | DB: 0.00564 (7%) | 200 OK [http://localhost/baseball/show_team_cached/1]
Processing BaseballController#show_team (for 127.0.0.1 at 2008-09-22 15:31:51) [GET]
Session ID: BAh7BiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNo
SGFzaHsABjoKQHVzZWR7AA==--5e49bdf6639fdc26f216483d87894b99e8190efc
Parameters: {"action"=>"show_team", "id"=>"1", "controller"=>"baseball"}
Team Columns (0.001369) SHOW FIELDS FROM `teams`
Team Load (0.001876) SELECT * FROM `teams` WHERE (`teams`.`id` = 1)
Rendering baseball/show_team
Player Load (0.000683) SELECT `players`.* FROM `players` INNER JOIN contracts ON players.id = contracts.player_id WHERE ((`contracts`.team_id = 1))
Player Columns (0.001610) SHOW FIELDS FROM `players`
Completed in 0.03088 (32 reqs/sec) | Rendering: 0.01993 (64%) | DB: 0.00554 (17%) | 200 OK [http://localhost/baseball/show_team/1]


Processing BaseballController#show_team_cached (for 127.0.0.1 at 2007-10-26 13:48:41) [GET]
Session ID: BAh7BiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNo%0ASGFzaHsABjoKQHVzZWR7AA%3D%3D--2f18f5b4601093f9163734981d5905979f0347b9
Parameters: {"action"=>"show_team_cached", "id"=>"1", "controller"=>"baseball"}
SQL (0.000170) SET NAMES 'utf8'
SQL (0.000087) SET SQL_AUTO_IS_NULL=0
Fragment read: localhost:3000/baseball/show_team_cached/1 (0.00002)
Team Columns (0.002082) SHOW FIELDS FROM teams
Team Load (0.000499) SELECT * FROM teams WHERE (teams.`id` = 1) 
Rendering baseball/show_team_cached
Fragment read: localhost:3000/baseball/show_team_cached/1 (0.00002)
Player Load (0.000692) SELECT players.* FROM players INNER JOIN contracts ON players.id = contracts.player_id WHERE ((contracts.team_id = 1)) 
Player Columns (0.001642) SHOW FIELDS FROM players
Cached fragment: localhost:3000/baseball/show_team_cached/1 (0.00002)
Completed in 0.02443 (40 reqs/sec) | Rendering: 0.01267 (51%) | DB: 0.00517 (21%) | 200 OK [http://localhost/baseball/show_team_cached/1]
Processing BaseballController#show_team (for 127.0.0.1 at 2008-09-22 15:31:52) [GET]
Session ID: BAh7BiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNo
SGFzaHsABjoKQHVzZWR7AA==--5e49bdf6639fdc26f216483d87894b99e8190efc
Parameters: {"action"=>"show_team", "id"=>"1", "controller"=>"baseball"}
Team Columns (0.001347) SHOW FIELDS FROM `teams`
Team Load (0.001851) SELECT * FROM `teams` WHERE (`teams`.`id` = 1)
Rendering baseball/show_team
Player Load (0.000688) SELECT `players`.* FROM `players` INNER JOIN contracts ON players.id = contracts.player_id WHERE ((`contracts`.team_id = 1))
Player Columns (0.001630) SHOW FIELDS FROM `players`
Completed in 0.03050 (32 reqs/sec) | Rendering: 0.01949 (63%) | DB: 0.00552 (18%) | 200 OK [http://localhost/baseball/show_team/1]
# codecite nocache

# codecite fragment
Processing BaseballController#show_team_cached (for 127.0.0.1 at 2007-10-26 13:49:24) [GET]
Session ID: BAh7BiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNo%0ASGFzaHsABjoKQHVzZWR7AA%3D%3D--2f18f5b4601093f9163734981d5905979f0347b9
Processing BaseballController#show_team_cached (for 127.0.0.1 at 2008-09-22 15:33:28) [GET]
Session ID: BAh7BiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNo
SGFzaHsABjoKQHVzZWR7AA==--5e49bdf6639fdc26f216483d87894b99e8190efc
Parameters: {"action"=>"show_team_cached", "id"=>"1", "controller"=>"baseball"}
SQL (0.000100) SET NAMES 'utf8'
SQL (0.000084) SET SQL_AUTO_IS_NULL=0
Fragment read: localhost:3000/baseball/show_team_cached/1 (0.00002)
Team Columns (0.002063) SHOW FIELDS FROM teams
Team Load (0.000558) SELECT * FROM teams WHERE (teams.`id` = 1) 
SQL (0.000229) SET NAMES 'utf8'
SQL (0.000110) SET SQL_AUTO_IS_NULL=0
Cached fragment hit: views/localhost:3001/baseball/show_team_cached/1 (0.00002)
Team Columns (0.002073) SHOW FIELDS FROM `teams`
Team Load (0.000305) SELECT * FROM `teams` WHERE (`teams`.`id` = 1)
Rendering baseball/show_team_cached
Fragment read: localhost:3000/baseball/show_team_cached/1 (0.00002)
Player Load (0.000742) SELECT players.* FROM players INNER JOIN contracts ON players.id = contracts.player_id WHERE ((contracts.team_id = 1)) 
Player Columns (0.001458) SHOW FIELDS FROM players
Cached fragment: localhost:3000/baseball/show_team_cached/1 (0.00002)
Completed in 0.02462 (40 reqs/sec) | Rendering: 0.01339 (54%) | DB: 0.00500 (20%) | 200 OK [http://localhost/baseball/show_team_cached/1]
Cached fragment hit: views/localhost:3001/baseball/show_team_cached/1 (0.00002)
Player Load (0.000593) SELECT `players`.* FROM `players` INNER JOIN contracts ON players.id = contracts.player_id WHERE ((`contracts`.team_id = 1))
Player Columns (0.001045) SHOW FIELDS FROM `players`
Cached fragment miss: views/localhost:3001/baseball/show_team_cached/1 (0.00002)
Completed in 0.03046 (32 reqs/sec) | Rendering: 0.01770 (58%) | DB: 0.00436 (14%) | 200 OK [http://localhost/baseball/show_team_cached/1]


Processing BaseballController#show_team_cached (for 127.0.0.1 at 2007-10-26 13:49:25) [GET]
Session ID: BAh7BiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNo%0ASGFzaHsABjoKQHVzZWR7AA%3D%3D--2f18f5b4601093f9163734981d5905979f0347b9
Processing BaseballController#show_team_cached (for 127.0.0.1 at 2008-09-22 15:33:29) [GET]
Session ID: BAh7BiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNo
SGFzaHsABjoKQHVzZWR7AA==--5e49bdf6639fdc26f216483d87894b99e8190efc
Parameters: {"action"=>"show_team_cached", "id"=>"1", "controller"=>"baseball"}
Fragment read: localhost:3000/baseball/show_team_cached/1 (0.00002)
Cached fragment hit: views/localhost:3001/baseball/show_team_cached/1 (0.00002)
Rendering baseball/show_team_cached
Fragment read: localhost:3000/baseball/show_team_cached/1 (0.00002)
Completed in 0.00235 (425 reqs/sec) | Rendering: 0.00077 (32%) | DB: 0.00000 (0%) | 200 OK [http://localhost/baseball/show_team_cached/1]
Cached fragment hit: views/localhost:3001/baseball/show_team_cached/1 (0.00001)
Completed in 0.00231 (433 reqs/sec) | Rendering: 0.00060 (25%) | DB: 0.00000 (0%) | 200 OK [http://localhost/baseball/show_team_cached/1]


Processing BaseballController#show_team_cached (for 127.0.0.1 at 2007-10-26 13:49:25) [GET]
Session ID: BAh7BiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNo%0ASGFzaHsABjoKQHVzZWR7AA%3D%3D--2f18f5b4601093f9163734981d5905979f0347b9
Processing BaseballController#show_team_cached (for 127.0.0.1 at 2008-09-22 15:33:31) [GET]
Session ID: BAh7BiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNo
SGFzaHsABjoKQHVzZWR7AA==--5e49bdf6639fdc26f216483d87894b99e8190efc
Parameters: {"action"=>"show_team_cached", "id"=>"1", "controller"=>"baseball"}
Fragment read: localhost:3000/baseball/show_team_cached/1 (0.00007)
Cached fragment hit: views/localhost:3001/baseball/show_team_cached/1 (0.00002)
Rendering baseball/show_team_cached
Fragment read: localhost:3000/baseball/show_team_cached/1 (0.00002)
Completed in 0.00263 (380 reqs/sec) | Rendering: 0.00074 (28%) | DB: 0.00000 (0%) | 200 OK [http://localhost/baseball/show_team_cached/1]
# codecite fragment
Cached fragment hit: views/localhost:3001/baseball/show_team_cached/1 (0.00001)
Completed in 0.00233 (429 reqs/sec) | Rendering: 0.00058 (24%) | DB: 0.00000 (0%) | 200 OK [http://localhost/baseball/show_team_cached/1]

# codecite query cache
Processing BaseballController#modify_team (for 127.0.0.1 at 2007-10-26 14:43:41) [GET]
Session ID: BAh7BiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNo%0ASGFzaHsABjoKQHVzZWR7AA%3D%3D--2f18f5b4601093f9163734981d5905979f0347b9
Processing BaseballController#modify_team (for 127.0.0.1 at 2008-09-22 15:48:32) [GET]
Session ID: BAh7BiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNo
SGFzaHsABjoKQHVzZWR7AA==--5e49bdf6639fdc26f216483d87894b99e8190efc
Parameters: {"action"=>"modify_team", "id"=>"1", "controller"=>"baseball"}
Team Columns (0.002146) SHOW FIELDS FROM teams
Team Load (0.000697) SELECT * FROM teams WHERE (teams.`id` = 1) 
CACHE (0.000000) SELECT * FROM teams WHERE (teams.`id` = 1) 
SQL (0.000119) BEGIN
Team Update (0.000275) UPDATE teams SET `created_at` = '2007-10-23 11:28:33', `city` = 'Boston', `updated_at` = '2007-10-26 14:43:41', `name` = 'New Name' WHERE `id` = 1
SQL (0.000337) COMMIT
Team Load (0.000262) SELECT * FROM teams WHERE (teams.`id` = 1) 
Rendering baseball/modify_team
Completed in 0.01346 (74 reqs/sec) | Rendering: 0.00101 (7%) | DB: 0.00384 (28%) | 200 OK [http://localhost/baseball/modify_team/1]
# codecite query cache
Team Columns (0.001319) SHOW FIELDS FROM `teams`
Team Load (0.000625) SELECT * FROM `teams` WHERE (`teams`.`id` = 1)
CACHE (0.000000) SELECT * FROM `teams` WHERE (`teams`.`id` = 1)
SQL (0.000076) BEGIN
Team Update (0.000194) UPDATE `teams` SET `updated_at` = '2008-09-22 19:48:32', `name` = '2008-09-22 15:48:32' WHERE `id` = 1
SQL (0.000542) COMMIT
Team Load (0.000146) SELECT * FROM `teams` WHERE (`teams`.`id` = 1)
Completed in 0.01017 (98 reqs/sec) | Rendering: 0.00021 (2%) | DB: 0.00290 (28%) | 200 OK [http://localhost/baseball/modify_team/1]
6 changes: 0 additions & 6 deletions rails_samples/spec/fixtures/contracts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,18 @@
# codecite totally random
<% (1..100).each do |i| %>
contract_<%= i %>:
id: <%= i %>
salary: <%= rand(5000000) %>
length: <%= rand(5) %>
player_id: <%= rand(200) %>
team_id: <%= rand(200) %>
created_at: <%= Time.now.iso8601 %>
updated_at: <%= Time.now.iso8601 %>
<% end %>
# codecite totally random
# codecite large teams
<% (101..200).each do |i| %>
contract_<%= i %>:
id: <%= i %>
salary: <%= rand(5000000) %>
length: <%= rand(5) %>
player_id: <%= rand(200) %>
team_id: <%= rand(2) + 1 %>
created_at: <%= Time.now.iso8601 %>
updated_at: <%= Time.now.iso8601 %>
<% end %>
# codecite large teams
17 changes: 9 additions & 8 deletions rails_samples/spec/fixtures/players.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
# codecite many
<% (1..200).each do |i| %>
player_<%= i %>:
id: <%= i %>
name: Player <%= i %>
position: Random
<% end %>
# codecite many

# codecite fixtures
manny:
name: Manny Ramirez
Expand All @@ -12,12 +21,4 @@ arod:
jeter:
name: Derek Jeter
position: Infield

# codecite fixtures
# codecite many
<% (5..200).each do |i| %>
player_<%= i %>:
name: Player <%= i %>
position: Random
<% end %>
# codecite many
18 changes: 9 additions & 9 deletions rails_samples/spec/fixtures/teams.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
# codecite many
<% (1..200).each do |i| %>
team_<%= i %>:
id: <%= i %>
name: Team <%= i %>
City: Random
<% end %>
# codecite many

# codecite fixtures
redsox:
name: Red Sox
city: Boston
yankees:
name: Yankees
city: New York

# codecite fixtures

# codecite many
<% (3..200).each do |i| %>
team_<%= i %>:
name: Team <%= i %>
City: Random
<% end %>
# codecite many
6 changes: 0 additions & 6 deletions rails_samples/test/fixtures/contracts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,18 @@
# codecite totally random
<% (1..100).each do |i| %>
contract_<%= i %>:
id: <%= i %>
salary: <%= rand(5000000) %>
length: <%= rand(5) %>
player_id: <%= rand(200) %>
team_id: <%= rand(200) %>
created_at: <%= Time.now.iso8601 %>
updated_at: <%= Time.now.iso8601 %>
<% end %>
# codecite totally random
# codecite large teams
<% (101..200).each do |i| %>
contract_<%= i %>:
id: <%= i %>
salary: <%= rand(5000000) %>
length: <%= rand(5) %>
player_id: <%= rand(200) %>
team_id: <%= rand(2) + 1 %>
created_at: <%= Time.now.iso8601 %>
updated_at: <%= Time.now.iso8601 %>
<% end %>
# codecite large teams
17 changes: 9 additions & 8 deletions rails_samples/test/fixtures/players.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
# codecite many
<% (1..200).each do |i| %>
player_<%= i %>:
id: <%= i %>
name: Player <%= i %>
position: Random
<% end %>
# codecite many

# codecite fixtures
manny:
name: Manny Ramirez
Expand All @@ -12,12 +21,4 @@ arod:
jeter:
name: Derek Jeter
position: Infield

# codecite fixtures
# codecite many
<% (5..200).each do |i| %>
player_<%= i %>:
name: Player <%= i %>
position: Random
<% end %>
# codecite many
18 changes: 9 additions & 9 deletions rails_samples/test/fixtures/teams.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
# codecite many
<% (1..200).each do |i| %>
team_<%= i %>:
id: <%= i %>
name: Team <%= i %>
City: Random
<% end %>
# codecite many

# codecite fixtures
redsox:
name: Red Sox
city: Boston
yankees:
name: Yankees
city: New York

# codecite fixtures

# codecite many
<% (3..200).each do |i| %>
team_<%= i %>:
name: Team <%= i %>
City: Random
<% end %>
# codecite many

0 comments on commit 2efece6

Please sign in to comment.