From d9349704c75389ee19ab6435ab321e6b0e4c4d30 Mon Sep 17 00:00:00 2001 From: evazion Date: Sat, 18 Feb 2017 05:44:57 -0600 Subject: [PATCH 1/2] dmails: add indexes on is_read and is_deleted (fix #2886). --- .../20170218104710_add_indexes_to_dmails.rb | 7 +++++++ db/structure.sql | 16 ++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 db/migrate/20170218104710_add_indexes_to_dmails.rb diff --git a/db/migrate/20170218104710_add_indexes_to_dmails.rb b/db/migrate/20170218104710_add_indexes_to_dmails.rb new file mode 100644 index 000000000..13028df8c --- /dev/null +++ b/db/migrate/20170218104710_add_indexes_to_dmails.rb @@ -0,0 +1,7 @@ +class AddIndexesToDmails < ActiveRecord::Migration + def change + execute "set statement_timeout = 0" + add_index :dmails, :is_read + add_index :dmails, :is_deleted + end +end diff --git a/db/structure.sql b/db/structure.sql index c3387c466..240c02f73 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -5084,6 +5084,20 @@ CREATE UNIQUE INDEX index_dmail_filters_on_user_id ON dmail_filters USING btree CREATE INDEX index_dmails_on_creator_ip_addr ON dmails USING btree (creator_ip_addr); +-- +-- Name: index_dmails_on_is_deleted; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_dmails_on_is_deleted ON dmails USING btree (is_deleted); + + +-- +-- Name: index_dmails_on_is_read; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_dmails_on_is_read ON dmails USING btree (is_read); + + -- -- Name: index_dmails_on_message_index; Type: INDEX; Schema: public; Owner: - -- @@ -7450,3 +7464,5 @@ INSERT INTO schema_migrations (version) VALUES ('20170112060921'); INSERT INTO schema_migrations (version) VALUES ('20170117233040'); +INSERT INTO schema_migrations (version) VALUES ('20170218104710'); + From abae71c0605eaa8b0fa0d828e49978559568a0c5 Mon Sep 17 00:00:00 2001 From: evazion Date: Sat, 18 Feb 2017 05:45:36 -0600 Subject: [PATCH 2/2] layouts/default.html.erb: optimize dmail notice sql. * CurrentUser.dmail_count caused an unnecessary COUNT(*). * CurrentUser.dmails.unread.present? caused *all* unread dmails to be loaded. We want to only load the first one. --- app/views/layouts/default.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/layouts/default.html.erb b/app/views/layouts/default.html.erb index 95fd2c3df..9ef528a5f 100644 --- a/app/views/layouts/default.html.erb +++ b/app/views/layouts/default.html.erb @@ -85,7 +85,7 @@ <%= render "users/ban_notice" %> <% end %> - <% if CurrentUser.dmail_count.present? && CurrentUser.dmails.unread.present? && cookies[:hide_dmail_notice].to_i != CurrentUser.dmails.unread.first.id %> + <% if CurrentUser.has_mail? && CurrentUser.dmails.unread.first.present? && cookies[:hide_dmail_notice].to_i != CurrentUser.dmails.unread.first.id %> <%= render "users/dmail_notice" %> <% end %>