What generates the first ActiveAdmin COUNT query? - ruby-on-rails

The beginning of my ActiveAdmin rails log for a query looks like this:
Started GET "/things" for 127.0.0.1 at 2015-12-17 15:43:30 -0500
Processing by ThingsController#index as HTML
AdminUser Load (57.1ms) SELECT `admin_users`.* FROM `admin_users` WHERE `admin_users`.`id` = 1 ORDER BY `admin_users`.`id` ASC LIMIT 1
(58.1ms) SELECT COUNT(count_column) FROM (SELECT 1 AS count_column FROM `things` WHERE `things`.`retired_at` IS NULL AND `things`.`errored_at` IS NULL LIMIT 30 OFFSET 0) subquery_for_count
CACHE (0.0ms) SELECT COUNT(count_column) FROM (SELECT 1 AS count_column FROM `things` WHERE `things`.`retired_at` IS NULL AND `things`.`errored_at` IS NULL LIMIT 30 OFFSET 0) subquery_for_count
CACHE (0.0ms) SELECT COUNT(count_column) FROM (SELECT 1 AS count_column FROM `things` WHERE `things`.`retired_at` IS NULL AND `things`.`errored_at` IS NULL LIMIT 30 OFFSET 0) subquery_for_count
CACHE (0.0ms) SELECT COUNT(count_column) FROM (SELECT 1 AS count_column FROM `things` WHERE `things`.`retired_at` IS NULL AND `things`.`errored_at` IS NULL LIMIT 30 OFFSET 0) subquery_for_count
What are the mechanisms and files in ActiveAdmin or its dependencies that are generating the 58.1ms SELECT COUNT ... subquery_for_count?

You can refer the following URL: documentation
That count query can be reduced with following:
index pagination_total: false do
# ...
end
Hope this helps you.

Related

Rails ActiveRecord includes syntax for multiple parent/ child

The way my models are set up:
an Order object has many RentalItems & TypeLogistics
RentalItem & TypeLogistic objects each has many ChargedAmounts & Refunds
further, the Order object itself has many ChargedAmounts & Refunds
The following queries appear to be working correctly, for when I want to eager load the stated associations for the 19th Order object in db:
# Load order, and its charged_amounts & refunds
#order = Order.includes(:charged_amounts, :refunds).find(19)
=>
Order Load (0.2ms) SELECT "orders".* FROM "orders" WHERE "orders"."id" = ? LIMIT 1 [["id", 19]]
ChargedAmount Load (0.3ms) SELECT "charged_amounts".* FROM "charged_amounts" WHERE "charged_amounts"."order_id" IN (19)
Refund Load (0.3ms) SELECT "refunds".* FROM "refunds" WHERE "refunds"."order_id" IN (19)
# Load order, its type_logistics, and the charged_amounts & refunds that belong to each type_logistic
#order = Order.includes(type_logistics:[:charged_amounts, :refunds]).find(19)
=>
Order Load (0.1ms) SELECT "orders".* FROM "orders" WHERE "orders"."id" = ? LIMIT 1 [["id", 19]]
TypeLogistic Load (1.1ms) SELECT "type_logistics".* FROM "type_logistics" WHERE "type_logistics"."order_id" IN (19)
ChargedAmount Load (0.3ms) SELECT "charged_amounts".* FROM "charged_amounts" WHERE "charged_amounts"."type_logistic_id" IN (26)
Refund Load (0.2ms) SELECT "refunds".* FROM "refunds" WHERE "refunds"."type_logistic_id" IN (26)
# Load order, its rental_items, and the charged_amounts & refunds that belong to each rental_item
#order = Order.includes(rental_items: [:charged_amounts, :refunds]).find(19)
=>
Order Load (0.3ms) SELECT "orders".* FROM "orders" WHERE "orders"."id" = ? LIMIT 1 [["id", 19]]
RentalItem Load (0.2ms) SELECT "rental_items".* FROM "rental_items" WHERE "rental_items"."order_id" IN (19)
ChargedAmount Load (0.2ms) SELECT "charged_amounts".* FROM "charged_amounts" WHERE "charged_amounts"."rental_item_id" IN (27, 28)
Refund Load (0.1ms) SELECT "refunds".* FROM "refunds" WHERE "refunds"."rental_item_id" IN (27, 28)
But the challenge is that I want to eager load ALL of it: the order's charged_amounts and refunds, and all of its rental_items and type_logistics and the charged_amounts and refunds for each rental_item and type_logistic.
But when I string the query together, it looks like the second set of associations (type_logistics and its charged_amounts and refunds) aren't loading at all based on the queries.
#order = Order.includes(:charged_amounts, :refunds, rental_items: [:charged_amounts, :refunds], type_logistics:[:charged_amounts, :refunds]).find(19)
=>
Order Load (0.2ms) SELECT "orders".* FROM "orders" WHERE "orders"."id" = ? LIMIT 1 [["id", 19]]
ChargedAmount Load (0.2ms) SELECT "charged_amounts".* FROM "charged_amounts" WHERE "charged_amounts"."order_id" IN (19)
Refund Load (0.2ms) SELECT "refunds".* FROM "refunds" WHERE "refunds"."order_id" IN (19)
RentalItem Load (0.2ms) SELECT "rental_items".* FROM "rental_items" WHERE "rental_items"."order_id" IN (19)
ChargedAmount Load (0.1ms) SELECT "charged_amounts".* FROM "charged_amounts" WHERE "charged_amounts"."rental_item_id" IN (27, 28)
Refund Load (0.1ms) SELECT "refunds".* FROM "refunds" WHERE "refunds"."rental_item_id" IN (27, 28)
But the charged_amounts and refunds on the order don't have any other associations, so they're not the "key" for anything. Any assistance here?
An approach I have followed in previous projects is:
Order.eager_load(:charged_amounts, :refunds)
.eager_load(rental_items: [:charged_amounts, :refunds])
.eager_load(type_logistics: [:charged_amounts, :refunds] )
.find(19)
I don't know if this may be the solution. Also note that I'm using the AR.eager_load method. Feel free to swap that for AR.includes

Rails 4 - Why does using includes() not make a join between Pins and Replies?

I'm a Rails and Ruby newcomer. I want to optimise SQL queries where I can and I was reading about using includes() to make Rails aware, that I want to eager load and join two tables.
In my show action on the pin controller:
def show
#pin = Pin.includes(:replies, :user).where(id: params[:id]).first
end
If I check the log on the queries, I see the following:
Started GET "/pin/1703704382" for 127.0.0.1 at 2014-06-12 15:30:18 +0100
Processing by PinsController#show as HTML
Parameters: {"id"=>"1703704382"}
Pin Load (0.2ms) SELECT `pins`.* FROM `pins` WHERE `pins`.`id` = 145 ORDER BY `pins`.`id` ASC LIMIT 1
Reply Load (0.1ms) SELECT `replies`.* FROM `replies` WHERE `replies`.`pin_id` IN (145)
User Load (0.1ms) SELECT `users`.* FROM `users` WHERE `users`.`id` IN (22)
User Load (0.1ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 22 LIMIT 1
Profile Load (0.1ms) SELECT `profiles`.* FROM `profiles` WHERE `profiles`.`user_id` = 22 ORDER BY `profiles`.`id` ASC LIMIT 1
CACHE (0.0ms) SELECT `profiles`.* FROM `profiles` WHERE `profiles`.`user_id` = 22 ORDER BY `profiles`.`id` ASC LIMIT 1 [["user_id", 22]]
Type Load (0.1ms) SELECT `types`.* FROM `types` WHERE `types`.`id` = 1 ORDER BY `types`.`id` ASC LIMIT 1
Skill Load (0.1ms) SELECT `skills`.* FROM `skills` WHERE `skills`.`id` = 3 ORDER BY `skills`.`id` ASC LIMIT 1
Instrument Load (0.2ms) SELECT `instruments`.* FROM `instruments` WHERE `instruments`.`id` = 6 ORDER BY `instruments`.`id` ASC LIMIT 1
Genre Load (0.1ms) SELECT `genres`.* FROM `genres` INNER JOIN `genre_pins` ON `genres`.`id` = `genre_pins`.`genre_id` WHERE `genre_pins`.`pin_id` = 145
Bookmark Load (0.1ms) SELECT `bookmarks`.* FROM `bookmarks` WHERE `bookmarks`.`pin_id` = 145
User Load (0.1ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 22 ORDER BY `users`.`id` ASC LIMIT 1
(0.2ms) SELECT COUNT(*) FROM `bookmarks` WHERE `bookmarks`.`pin_id` = 145
(0.1ms) SELECT COUNT(*) FROM `replies` WHERE `replies`.`pin_id` = 145
Rendered partials/_pin.html.erb (14.3ms)
Pin Load (0.1ms) SELECT `pins`.* FROM `pins` WHERE `pins`.`id` = 145 ORDER BY `pins`.`id` ASC LIMIT 1
CACHE (0.0ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 22 ORDER BY `users`.`id` ASC LIMIT 1 [["id", 22]]
CACHE (0.0ms) SELECT `profiles`.* FROM `profiles` WHERE `profiles`.`user_id` = 22 ORDER BY `profiles`.`id` ASC LIMIT 1 [["user_id", 22]]
Rendered replies/_reply.html.erb (4.0ms)
Rendered replies/_form.html.erb (1.5ms)
Rendered pins/show.html.erb within layouts/application (21.7ms)
Rendered partials/_meta.html.erb (0.1ms)
Rendered partials/_top.html.erb (1.3ms)
Rendered partials/_tags.html.erb (0.1ms)
Rendered partials/_search.html.erb (1.0ms)
Completed 200 OK in 33ms (Views: 27.2ms | ActiveRecord: 2.0ms | Solr: 0.0ms)
It seems like it is running separate queries to get pins, replies and the user. How can I join these into one query? Surely this could be better optimised.
Thanks for your advice and patience!
It seems like it is running separate queries to get pins, replies and the user. How can I join these into one query? Surely this could be better optimised.
This is not automatically true. Hydration (the fact of creating nested records, etc, since you don't get in a hierarchical structure from your DB) can be very costly with many relations. It's actually often times better for your performance to use only a very simple query to fetch every record of one table.
If you still want to join (with shallow relations, it's probably better), you can use .joins

I killed my projects BD, but I need it for tomorow

I finished few minutes ago my project. I made a commit, after this I wanted to clear DB because there was many testing records. So I ran this in my DBconsole:
sqlite> delete from users where id;
sqlite> delete from users where id=1;
sqlite> delete from posts where id=1;
sqlite> delete from votes where id=1;
After this my project didn't work(((. It returns:
We're sorry, but something went wrong.
If you are the application owner check the logs for more information.
On every page, even statics!!!!
I need my project to tomorrow. I restored from Git, but error is not disappeared.
My logs see like this:
Started GET "/" for 127.0.0.1 at 2014-03-14 04:08:40 +0200
Processing by PostsController#index as HTML
(0.4ms) SELECT COUNT(*) FROM "posts" WHERE "posts"."statut" = 1
(0.3ms) SELECT COUNT(*) FROM "posts" WHERE "posts"."statut" = 2
(0.4ms) SELECT COUNT(*) FROM "posts" WHERE ("posts"."statut" BETWEEN 3 AND 4)
Post Load (0.7ms) SELECT "posts".* FROM "posts" WHERE "posts"."statut" = 1 ORDER BY created_at DESC LIMIT 10
Post Load (0.6ms) SELECT "posts".* FROM "posts" WHERE "posts"."statut" = 2 ORDER BY created_at DESC LIMIT 10
Post Load (0.5ms) SELECT "posts".* FROM "posts" WHERE ("posts"."statut" BETWEEN 3 AND 4) ORDER BY created_at DESC LIMIT 10
Rendered posts/index.html.erb within layouts/application (23.5ms)
CACHE (0.0ms) SELECT COUNT(*) FROM "posts" WHERE "posts"."statut" = 1
CACHE (0.0ms) SELECT COUNT(*) FROM "posts" WHERE "posts"."statut" = 2
CACHE (0.0ms) SELECT COUNT(*) FROM "posts" WHERE ("posts"."statut" BETWEEN 3 AND 4)
CACHE (0.0ms) SELECT COUNT(*) FROM "posts" WHERE "posts"."statut" = 1
CACHE (0.0ms) SELECT COUNT(*) FROM "posts" WHERE "posts"."statut" = 2
CACHE (0.0ms) SELECT COUNT(*) FROM "posts" WHERE ("posts"."statut" BETWEEN 3 AND 4)
CACHE (0.0ms) SELECT COUNT(*) FROM "posts" WHERE "posts"."statut" = 1
CACHE (0.0ms) SELECT COUNT(*) FROM "posts" WHERE "posts"."statut" = 2
CACHE (0.0ms) SELECT COUNT(*) FROM "posts" WHERE ("posts"."statut" BETWEEN 3 AND 4)
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 8]]
Completed 500 Internal Server Error in 74ms
This is for main page. Help me!! I can give u a git, I need to repair it, please.
You deleted all your users with this statement.
delete from users where id;
So the line in the log
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 8]]
Won't be able to load user with id 8 because the table is empty. Maybe you need to add back a user crucial for your program to function.

spree 0.70.3 rails 3.1.3 issue with taxonomy

running spree 0.70.3 on rails 3.1.3
I create through the admin a new taxonomy tree, and then i add a taxon on a product.
The new taxon does it indeed show on the sidebar however when try to access i get 404 doesnt exist.
Started GET "/t/organa-metrisis/mikrometra" for 127.0.0.1 at 2011-11-28 22:44:33 +0200
Property Load (0.2ms) SELECT "properties".* FROM "properties" WHERE "properties"."name" = 'brand' LIMIT 1
Processing by TaxonsController#show as HTML
Parameters: {"id"=>"organa-metrisis/mikrometra"}
AppConfiguration Load (0.3ms) SELECT "configurations".* FROM "configurations" WHERE "configurations"."type" IN ('AppConfiguration') AND "configurations"."name" = 'Default configuration' LIMIT 1
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
Taxon Load (0.3ms) SELECT "taxons".* FROM "taxons" WHERE "taxons"."permalink" = 'organa-metrisis/mikrometra' LIMIT 1
Rendered public/404.html (116.9ms)
Completed 404 Not Found in 364ms (Views: 217.9ms | ActiveRecord: 2.3ms)
I'm currently running the same environment and rails, but my output is different, and works fine. I recommend re-creating your Taxonomy, and then re-assigning your Taxons on the product. It's possible that there's something wrong with your _taxonomies.html.erb view in "views/shared".
Here's my sample output (with 4 Taxons at the top level, and 8 Taxons at the 2nd level of one Taxon):
Started GET "/t/cards/congratulations" for 127.0.0.1 at 2011-12-18 22:11:26 -0500
Property Load (0.1ms) SELECT "properties".* FROM "properties" WHERE "properties"."name" = 'brand' LIMIT 1
Processing by TaxonsController#show as HTML
Parameters: {"id"=>"cards/congratulations"}
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
Taxon Load (0.4ms) SELECT "taxons".* FROM "taxons" WHERE "taxons"."permalink" = 'cards/congratulations' LIMIT 1
Taxon Load (0.3ms) SELECT "taxons".* FROM "taxons" WHERE "taxons"."id" = ? LIMIT 1 [["id", 8]]
Taxon Load (0.3ms) SELECT "taxons".* FROM "taxons" WHERE ("taxons"."lft" >= 8 AND "taxons"."rgt" <= 9) ORDER BY "taxons"."lft"
Taxonomy Load (0.2ms) SELECT "taxonomies".* FROM "taxonomies" INNER JOIN "taxons" ON "taxons"."taxonomy_id" = "taxonomies"."id" AND "taxons"."parent_id" IS NULL
Taxon Load (0.3ms) SELECT "taxons".* FROM "taxons" WHERE "taxons"."taxonomy_id" IN (1, 2, 3, 4) AND ("taxons"."parent_id" IS NULL)
Taxon Load (0.4ms) SELECT "taxons".* FROM "taxons" WHERE "taxons"."parent_id" IN (1, 2, 3, 4) ORDER BY "lft"
Taxon Load (0.4ms) SELECT "taxons".* FROM "taxons" WHERE ("taxons"."lft" <= 8 AND "taxons"."rgt" >= 9) ORDER BY "taxons"."lft"
CACHE (0.0ms) SELECT "taxons".* FROM "taxons" WHERE ("taxons"."lft" <= 8 AND "taxons"."rgt" >= 9) ORDER BY "taxons"."lft"
CACHE (0.0ms) SELECT "taxons".* FROM "taxons" WHERE ("taxons"."lft" <= 8 AND "taxons"."rgt" >= 9) ORDER BY "taxons"."lft"
CACHE (0.0ms) SELECT "taxons".* FROM "taxons" WHERE ("taxons"."lft" <= 8 AND "taxons"."rgt" >= 9) ORDER BY "taxons"."lft"
CACHE (0.0ms) SELECT "taxons".* FROM "taxons" WHERE ("taxons"."lft" <= 8 AND "taxons"."rgt" >= 9) ORDER BY "taxons"."lft"
CACHE (0.0ms) SELECT "taxons".* FROM "taxons" WHERE ("taxons"."lft" <= 8 AND "taxons"."rgt" >= 9) ORDER BY "taxons"."lft"
CACHE (0.0ms) SELECT "taxons".* FROM "taxons" WHERE ("taxons"."lft" <= 8 AND "taxons"."rgt" >= 9) ORDER BY "taxons"."lft"
CACHE (0.0ms) SELECT "taxons".* FROM "taxons" WHERE ("taxons"."lft" <= 8 AND "taxons"."rgt" >= 9) ORDER BY "taxons"."lft"
CACHE (0.0ms) SELECT "taxons".* FROM "taxons" WHERE ("taxons"."lft" <= 8 AND "taxons"."rgt" >= 9) ORDER BY "taxons"."lft"
Rendered spree_dodatest_theme/app/views/shared/_taxonomies.html.erb (140.1ms)
... (it goes on)

Is there a way to identify why the database ROLLSBACK in a Rails application?

I'm trying to update a model object, and it keeps rolling back. Occassionaly protesting that it is a validation error. But it doesn't point to what is actually failing.
In the end, I tried to delete it, but in the deletion, it still fails validation.
Is there a way to debug this and find out exactly why/what is causing this?
Thanks
A typical response to an update or delete:
ActiveRecord::RecordNotSaved: ActiveRecord::RecordNotSaved
from /data/HQ_Channel2/releases/20111011173855/vendor/rails/activerecord/lib/active_record/base.rb:2551:in `save_without_validation!'
from /data/HQ_Channel2/releases/20111011173855/vendor/rails/activerecord/lib/active_record/validations.rb:1019:in `save_without_dirty!'
from /data/HQ_Channel2/releases/20111011173855/vendor/rails/activerecord/lib/active_record/dirty.rb:87:in `save_without_transactions!'
from /data/HQ_Channel2/releases/20111011173855/vendor/rails/activerecord/lib/active_record/transactions.rb:200:in `save!'
from /data/HQ_Channel2/releases/20111011173855/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:136:in `transaction'
And for more evidence, this is the stack from the appication when I try to create a new object:
Processing OrganizationsController#create (for 127.0.0.1 at 2011-10-12 15:43:02) [POST]
Parameters: {"commit"=>"submit", "action"=>"create", "authenticity_token"=>"QxTT80hdtULmkt7PeUH5MG+BZ/5l+a22ry3EL49q1V8=", "controller"=>"organizations", "organization"=>{"city"=>"lkjlkj", "name"=>"asdfa", "contact_24"=>"1", "zip"=>"123123", "quick_description"=>"2342, 123, 3,2423, 2", "url"=>"www.martini494bistro.com/", "hq_url"=>"12341234", "map_it"=>"1", "street"=>"lkjlkj", "phone_work"=>"123123123123", "is_authorized"=>"1", "state"=>"NJ"}}
User Columns (2.2ms) SHOW FIELDS FROM `users`
User Load (4.4ms) SELECT * FROM `users` WHERE (`users`.`persistence_token` = '77ca6dea2961c5102be62d8e995e3f4bfdcb5bcfdf64a4e8361d2f3b49e9b377e6467d1a01a3fbe7fc6dab76382220b044d3782f6045130a2de047d8b8f0bd87') LIMIT 1
SQL (0.1ms) BEGIN
User Update (0.3ms) UPDATE `users` SET `updated_at` = '2011-10-12 19:43:02', `perishable_token` = 'YP8Ivses9OgR6LtrNBvF', `last_request_at` = '2011-10-12 19:43:02' WHERE `id` = 2953
Solr Update (7.0ms) <?xml version="1.0" encoding="UTF-8"?><add><doc><field name="type">User</field><field name="type">ActiveRecord::Base</field><field name="id">User 2953</field><field name="email_s">asdfasdf#asdfasdf.com</field><field name="name_s">asdfadsf adfasdf</field><field name="first_name_s">asdfadsf</field><field name="created_at_d">2011-10-12T19:39:36Z</field><field name="class_name">User</field><field name="last_name_s">adfasdf</field><field name="name_text">asdfadsf adfasdf</field><field name="email_text">asdfasdf#asdfasdf.com</field><field name="last_name_text">adfasdf</field><field name="first_name_text">asdfadsf</field></doc></add>
SQL (0.6ms) COMMIT
SQL (1.1ms) SHOW TABLES
Organization Columns (5.4ms) SHOW FIELDS FROM `organizations`
Organization Load (2.9ms) SELECT `organizations`.* FROM `organizations` INNER JOIN `organizations_users` ON `organizations`.id = `organizations_users`.organization_id WHERE ((`organizations_users`.user_id = 2953))
SQL (0.1ms) BEGIN
Organization Load (1.1ms) SELECT `organizations`.id FROM `organizations` WHERE (LOWER(`organizations`.`name`) = BINARY 'asdfa') LIMIT 1
Organization Load (2.2ms) SELECT `organizations`.id FROM `organizations` WHERE (LOWER(`organizations`.`hq_url`) = BINARY '12341234') LIMIT 1
QuickFact Columns (1.3ms) SHOW FIELDS FROM `quick_facts`
SQL (2.2ms) SELECT count(*) AS count_all FROM `quick_facts` WHERE (`quick_facts`.organization_id = NULL)
CACHE (0.0ms) SELECT count(*) AS count_all FROM `quick_facts` WHERE (`quick_facts`.organization_id = NULL)
CACHE (0.0ms) SELECT count(*) AS count_all FROM `quick_facts` WHERE (`quick_facts`.organization_id = NULL)
SQL (0.1ms) ROLLBACK
SQL (3.1ms) BEGIN
CACHE (0.0ms) SELECT `organizations`.id FROM `organizations` WHERE (LOWER(`organizations`.`name`) = BINARY 'asdfa') LIMIT 1
CACHE (0.0ms) SELECT `organizations`.id FROM `organizations` WHERE (LOWER(`organizations`.`hq_url`) = BINARY '12341234') LIMIT 1
CACHE (0.0ms) SELECT count(*) AS count_all FROM `quick_facts` WHERE (`quick_facts`.organization_id = NULL)
CACHE (0.0ms) SELECT count(*) AS count_all FROM `quick_facts` WHERE (`quick_facts`.organization_id = NULL)
CACHE (0.0ms) SELECT count(*) AS count_all FROM `quick_facts` WHERE (`quick_facts`.organization_id = NULL)
SQL (0.1ms) ROLLBACK
CACHE (0.0ms) SELECT `organizations`.id FROM `organizations` WHERE (LOWER(`organizations`.`name`) = BINARY 'asdfa') LIMIT 1
CACHE (0.0ms) SELECT `organizations`.id FROM `organizations` WHERE (LOWER(`organizations`.`hq_url`) = BINARY '12341234') LIMIT 1
SQL (0.1ms) BEGIN
CACHE (0.0ms) SELECT `organizations`.id FROM `organizations` WHERE (LOWER(`organizations`.`name`) = BINARY 'asdfa') LIMIT 1
CACHE (0.0ms) SELECT `organizations`.id FROM `organizations` WHERE (LOWER(`organizations`.`hq_url`) = BINARY '12341234') LIMIT 1
CACHE (0.0ms) SELECT count(*) AS count_all FROM `quick_facts` WHERE (`quick_facts`.organization_id = NULL)
CACHE (0.0ms) SELECT count(*) AS count_all FROM `quick_facts` WHERE (`quick_facts`.organization_id = NULL)
CACHE (0.0ms) SELECT count(*) AS count_all FROM `quick_facts` WHERE (`quick_facts`.organization_id = NULL)
SQL (0.1ms) ROLLBACK
SQL (0.1ms) BEGIN
CACHE (0.0ms) SELECT `organizations`.id FROM `organizations` WHERE (LOWER(`organizations`.`name`) = BINARY 'asdfa') LIMIT 1
CACHE (0.0ms) SELECT `organizations`.id FROM `organizations` WHERE (LOWER(`organizations`.`hq_url`) = BINARY '12341234') LIMIT 1
CACHE (0.0ms) SELECT count(*) AS count_all FROM `quick_facts` WHERE (`quick_facts`.organization_id = NULL)
CACHE (0.0ms) SELECT count(*) AS count_all FROM `quick_facts` WHERE (`quick_facts`.organization_id = NULL)
CACHE (0.0ms) SELECT count(*) AS count_all FROM `quick_facts` WHERE (`quick_facts`.organization_id = NULL)
SQL (0.1ms) ROLLBACK
Rendering template within layouts/application
Rendering organizations/new
Rendered organizations/_form (4.2ms)
Rendered layouts/_head (2.7ms)
SQL (0.7ms) SELECT count(*) AS count_all FROM `organizations` INNER JOIN `organizations_users` ON `organizations`.id = `organizations_users`.organization_id WHERE ((`organizations_users`.user_id = 2953))
Rendered layouts/_login_status_new (2.1ms)
Rendered layouts/_header_new (2.9ms)
Rendered layouts/_need_login (0.2ms)
Rendered layouts/_already_have_tooltip (0.1ms)
Completed in 227923ms (View: 34, DB: 29) | 200 OK [http://localhost/organizations]
SQL (0.1ms) SET NAMES 'utf8'
SQL (0.1ms) SET NAMES 'utf8'
SQL (0.1ms) SET SQL_AUTO_IS_NULL=0
Processing DynamicStylesheetsController#image_css to css (for 127.0.0.1 at 2011-10-12 15:46:50) [GET]
Parameters: {"format"=>"css", "action"=>"image_css", "controller"=>"dynamic_stylesheets"}
At a guess, these lines:
SQL (2.2ms) SELECT count(*) AS count_all FROM `quick_facts` WHERE (`quick_facts`.organization_id = NULL)
CACHE (0.0ms) SELECT count(*) AS count_all FROM `quick_facts` WHERE (`quick_facts`.organization_id = NULL)
CACHE (0.0ms) SELECT count(*) AS count_all FROM `quick_facts` WHERE (`quick_facts`.organization_id = NULL)
SQL (0.1ms) ROLLBACK
.. mean that you have a uniqueness validation that's failing because the null value is "taken".

Resources