aboutsummaryrefslogtreecommitdiffstats
path: root/lib/attachment_to_html/attachment_to_html.rb
diff options
context:
space:
mode:
authorGareth Rees <gareth@mysociety.org>2015-04-21 15:01:32 +0100
committerGareth Rees <gareth@mysociety.org>2015-04-27 16:17:11 +0100
commit578a658bd1988ec23bfb5f3c2cc173bab20d76ba (patch)
tree33ee86acf88e7136a881714ba7e4cb0b9d79a337 /lib/attachment_to_html/attachment_to_html.rb
parent5cbf0836c049d5b9039fefb64a39e81aa8eb6b5e (diff)
Improve performance initializing OutgoingMessage
Reduces the amount of queries to associated objects by directly checking the database before setting the default body content. Before > info_request.outgoing_messages OutgoingMessage Load (0.4ms) SELECT "outgoing_messages".* FROM "outgoing_messages" WHERE "outgoing_messages"."info_request_id" = 137 ORDER BY created_at InfoRequest Load (0.5ms) SELECT "info_requests".* FROM "info_requests" WHERE "info_requests"."id" = 137 LIMIT 1 PublicBody Load (0.5ms) SELECT "public_bodies".* FROM "public_bodies" WHERE "public_bodies"."id" = 16 LIMIT 1 HasTagString::HasTagStringTag Load (0.4ms) SELECT "has_tag_string_tags".* FROM "has_tag_string_tags" WHERE "has_tag_string_tags"."model_id" = 16 AND (model = 'PublicBody') CensorRule Load (0.4ms) SELECT "censor_rules".* FROM "censor_rules" WHERE "censor_rules"."info_request_id" IS NULL AND "censor_rules"."public_body_id" IS NULL AND "censor_rules"."user_id" IS NULL User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."id" = 13 LIMIT 1 (0.5ms) SELECT COUNT(*) FROM "censor_rules" WHERE "censor_rules"."user_id" = 13 CensorRule Load (0.5ms) SELECT "censor_rules".* FROM "censor_rules" WHERE "censor_rules"."info_request_id" = 137 ORDER BY created_at desc CensorRule Load (0.5ms) SELECT "censor_rules".* FROM "censor_rules" WHERE "censor_rules"."public_body_id" = 16 ORDER BY created_at desc InfoRequest Load (0.5ms) SELECT "info_requests".* FROM "info_requests" WHERE "info_requests"."id" = 137 LIMIT 1 PublicBody Load (0.5ms) SELECT "public_bodies".* FROM "public_bodies" WHERE "public_bodies"."id" = 16 LIMIT 1 HasTagString::HasTagStringTag Load (0.6ms) SELECT "has_tag_string_tags".* FROM "has_tag_string_tags" WHERE "has_tag_string_tags"."model_id" = 16 AND (model = 'PublicBody') CensorRule Load (0.5ms) SELECT "censor_rules".* FROM "censor_rules" WHERE "censor_rules"."info_request_id" IS NULL AND "censor_rules"."public_body_id" IS NULL AND "censor_rules"."user_id" IS NULL User Load (0.6ms) SELECT "users".* FROM "users" WHERE "users"."id" = 13 LIMIT 1 (0.5ms) SELECT COUNT(*) FROM "censor_rules" WHERE "censor_rules"."user_id" = 13 CensorRule Load (0.4ms) SELECT "censor_rules".* FROM "censor_rules" WHERE "censor_rules"."info_request_id" = 137 ORDER BY created_at desc CensorRule Load (0.5ms) SELECT "censor_rules".* FROM "censor_rules" WHERE "censor_rules"."public_body_id" = 16 ORDER BY created_at desc => [#<OutgoingMessage id: 36, info_request_id: 137, body: "Some information please", status: "sent", message_type: "initial_request", created_at: "2015-04-17 10:50:21", updated_at: "2015-04-17 10:50:21", last_sent_at: "2015-04-17 10:50:21", incoming_message_followup_id: nil, what_doing: "normal_sort", prominence: "normal", prominence_reason: nil>, #<OutgoingMessage id: 37, info_request_id: 137, body: "Dear Example Public Body 6,\r\n\r\nc'mooooooonnnnnn\r\n\r\n...", status: "sent", message_type: "followup", created_at: "2015-04-20 12:18:30", updated_at: "2015-04-20 12:18:30", last_sent_at: "2015-04-20 12:18:30", incoming_message_followup_id: 30, what_doing: "normal_sort", prominence: "normal", prominence_reason: nil>] After > info_request.outgoing_messages OutgoingMessage Load (0.8ms) SELECT "outgoing_messages".* FROM "outgoing_messages" WHERE "outgoing_messages"."info_request_id" = 137 ORDER BY created_at => [#<OutgoingMessage id: 36, info_request_id: 137, body: "Some information please", status: "sent", message_type: "initial_request", created_at: "2015-04-17 10:50:21", updated_at: "2015-04-17 10:50:21", last_sent_at: "2015-04-17 10:50:21", incoming_message_followup_id: nil, what_doing: "normal_sort", prominence: "normal", prominence_reason: nil>, #<OutgoingMessage id: 37, info_request_id: 137, body: "Dear Example Public Body 6,\r\n\r\nc'mooooooonnnnnn\r\n\r\n...", status: "sent", message_type: "followup", created_at: "2015-04-20 12:18:30", updated_at: "2015-04-20 12:18:30", last_sent_at: "2015-04-20 12:18:30", incoming_message_followup_id: 30, what_doing: "normal_sort", prominence: "normal", prominence_reason: nil>]
Diffstat (limited to 'lib/attachment_to_html/attachment_to_html.rb')
0 files changed, 0 insertions, 0 deletions