Skip to content

refactor(async): drop fake-async wrappers - #264

Merged
rlorenzo merged 1 commit into
mainfrom
refactor/remove-fake-async-task-run
Aug 7, 2026
Merged

refactor(async): drop fake-async wrappers#264
rlorenzo merged 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
  • Drops the async state machine from StudentGroupService.GetEighthsGroupsAsync, which awaited Task.FromResult over a hardcoded list. The interface signature stays Task<List<string>> because its three sibling group getters are genuinely DB-backed, so no call sites change
  • Keeps the two Task.Run calls that offload genuinely blocking sync work (LdapHealthCheck's LDAP bind, PhotoService's network-share File.Exists) with comments explaining why. The repo's other Task.Run sites are untouched and are not fake async: the Effort harvest/import/rollover controllers use it for fire-and-forget background jobs, and BiorenderStudentLookup uses it for a throttled fan-out
  • Adapts RAPSControllerTests to the sync RolePermissions signature via a sync overload of the bad-request helper
  • Fixes two <param> tags that did not resolve to their parameter: RoleList documented Instance against a parameter named instance (XML doc param names are case-sensitive), and DirectoryResult documented uid against a parameter named mothraID. Both were flagged by the ReSharper gate once the signature lines entered the diff

Testing

  • All 2708 backend tests pass
  • npm run verify:build clean, with no new analyzer warnings
  • Verified there are no remaining CS1998 (async method without await) warnings anywhere in the project
  • The one warning on touched files, CA1502 on RAPSController.Nav (complexity 35), is pre-existing and on untouched lines. It is one of 17 pre-existing CA1502 warnings in the repo and belongs in a separate refactor

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 10.16949% with 53 lines in your changes missing coverage. Please review.
✅ Project coverage is 41.88%. Comparing base (553849d) to head (6ddf817).

Files with missing lines Patch % Lines
web/Areas/RAPS/Controllers/RAPSController.cs 15.00% 34 Missing ⚠️
web/Areas/Students/Services/StudentGroupService.cs 0.00% 5 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 ⚠️
... and 3 more
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #264   +/-   ##
=======================================
  Coverage   41.88%   41.88%           
=======================================
  Files         986      986           
  Lines       49490    49489    -1     
  Branches     5842     5843    +1     
=======================================
  Hits        20727    20727           
+ Misses      27854    27853    -1     
  Partials      909      909           
Flag Coverage Δ
backend 39.94% <10.16%> (+<0.01%) ⬆️
frontend 58.15% <ø> (ø)

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

Files with missing lines Coverage Δ
web/Areas/Students/Services/PhotoService.cs 70.28% <ø> (ø)
web/Classes/HealthChecks/LdapHealthCheck.cs 0.00% <ø> (ø)
web/Views/Shared/Components/CMSBlocks/CMSBlocks.cs 0.00% <0.00%> (ø)
web/Views/Shared/Components/LeftNav/LeftNav.cs 0.00% <0.00%> (ø)
web/Views/Shared/Components/MainNav/MainNav.cs 0.00% <0.00%> (ø)
web/Views/Shared/Components/MiniNav/MiniNav.cs 0.00% <0.00%> (ø)
...b/Views/Shared/Components/ProfilePic/ProfilePic.cs 0.00% <0.00%> (ø)
...Shared/Components/SessionTimeout/SessionTimeout.cs 0.00% <0.00%> (ø)
web/Views/Shared/Components/VueCdn/VueCdnCreate.cs 0.00% <0.00%> (ø)
web/Views/Shared/Components/VueCdn/VueCdnInit.cs 0.00% <0.00%> (ø)
... and 5 more

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 summarizes the primary change: removing unnecessary async wrappers and converting trivial synchronous work to synchronous methods.
Description check ✅ Passed The description directly explains the fake-async removal, affected components, retained Task.Run uses, tests, 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
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

Copilot AI review requested due to automatic review settings August 6, 2026 08:10
@rlorenzo
rlorenzo force-pushed the refactor/remove-fake-async-task-run branch from e15a349 to 016530e Compare August 6, 2026 08:10

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.

Copilot AI review requested due to automatic review settings August 7, 2026 04:14
@rlorenzo
rlorenzo force-pushed the refactor/remove-fake-async-task-run branch from 016530e to edf7bf3 Compare August 7, 2026 04:14

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

  • This inline comment still refers to "uid", but the route and parameter were corrected to mothraID. Updating the comment avoids confusion about which identifier this action uses.
            // pull in the user based on uid

@rlorenzo
rlorenzo force-pushed the refactor/remove-fake-async-task-run branch from edf7bf3 to 6157660 Compare August 7, 2026 18:08
- convert controller actions and view components with no real async
  work to synchronous signatures
- drop the async state machine from GetEighthsGroupsAsync, which
  awaited Task.FromResult over a hardcoded list
- keep the legitimate Task.Run offloads (blocking LDAP bind,
  network-share File.Exists) with comments explaining why
@rlorenzo
rlorenzo force-pushed the refactor/remove-fake-async-task-run branch from 6157660 to 6ddf817 Compare August 7, 2026 18:38
@rlorenzo rlorenzo changed the title refactor(async): drop fake-async Task.Run wrappers refactor(async): drop fake-async wrappers Aug 7, 2026
@rlorenzo
rlorenzo requested a review from Copilot August 7, 2026 18:46

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 16 out of 16 changed files in this pull request and generated no new comments.

Suppressed comments (1)

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

  • The route parameter and action parameter are named mothraID, which is inconsistent with the repo’s prevailing *Id casing (e.g., MothraId/mothraId elsewhere) and makes the inline comment misleading. Rename to mothraId for consistency and update the inline comment to match what the stub will eventually do.
        /// <param name="mothraID">Mothra ID</param>
        [Route("userInfo/{mothraID}")]
        public IActionResult DirectoryResult(string mothraID)
        {
            // pull in the user based on uid

@rlorenzo
rlorenzo requested a review from bniedzie August 7, 2026 20:53
@rlorenzo
rlorenzo merged commit 17909eb into main Aug 7, 2026
14 of 15 checks passed
@rlorenzo
rlorenzo deleted the refactor/remove-fake-async-task-run branch August 7, 2026 22:56
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.

5 participants