optimize planner wiki page query

it's far more common for wiki pages to not be linked to wiki pages, so only look up their
assignment visibilities if necessary

Change-Id: Idf3f05e2c5e59a2163bd692497160c2388551be2
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/246533
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Reviewed-by: James Williams <jamesw@instructure.com>
QA-Review: Cody Cutrer <cody@instructure.com>
Product-Review: Cody Cutrer <cody@instructure.com>
This commit is contained in:
Cody Cutrer 2020-08-31 09:12:16 -06:00
parent a1293ff960
commit bedf970aab
2 changed files with 27 additions and 2 deletions

View File

@ -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

View File

@ -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 <http://www.gnu.org/licenses/>.
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