Skip to content

[BEEEP] Lazy load the current user in the CurrentContext #5605

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from

Conversation

jonashendrickx
Copy link
Contributor

🎟️ Tracking

📔 Objective

The User property is currently being cached in CurrentContext and exposed with ICurrentContext using dependency injection with a request scope. The properties in this object are being set using the middleware after a user is authenticated and authorized to access a specific endpoint.

I believe the CurrentContext should be singlehandedly responsible for populating this object as it would otherwise unnecessarily add technical debt as to where the property is being populated and when.

By lazy loading the property when it is only being used, we will not unnecessarily retrieve the user from the backend when it is not needed.

There are potential performance improvements coming from this change. Although it's very unlikely you will try to retrieve the same user multiple times in a single request scope.

📸 Screenshots

⏰ Reminders before review

  • Contributor guidelines followed
  • All formatters and local linters executed and passed
  • Written new unit and / or integration tests where applicable
  • Protected functional changes with optionality (feature flags)
  • Used internationalization (i18n) for all UI strings
  • CI builds passed
  • Communicated to DevOps any deployment requirements
  • Updated any necessary documentation (Confluence, contributing docs) or informed the documentation team

🦮 Reviewer guidelines

  • 👍 (:+1:) or similar for great changes
  • 📝 (:memo:) or ℹ️ (:information_source:) for notes or general info
  • ❓ (:question:) for questions
  • 🤔 (:thinking:) or 💭 (:thought_balloon:) for more open inquiry that's not quite a confirmed issue and could potentially benefit from discussion
  • 🎨 (:art:) for suggestions / improvements
  • ❌ (:x:) or ⚠️ (:warning:) for more significant problems or concerns needing attention
  • 🌱 (:seedling:) or ♻️ (:recycle:) for future improvements or indications of technical debt
  • ⛏ (:pick:) for minor or nitpick changes

@jonashendrickx jonashendrickx requested review from a team as code owners April 4, 2025 09:15
@jonashendrickx jonashendrickx requested a review from rr-bw April 4, 2025 09:15
Copy link
Contributor

github-actions bot commented Apr 4, 2025

Logo
Checkmarx One – Scan Summary & Details21fb7c4c-24e6-4744-a6db-1cc45c2cd45e

Fixed Issues (1)

Great job! The following issues were fixed in this Pull Request

Severity Issue Source File / Package
MEDIUM CSRF /src/Api/AdminConsole/Controllers/GroupsController.cs: 164

Copy link

sonarqubecloud bot commented Apr 4, 2025

Copy link

codecov bot commented Apr 4, 2025

Codecov Report

Attention: Patch coverage is 43.75000% with 18 lines in your changes missing coverage. Please review.

Project coverage is 45.12%. Comparing base (67d7d68) to head (2cd8c75).
Report is 19 commits behind head on main.

Files with missing lines Patch % Lines
...i/Billing/Controllers/AccountsBillingController.cs 0.00% 6 Missing ⚠️
src/Core/Auth/Identity/UserStore.cs 50.00% 2 Missing and 3 partials ⚠️
src/Core/Services/Implementations/UserService.cs 44.44% 5 Missing ⚠️
src/Notifications/NotificationsHub.cs 0.00% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5605   +/-   ##
=======================================
  Coverage   45.12%   45.12%           
=======================================
  Files        1565     1565           
  Lines       71723    71726    +3     
  Branches     6424     6424           
=======================================
+ Hits        32363    32365    +2     
- Misses      37982    37983    +1     
  Partials     1378     1378           

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@rr-bw rr-bw requested review from ike-kottlowski and removed request for rr-bw April 4, 2025 16:32
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.

1 participant