diff --git a/app/models/wiki_page.rb b/app/models/wiki_page.rb index 4d684f84f40..2deba7e45de 100644 --- a/app/models/wiki_page.rb +++ b/app/models/wiki_page.rb @@ -81,8 +81,7 @@ class WikiPage < ActiveRecord::Base end scope :visible_to_user, -> (user_id) do - joins(sanitize_sql(["LEFT JOIN #{AssignmentStudentVisibility.quoted_table_name} as asv on wiki_pages.assignment_id = asv.assignment_id AND asv.user_id = ?", user_id])). - where("wiki_pages.assignment_id IS NULL OR asv IS NOT NULL") + where("wiki_pages.assignment_id IS NULL OR EXISTS (SELECT 1 FROM #{AssignmentStudentVisibility.quoted_table_name} asv WHERE wiki_pages.assignment_id = asv.assignment_id AND asv.user_id = ?)", user_id) end TITLE_LENGTH = 255 diff --git a/db/migrate/20200831150747_add_index_on_wiki_pages_for_planner.rb b/db/migrate/20200831150747_add_index_on_wiki_pages_for_planner.rb new file mode 100644 index 00000000000..b19bd143b65 --- /dev/null +++ b/db/migrate/20200831150747_add_index_on_wiki_pages_for_planner.rb @@ -0,0 +1,26 @@ +# +# Copyright (C) 2020 - present Instructure, Inc. +# +# This file is part of Canvas. +# +# Canvas is free software: you can redistribute it and/or modify it under +# the terms of the GNU Affero General Public License as published by the Free +# Software Foundation, version 3 of the License. +# +# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more +# details. +# +# You should have received a copy of the GNU Affero General Public License along +# with this program. If not, see . + +class AddIndexOnWikiPagesForPlanner < ActiveRecord::Migration[5.2] + tag :predeploy + disable_ddl_transaction! + + def change + add_index :wiki_pages, [:wiki_id, :todo_date], where: "todo_date IS NOT NULL", + algorithm: :concurrently, if_not_exists: true + end +end