Skip to content

refactor(async): drop fake-async Task.Run wrappers - #264

Open
rlorenzo wants to merge 1 commit into
mainfrom
refactor/remove-fake-async-task-run
Open

refactor(async): drop fake-async Task.Run wrappers#264
rlorenzo wants to merge 1 commit into
mainfrom
refactor/remove-fake-async-task-run

Conversation

@rlorenzo

@rlorenzo rlorenzo commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Removes the fake-async await Task.Run(() => ...) wrappers that scheduled trivial synchronous work (mostly View(...) allocations) onto the thread pool
  • Converts the affected RAPS and Directory controller actions plus 10 shared view components (InvokeAsync to Invoke) to synchronous signatures; actions with real awaits stay async
  • Keeps the two legitimate Task.Run offloads (LdapHealthCheck's blocking LDAP bind, PhotoService's network-share File.Exists) with comments explaining why
  • Adapts RAPSControllerTests to the sync RolePermissions signature via a sync overload of the bad-request helper
  • Fixes two <param> tags whose names never matched their parameter (RoleList, DirectoryResult), flagged by the ReSharper gate once the signature lines entered the diff

Testing

  • All 2698 backend tests pass
  • Lint clean on touched files (the one remaining warning, CA1502 on RAPSController.Nav, is pre-existing and on untouched lines)

Copilot AI review requested due to automatic review settings July 23, 2026 03:45
@rlorenzo

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@codecov-commenter

Copy link
Copy Markdown

Bundle Report

Bundle size has no change ✅

@codecov-commenter

codecov-commenter commented Jul 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 11.11111% with 48 lines in your changes missing coverage. Please review.
✅ Project coverage is 50.07%. Comparing base (dd7f02c) to head (e15a349).

Files with missing lines Patch % Lines
web/Areas/RAPS/Controllers/RAPSController.cs 15.00% 34 Missing ⚠️
...Areas/Directory/Controllers/DirectoryController.cs 0.00% 3 Missing ⚠️
...ared/Components/EmulationBanner/EmulationBanner.cs 0.00% 2 Missing ⚠️
web/Views/Shared/Components/CMSBlocks/CMSBlocks.cs 0.00% 1 Missing ⚠️
web/Views/Shared/Components/LeftNav/LeftNav.cs 0.00% 1 Missing ⚠️
web/Views/Shared/Components/MainNav/MainNav.cs 0.00% 1 Missing ⚠️
web/Views/Shared/Components/MiniNav/MiniNav.cs 0.00% 1 Missing ⚠️
...b/Views/Shared/Components/ProfilePic/ProfilePic.cs 0.00% 1 Missing ⚠️
...Shared/Components/SessionTimeout/SessionTimeout.cs 0.00% 1 Missing ⚠️
web/Views/Shared/Components/VueCdn/VueCdnCreate.cs 0.00% 1 Missing ⚠️
... and 2 more
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #264   +/-   ##
=======================================
  Coverage   50.07%   50.07%           
=======================================
  Files         998      998           
  Lines       58354    58353    -1     
  Branches     5853     5854    +1     
=======================================
  Hits        29221    29221           
+ Misses      28228    28227    -1     
  Partials      905      905           
Flag Coverage Δ
backend 49.24% <11.11%> (+<0.01%) ⬆️
frontend 58.45% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors ASP.NET MVC actions and shared view components to remove “fake async” await Task.Run(...) wrappers around synchronous work, keeping true async where there are real awaits and documenting the remaining legitimate offloads.

Changes:

  • Converted trivial async controller actions and view components to synchronous signatures and removed Task.Run wrappers for View(...)/Redirect(...).
  • Kept and documented the two intentional Task.Run usages (blocking LDAP bind; potentially-blocking network share File.Exists).
  • Updated/added tests to cover new sync action behavior and some related correctness fixes (e.g., background OU group sync scope, bad-request guards).

Reviewed changes

Copilot reviewed 23 out of 23 changed files in this pull request and generated no comments.

Show a summary per file
File Description
web/Views/Shared/Components/VueTableDefault/VueTableDefault.cs Make view component synchronous; remove Task.Run around View.
web/Views/Shared/Components/VueCdn/VueCdnInit.cs Make view component synchronous; remove Task.Run.
web/Views/Shared/Components/VueCdn/VueCdnCreate.cs Make view component synchronous; remove Task.Run.
web/Views/Shared/Components/SessionTimeout/SessionTimeout.cs Make view component synchronous; remove Task.Run.
web/Views/Shared/Components/ProfilePic/ProfilePic.cs Make view component synchronous; remove Task.Run.
web/Views/Shared/Components/MiniNav/MiniNav.cs Make view component synchronous; remove Task.Run.
web/Views/Shared/Components/MainNav/MainNav.cs Make view component synchronous; remove Task.Run.
web/Views/Shared/Components/LeftNav/LeftNav.cs Make view component synchronous; remove Task.Run.
web/Views/Shared/Components/EmulationBanner/EmulationBanner.cs Make view component synchronous; remove Task.Run/use direct Content/View.
web/Views/Shared/Components/CMSBlocks/CMSBlocks.cs Make view component synchronous; remove Task.Run.
web/Classes/HealthChecks/LdapHealthCheck.cs Add rationale comment for intentional Task.Run offload.
web/Areas/Students/Services/PhotoService.cs Add rationale comment for intentional Task.Run offload.
web/Areas/RAPS/Models/GroupAddEdit.cs Make GroupId nullable for “new group” semantics.
web/Areas/RAPS/Controllers/RAPSController.cs Remove fake-async wrappers; add ModelState guards; fix background group sync scoping/logging; minor query improvements.
web/Areas/RAPS/Controllers/AdGroupsController.cs Fix missing return on mismatched ID bad-request path.
web/Areas/Directory/Controllers/DirectoryController.cs Remove fake-async wrappers; add shared AAUD search helper; make VMACS enrichment properly async.
web/Areas/CTS/Controllers/CTSController.cs Add targeted analyzer suppression for filter override.
web/Areas/CMS/Controllers/CMSController.cs Switch to creating the Data.CMS logger from ILoggerFactory.
test/RAPS/RAPSControllerTests.cs Add coverage for ModelState bad-request guards + sync RolePermissions behavior.
test/RAPS/AdGroupsControllerTests.cs Add regression test for mismatched group ID not updating entity.
test/Directory/DirectoryControllerTests.cs Add SQLite-translated query tests for shared directory search helper.
test/ClinicalScheduler/Integration/ServiceLayerIntegrationTest.cs Refactor test constructor to helper factories (maintainability).
.editorconfig Add/extend analyzer suppressions for generated contexts and ApiPagination.

Comment thread web/Areas/RAPS/Controllers/RAPSController.cs Fixed
@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

Directory search

Layer / File(s) Summary
Directory search flow and coverage
web/Areas/Directory/Controllers/DirectoryController.cs, test/Directory/DirectoryControllerTests.cs
Directory routes and search logic are refactored around shared AAUD filtering, VMACS enrichment, and SQLite-backed tests for matching, filtering, and ordering.

RAPS controller behavior

Layer / File(s) Summary
Controller contracts and synchronization
web/Areas/RAPS/Controllers/RAPSController.cs, web/Areas/RAPS/Controllers/AdGroupsController.cs, web/Areas/RAPS/Models/GroupAddEdit.cs
RAPS actions return synchronous results, validate model state, schedule group synchronization through a fresh scope, and return BadRequest for mismatched group identifiers.
Controller behavior tests
test/RAPS/*
Tests cover invalid model state, permission and role lookups, missing groups, scope creation, mismatched group IDs, and persistence behavior.

Synchronous execution cleanup

Layer / File(s) Summary
View-component entry points
web/Views/Shared/Components/*/*.cs
Shared view components now use synchronous Invoke methods and direct view results instead of InvokeAsync and Task.Run.
Supporting updates
.editorconfig, web/Areas/CMS/Controllers/CMSController.cs, web/Areas/CTS/Controllers/CTSController.cs, test/ClinicalScheduler/Integration/ServiceLayerIntegrationTest.cs, web/Classes/HealthChecks/LdapHealthCheck.cs, web/Areas/Students/Services/PhotoService.cs
Logging construction, analyzer suppressions, test dependency initialization, and comments for retained blocking operations are updated.

Estimated code review effort: 4 (Complex) | ~45 minutes

Suggested reviewers: copilot

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 47.37% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely describes the primary change: removing unnecessary Task.Run wrappers from asynchronous code.
Description check ✅ Passed The description directly explains the refactoring, retained legitimate Task.Run uses, test updates, and validation results.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/remove-fake-async-task-run

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 6

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@test/RAPS/RAPSControllerTests.cs`:
- Around line 177-190: Add a success-path test alongside
GroupSync_RendersWithoutSyncing_WhenGroupMissing that seeds an OuGroup, invokes
GroupSync with its ID, and asserts scopeFactory.Received(1).CreateScope() and/or
populated ViewData["Group"]. Keep the assertion focused on synchronous dispatch;
do not await the fire-and-forget background task.

In `@web/Areas/Directory/Controllers/DirectoryController.cs`:
- Around line 64-73: Refactor the result-building loops in Get and GetUCD so
LookupEmailHost(_aaud) remains sequential, while
AddVmacsContactInfoAsync(result) calls are collected and awaited together with
Task.WhenAll after each loop. Preserve result ordering and ensure every
constructed result receives VMACS enrichment before the action returns.
- Around line 57-75: Update the Get method’s per-result LDAP lookup so the
blocking LdapService.GetUserByID call runs on a pool thread, or offload the
complete per-result metadata work without blocking the async continuation.
Preserve result construction, LookupEmailHost, AddVmacsContactInfoAsync, and
ordering while ensuring each LdapConnection operation does not execute directly
on the request thread.

In `@web/Areas/RAPS/Controllers/RAPSController.cs`:
- Around line 589-629: Replace the discarded SyncGroupInBackground call in
GroupSync with enqueueing the groupId and group name through a registered
background queue/handler. Implement processing in an IHostedService or
BackgroundService using IServiceScopeFactory to resolve RAPSContext and run
OuGroupService.Sync, with appropriate failure handling and lifecycle tracking;
remove the controller-owned fire-and-forget execution path.
- Around line 74-99: In the Nav method, replace the SingleOrDefaultAsync lookup
of VwAaudUser by MothraId with FirstOrDefaultAsync, preserving the existing null
guard and AsNoTracking behavior so duplicate MothraId rows do not fail RAPS
requests.

In `@web/Views/Shared/Components/ProfilePic/ProfilePic.cs`:
- Around line 17-22: Update ProfilePic.Invoke to InvokeAsync and await an
asynchronous GetByLoginIdAsync lookup; implement or reuse the corresponding
IUserHelper/UserHelper path with FirstOrDefaultAsync for cache misses. Preserve
the existing “Default” view and user result, and do not use Task.Run.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 5a7266cc-41db-41e7-89dd-c94498fea40c

📥 Commits

Reviewing files that changed from the base of the PR and between b52f541 and 0b639b1.

📒 Files selected for processing (23)
  • .editorconfig
  • test/ClinicalScheduler/Integration/ServiceLayerIntegrationTest.cs
  • test/Directory/DirectoryControllerTests.cs
  • test/RAPS/AdGroupsControllerTests.cs
  • test/RAPS/RAPSControllerTests.cs
  • web/Areas/CMS/Controllers/CMSController.cs
  • web/Areas/CTS/Controllers/CTSController.cs
  • web/Areas/Directory/Controllers/DirectoryController.cs
  • web/Areas/RAPS/Controllers/AdGroupsController.cs
  • web/Areas/RAPS/Controllers/RAPSController.cs
  • web/Areas/RAPS/Models/GroupAddEdit.cs
  • web/Areas/Students/Services/PhotoService.cs
  • web/Classes/HealthChecks/LdapHealthCheck.cs
  • web/Views/Shared/Components/CMSBlocks/CMSBlocks.cs
  • web/Views/Shared/Components/EmulationBanner/EmulationBanner.cs
  • web/Views/Shared/Components/LeftNav/LeftNav.cs
  • web/Views/Shared/Components/MainNav/MainNav.cs
  • web/Views/Shared/Components/MiniNav/MiniNav.cs
  • web/Views/Shared/Components/ProfilePic/ProfilePic.cs
  • web/Views/Shared/Components/SessionTimeout/SessionTimeout.cs
  • web/Views/Shared/Components/VueCdn/VueCdnCreate.cs
  • web/Views/Shared/Components/VueCdn/VueCdnInit.cs
  • web/Views/Shared/Components/VueTableDefault/VueTableDefault.cs

Comment thread test/RAPS/RAPSControllerTests.cs
Comment thread web/Areas/Directory/Controllers/DirectoryController.cs
Comment thread web/Areas/Directory/Controllers/DirectoryController.cs
Comment thread web/Areas/RAPS/Controllers/RAPSController.cs
Comment thread web/Areas/RAPS/Controllers/RAPSController.cs
Comment thread web/Views/Shared/Components/ProfilePic/ProfilePic.cs
- convert controller actions and view components with no real async
  work to synchronous signatures
- keep the two legitimate Task.Run offloads (blocking LDAP bind,
  network-share File.Exists) with comments explaining why
Copilot AI review requested due to automatic review settings July 31, 2026 22:41
@rlorenzo
rlorenzo force-pushed the refactor/remove-fake-async-task-run branch from 0b639b1 to e15a349 Compare July 31, 2026 22:41

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 15 out of 15 changed files in this pull request and generated no new comments.

Suppressed comments (1)

web/Areas/Directory/Controllers/DirectoryController.cs:112

  • The inline comment still refers to "uid", but this action now routes/binds by mothraID (and the XML doc was updated accordingly). Update the comment to avoid confusion when maintaining this action.
            // pull in the user based on uid

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants