From 81ab5fb4e0e63258dac9f15667080b437f2def25 Mon Sep 17 00:00:00 2001 From: b0ink <40929320+b0ink@users.noreply.github.com> Date: Tue, 3 Mar 2026 08:41:51 +1100 Subject: [PATCH 1/4] refactor: query moderated tasks instead of checking all student tasks --- app/models/unit.rb | 54 +++++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/app/models/unit.rb b/app/models/unit.rb index c7fa82766..f768ac11d 100644 --- a/app/models/unit.rb +++ b/app/models/unit.rb @@ -2203,32 +2203,36 @@ def tasks_for_moderation(user) my_unit_role = unit_role_for(user) mentees = my_unit_role ? staff.where(mentor_id: my_unit_role.id) : staff.none - tasks = student_tasks - .includes(:comments) - .left_joins(:moderated_task) - .where(moderated_tasks: { state: %i[open waiting_for_new_feedback] }) - .where(projects: { unit_id: id }) - .joins(:task_definition) - .joins(project: { tutorial_enrolments: :tutorial }) - .where('tutorials.tutorial_stream_id = task_definitions.tutorial_stream_id') - .select( - 'tasks.id AS task_id', - 'tasks.project_id', - 'tasks.task_definition_id', - 'tutorials.id AS tutorial_id', - 'tasks.task_status_id AS status_id', - 'tasks.completion_date', - 'tasks.submission_date', - 'tasks.times_assessed', - 'tasks.grade', - 'tasks.quality_pts', - '0 AS number_unread', - '0 AS similar_to_count', - 'false AS pinned', - 'false AS has_extensions', - 'tasks.*', + moderated_tasks = ModeratedTask + .where(state: %i[open waiting_for_new_feedback]) + .joins(task: [:task_definition, { project: { tutorial_enrolments: :tutorial } }]) + .where(tasks: { project_id: projects.select(:id) }) + .where('tutorials.tutorial_stream_id = task_definitions.tutorial_stream_id') + .includes(task: :comments) + .distinct + + tasks = Task + .joins(:moderated_task) + .merge(moderated_tasks) + .includes(:comments) + .select( + 'tasks.id AS task_id', + 'tasks.project_id', + 'tasks.task_definition_id', + 'tutorials.id AS tutorial_id', + 'tasks.task_status_id AS status_id', + 'tasks.completion_date', + 'tasks.submission_date', + 'tasks.times_assessed', + 'tasks.grade', + 'tasks.quality_pts', + '0 AS number_unread', + '0 AS similar_to_count', + 'false AS pinned', + 'false AS has_extensions', + 'tasks.*', ) - .distinct + .distinct if my_unit_role.nil? || my_unit_role.role != Role.convenor tasks = tasks.where(tutorials: { unit_role_id: mentees.select(:id) }) From d0a0f741424478ecf41d1518bdf363c612d6f89c Mon Sep 17 00:00:00 2001 From: b0ink <40929320+b0ink@users.noreply.github.com> Date: Tue, 3 Mar 2026 09:42:17 +1100 Subject: [PATCH 2/4] chore: enable snooze moderation task action --- app/api/unit_roles_api.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/api/unit_roles_api.rb b/app/api/unit_roles_api.rb index 65ab5aca4..021c4e655 100644 --- a/app/api/unit_roles_api.rb +++ b/app/api/unit_roles_api.rb @@ -149,7 +149,7 @@ class UnitRolesApi < Grape::API error!({ error: 'This task is under Feedback Review. Only review actions (upheld or overturn) are allowed. Please refresh the moderation queue.' }, 400) end else - unless %w[show_more show_less dismiss_ok].include?(action) + unless %w[show_more show_less dismiss_ok snooze].include?(action) error!({ error: 'Invalid action for this moderated task. Please refresh moderation queue.' }, 400) end end @@ -176,6 +176,9 @@ class UnitRolesApi < Grape::API when 'show_more' delta = -1 state = :waiting_for_new_feedback + when 'snooze' + delta = 0 + state = :waiting_for_new_feedback when 'show_less' delta = 1 state = :resolved From b0559f1607b17e8b61bb0d4321b8f7b11830d7f7 Mon Sep 17 00:00:00 2001 From: b0ink <40929320+b0ink@users.noreply.github.com> Date: Tue, 3 Mar 2026 09:59:38 +1100 Subject: [PATCH 3/4] chore: whitelist snooze action --- app/api/unit_roles_api.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/api/unit_roles_api.rb b/app/api/unit_roles_api.rb index 021c4e655..ff0d9f900 100644 --- a/app/api/unit_roles_api.rb +++ b/app/api/unit_roles_api.rb @@ -138,7 +138,7 @@ class UnitRolesApi < Grape::API end action = params[:action].downcase - unless %w[show_more show_less dismiss_ok upheld overturn].include?(action) + unless %w[show_more show_less dismiss_ok upheld overturn snooze].include?(action) error!({ error: 'Invalid moderation action' }, 400) end From 8da6b80a65a2eba90ffea077fb9f985248f3f85b Mon Sep 17 00:00:00 2001 From: b0ink <40929320+b0ink@users.noreply.github.com> Date: Tue, 3 Mar 2026 10:13:38 +1100 Subject: [PATCH 4/4] chore: ignore prerequisite task resubmit comment --- app/models/unit.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/models/unit.rb b/app/models/unit.rb index f768ac11d..e0b082817 100644 --- a/app/models/unit.rb +++ b/app/models/unit.rb @@ -2260,7 +2260,8 @@ def tasks_for_moderation(user) c.content_type == "status" && nxt&.content_type == "text" && (nxt.comment&.downcase&.include?("**automated comment**: some tests did not pass") || - nxt.comment&.downcase&.include?("**automated comment**: something went wrong with your submission")) + nxt.comment&.downcase&.include?("**automated comment**: something went wrong with your submission") || + nxt.comment&.downcase&.include?("**automated comment**: a prerequisite task was updated to fix and resubmit")) c.user == task.tutor && %w[status discussed_in_class text].include?(c.content_type) &&