Skip to content

CodeQL 14: refactor: convert foreach-add patterns to LINQ Select#200

Open
rlorenzo wants to merge 2 commits into
mainfrom
codeql/14-effort-pdf-select
Open

CodeQL 14: refactor: convert foreach-add patterns to LINQ Select#200
rlorenzo wants to merge 2 commits into
mainfrom
codeql/14-effort-pdf-select

Conversation

@rlorenzo
Copy link
Copy Markdown
Contributor

@rlorenzo rlorenzo commented May 13, 2026

Summary

Closes 3 of the 28 cs/linq/missed-select alerts where the foreach body is a simple build-and-add into a context/list:

  • CourseController.AddSessionCompetency (line 227) - foreach (var levelId in LevelIds) { var x = new SessionCompetency(...); context.Add(x); }context.AddRange(LevelIds.Select(levelId => new SessionCompetency(...))).
  • CourseController.UpdateSessionCompetency (line 273, same pattern).
  • IndividualSearchResult (line 130) - foreach (var r in results) { EmailHost = r.Split("@")[^1]; }Select(...) to materialize the list, then guard on count before assigning the last entry. Semantically identical.

Not addressed (still open)

The remaining 25 cs/linq/missed-select alerts are all in PDF/Excel cell-generation loops in Effort report services where the foreach body calls side-effectful QuestPDF.table.Cell()…Text(…) or ClosedXML.ws.Cell()…Value. Forcing those into Select just renames a single local without removing the iteration or its side effects, so the resulting code is the same length with worse readability. Those should be dismissed at the dashboard.

Context

Fourteenth in the CodeQL N: cleanup series.

Test plan

  • npm run test:backend - 1946 tests passing
  • Pre-commit lint+test+verify all passed

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 13, 2026

Warning

Rate limit exceeded

@rlorenzo has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 58 minutes and 32 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: ac83b265-82fc-4c72-a631-8873069338a3

📥 Commits

Reviewing files that changed from the base of the PR and between 38de1ad and 768fba1.

📒 Files selected for processing (2)
  • web/Areas/CTS/Controllers/CourseController.cs
  • web/Areas/Directory/Models/IndividualSearchResult.cs
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codeql/14-effort-pdf-select

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.

@codecov-commenter
Copy link
Copy Markdown

Bundle Report

Bundle size has no change ✅

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 13, 2026

Codecov Report

❌ Patch coverage is 0% with 21 lines in your changes missing coverage. Please review.
✅ Project coverage is 42.96%. Comparing base (38de1ad) to head (768fba1).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
web/Areas/CTS/Controllers/CourseController.cs 0.00% 15 Missing ⚠️
...b/Areas/Directory/Models/IndividualSearchResult.cs 0.00% 6 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #200   +/-   ##
=======================================
  Coverage   42.96%   42.96%           
=======================================
  Files         877      877           
  Lines       51468    51462    -6     
  Branches     4802     4800    -2     
=======================================
  Hits        22113    22113           
+ Misses      28831    28825    -6     
  Partials      524      524           
Flag Coverage Δ
backend 43.04% <0.00%> (+<0.01%) ⬆️
frontend 41.34% <ø> (ø)

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

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

S2971: SqlQueryRaw().ToList().Select(...) materializes the entire
result set into a List just to throw it away. Replace with
AsEnumerable() — same effect of switching to LINQ-to-objects so the
Split isn't translated to SQL, without the extra allocation.
@rlorenzo
Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 15, 2026

✅ Actions performed

Review triggered.

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.

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.

2 participants