perf: prevent an unneeded db/redis query for chat tool
test plan: * for courses that have the chat LTI tool enabled it should show up exactly as before * for courses that have no lti tools, profile a page load, * make sure you don't see anything like this in the logs: Redis (0.261ms) get active_external_tool_for/courses/6961-xyz/chat SQL ContextExternalTool Load (1.0ms) SELECT "context_external_tools"... Redis (0.253ms) get shard_7549:account_chain_ids/accounts/7549000... SQL ContextExternalTool Load (0.9ms) SELECT "context_external_tools"... Redis (0.295ms) set active_external_tool_for/courses/6961-xyz/chat Change-Id: Ia660a6f2eee6d08a3aabca9fa6643efd82b21040 Reviewed-on: https://gerrit.instructure.com/210798 Tested-by: Jenkins Reviewed-by: James Williams <jamesw@instructure.com> QA-Review: Ryan Shaw <ryan@instructure.com> Product-Review: Ryan Shaw <ryan@instructure.com>
This commit is contained in:
parent
8d1c0b5cd5
commit
08f9b7bd31
|
@ -352,8 +352,8 @@ module ApplicationHelper
|
|||
!@body_class_no_headers &&
|
||||
@current_user &&
|
||||
@context.is_a?(Course) &&
|
||||
embedded_chat_enabled &&
|
||||
external_tool_tab_visible('chat')
|
||||
external_tool_tab_visible('chat') &&
|
||||
embedded_chat_enabled
|
||||
end
|
||||
|
||||
def active_external_tool_by_id(tool_id)
|
||||
|
@ -379,9 +379,10 @@ module ApplicationHelper
|
|||
end
|
||||
|
||||
def external_tool_tab_visible(tool_id)
|
||||
return false unless available_section_tabs.any?{|tc| tc[:external]} # if the course has no external tool tabs, we know it won't have a chat one so we can bail early before querying the db/redis for it
|
||||
tool = active_external_tool_by_id(tool_id)
|
||||
return false unless tool
|
||||
@context.tabs_available(@current_user).find {|tc| tc[:id] == tool.asset_string}.present?
|
||||
available_section_tabs.find {|tc| tc[:id] == tool.asset_string}.present?
|
||||
end
|
||||
|
||||
def license_help_link
|
||||
|
|
|
@ -34,9 +34,9 @@ module SectionTabHelper
|
|||
:view_all_grades
|
||||
].freeze
|
||||
|
||||
def available_section_tabs(context, precalculated_permissions=nil)
|
||||
AvailableSectionTabs.new(
|
||||
context, @current_user, @domain_root_account, session, precalculated_permissions
|
||||
def available_section_tabs
|
||||
@available_section_tabs ||= AvailableSectionTabs.new(
|
||||
@context, @current_user, @domain_root_account, session
|
||||
).to_a
|
||||
end
|
||||
|
||||
|
@ -56,13 +56,13 @@ module SectionTabHelper
|
|||
|
||||
def section_tabs
|
||||
@section_tabs ||= begin
|
||||
if @context && available_section_tabs(@context).any?
|
||||
if @context && available_section_tabs.any?
|
||||
content_tag(:nav, {
|
||||
:role => 'navigation',
|
||||
:'aria-label' => nav_name
|
||||
}) do
|
||||
concat(content_tag(:ul, id: 'section-tabs') do
|
||||
available_section_tabs(@context).map do |tab|
|
||||
available_section_tabs.map do |tab|
|
||||
section_tab_tag(tab, @context, get_active_tab)
|
||||
end
|
||||
end)
|
||||
|
|
Loading…
Reference in New Issue