Autolab icon indicating copy to clipboard operation
Autolab copied to clipboard

Manage submissions speed

Open dwang3851 opened this issue 2 months ago β€’ 4 comments

Description

This changes implements server-side pagination for the manage submissions page to improve loading times.

Motivation and Context

Previously, it would take about 1.5 seconds for each page of the manage submissions page to load since we would render all of them at once. For example, for a submissions page with 400 submissions, it would take about 6 seconds. This change renders only one page at a time, to take a maximum of 1.5 seconds each time.

How Has This Been Tested?

Tested all of the manage submissions functions locally

Types of changes

  • [ ] Bug fix (non-breaking change which fixes an issue)
  • [x] New feature (non-breaking change which adds functionality)
  • [ ] Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • [x] I have run rubocop and erblint for style check. If you haven't, run overcommit --install && overcommit --sign to use pre-commit hook for linting
  • [ ] My change requires a change to the documentation, which is located at Autolab Docs
  • [ ] I have updated the documentation accordingly, included in this PR

dwang3851 avatar Oct 30 '25 22:10 dwang3851

πŸ“ Walkthrough

Walkthrough

Switched the submissions index to DataTables server-side rendering. Controller now serves paginated/searchable/sortable JSON and a new row formatter. Client JS manages selection state, delegated events, dynamic row rendering, and batch-action enablement. View removed server-rendered rows and provides header + select-all UI.

Changes

Cohort / File(s) Summary
Server-side DataTables & Controller
app/controllers/submissions_controller.rb
Added JSON handling for DataTables (paging, search by email, multi-column sort including computed score), computes recordsTotal/recordsFiltered, and introduced format_submission_for_datatable(submission, score = nil); declared action_auth_level for new action; removed prior per-request caching logic.
Client DataTables Initialization & Selection State
app/assets/javascripts/manage_submissions.js
Replaced legacy DataTable init with serverSide/ajax; added selectedStudentCids, selectedSubmissions, submissions_to_cud; implemented columns, createdRow, drawCallback, delegated handlers for dynamic elements; added toggleAllRows, toggleRow, updateSelectAllCheckbox, and updateSelectedCount; removed old pagination/hardcoded-row hacks.
View: Table Header & Template Simplification
app/views/submissions/index.html.erb
Removed server-rendered tbody and per-row markup, selected-count placeholder, and Regrade All block; simplified header generation to include select-all checkbox and sortable headers; retained modals/placeholders for annotations.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Browser as Browser (manage_submissions.js)
    participant Server as Server (SubmissionsController)
    participant DB as Database

    rect rgba(230,245,255,0.8)
    Note over User,Browser: Initial page load (HTML)
    User->>Browser: GET /submissions
    Browser->>Server: GET /submissions (HTML)
    Server->>DB: Query scaffold data (limited)
    DB-->>Server: Return scaffold
    Server-->>Browser: Render index view (DataTables config + headers)
    Browser->>Browser: Initialize DataTables (serverSide)
    end

    rect rgba(245,230,255,0.8)
    Note over Browser,Server: DataTables requests rows
    Browser->>Server: AJAX GET /submissions.json (draw,start,length,search,order)
    Server->>DB: Query submissions with filters/sort/limit (may compute score)
    DB-->>Server: Return rows
    Server->>Server: format_submission_for_datatable per row
    Server-->>Browser: JSON (data, draw, recordsTotal, recordsFiltered)
    Browser->>Browser: createdRow + drawCallback -> render row HTML, checkboxes, actions
    end

    rect rgba(230,255,235,0.8)
    Note over User,Browser: Selection & batch actions
    User->>Browser: Click row checkbox / select-all
    Browser->>Browser: toggleRow / toggleAllRows -> update selections, UI highlight
    Browser->>Browser: updateSelectedCount() -> enable/disable batch actions
    end

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45–75 minutes

  • Focus review on:
    • app/controllers/submissions_controller.rb: search/sort correctness (especially computed-score sort), record counts, and format_submission_for_datatable data/HTML.
    • app/assets/javascripts/manage_submissions.js: DataTables columns mapping, createdRow/drawCallback selection persistence, delegated event handlers, and batch-action endpoint wiring.
    • Column ordering and header ↔ DataTables column index alignment in app/views/submissions/index.html.erb.

Possibly related PRs

  • autolab/Autolab#2248 β€” Overlaps same files and the move to DataTables/server-side loading and selection refactor.
  • autolab/Autolab#2277 β€” Directly touches selection/count logic in manage_submissions.js, overlapping selection behavior changes.
  • autolab/Autolab#2287 β€” Modifies select-all and per-row toggle and batch-action handling in manage_submissions.js, closely related to this refactor.

Suggested reviewers

  • KesterTan
  • coder6583
  • jhs-panda

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
βœ… Passed checks (2 passed)
Check name Status Explanation
Title check βœ… Passed The title "Manage submissions speed" clearly describes the main objective of the changesetβ€”optimizing the performance of the manage submissions page through server-side pagination.
Description check βœ… Passed The description covers the key required sections: a clear summary of changes (server-side pagination implementation), motivation explaining the performance problem and its solution, and testing notes indicating local validation.
✨ Finishing touches
  • [ ] πŸ“ Generate docstrings
πŸ§ͺ Generate unit tests (beta)
  • [ ] Create PR with unit tests
  • [ ] Post copyable unit tests in a comment
  • [ ] Commit unit tests in branch manage-submissions-speed

[!TIP]

πŸ“ Customizable high-level summaries are now available in beta!

You can now customize how CodeRabbit generates the high-level summary in your pull requests β€” including its content, structure, tone, and formatting.

  • Provide your own instructions using the high_level_summary_instructions setting.
  • Format the summary however you like (bullet lists, tables, multi-section layouts, contributor stats, etc.).
  • Use high_level_summary_in_walkthrough to move the summary from the description to the walkthrough section.

Example instruction:

"Divide the high-level summary into five sections:

  1. πŸ“ Description β€” Summarize the main change in 50–60 words, explaining what was done.
  2. πŸ““ References β€” List relevant issues, discussions, documentation, or related PRs.
  3. πŸ“¦ Dependencies & Requirements β€” Mention any new/updated dependencies, environment variable changes, or configuration updates.
  4. πŸ“Š Contributor Summary β€” Include a Markdown table showing contributions: | Contributor | Lines Added | Lines Removed | Files Changed |
  5. βœ”οΈ Additional Notes β€” Add any extra reviewer context. Keep each section concise (under 200 words) and use bullet or numbered lists for clarity."

Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❀️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar Oct 30 '25 22:10 coderabbitai[bot]

Regrade all causes the whole page to re-render, the submissions seem to be empty for a while before it is loaded again.

As a result, the tooltip for regrade all also dissapears.

KesterTan avatar Nov 13 '25 23:11 KesterTan

Regrade all causes the whole page to re-render, the submissions seem to be empty for a while before it is loaded again.

As a result, the tooltip for regrade all also dissapears.

The tooltip for regrade all does not disappear for me, was unable to reproduce this behavior

dwang3851 avatar Nov 20 '25 22:11 dwang3851

https://github.com/user-attachments/assets/e6e5faa1-5870-4fae-811d-523e969dff74

Check recording above, there should be a tooltip that says x number of submissions regraded but none is shown.

Screenshot 2025-11-25 at 5 10 41β€―AM

KesterTan avatar Nov 25 '25 10:11 KesterTan