<commit_before># Helper to keep exception handling DRY
def find_course(id)
  Course.find(id).present?
rescue ActiveRecord::RecordNotFound
  redirect '/dashboard/courses', error: 'El curso no existe.'
end

before %r{\/dashboard\/courses\/(\d)\/(delete|edit)} do |id, _|
  find_course(id)
end

get '/dashboard/courses' do
  set_page_title('Cursos')
  @courses = Course.all
  @course_types = CourseType.all
  erb :courses, layout: :'layouts/dashboard'<commit_msg>Removed N+1 queries on Courses view<commit_after># Helper to keep exception handling DRY
def find_course(id)
  Course.find(id).present?
rescue ActiveRecord::RecordNotFound
  redirect '/dashboard/courses', error: 'El curso no existe.'
end

before %r{\/dashboard\/courses\/(\d)\/(delete|edit)} do |id, _|
  find_course(id)
end

get '/dashboard/courses' do
  set_page_title('Cursos')
  @courses = Course.all.includes(:course_type, :office)
  @course_types = CourseType.all
  erb :courses, layout: :'layouts/dashboard'
{'fraction_non_alphanumeric': 0.1406570841889117, 'fraction_numerical': 0.001026694045174538, 'mean_word_length': 5.170886075949367, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '303555', 'n_tokens_mistral': 337, 'n_tokens_neox': 343, 'n_words': 81}