Skip to content

TD-7613 competency data services query optimisation - #3720

Open
kevwhitt-hee wants to merge 6 commits into
DLS-Release-v1.3.3from
Develop/Fixes/TD-7613-CompetencyServiceQueryOptimisation
Open

TD-7613 competency data services query optimisation#3720
kevwhitt-hee wants to merge 6 commits into
DLS-Release-v1.3.3from
Develop/Fixes/TD-7613-CompetencyServiceQueryOptimisation

Conversation

@kevwhitt-hee

@kevwhitt-hee kevwhitt-hee commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

JIRA link

TD-7613

Description

In-place optimisations for queries across the data services relating to the competency framework service. These largely involve:

  • replacing scalar subqueries with appropriate joins
  • use of CTEs to avoid repeated table scans

No functional changes have been made; method signatures and return objects all remain the same (although a few have been made nullable deliberately). Developer testing has confirmed continued, like-for-like function and, in most cases, observable performance improvements.


Developer checks

(Leave tasks unticked if they haven't been appropriate for your ticket.)

I have:

  • Run the IDE auto formatter on all files I’ve worked on and made sure there are no IDE errors relating to them
  • Written or updated tests for the changes (accessibility ui tests for views, tests for controller, data services, services, view models created or modified) and made sure all tests are passing
  • Manually tested my work with and without JavaScript (adding notes where functionality requires JavaScript)
  • Tested any Views or partials created or changed with Wave Chrome plugin. Addressed any valid accessibility issues and documented any invalid errors
  • Updated my Jira ticket with testing notes, including information about other parts of the system that were touched as part of the MR and need to be tested to ensure nothing is broken
  • Scanned over my pull request in GitHub and addressed any warnings from the GitHub Build and Test checks in the GitHub PR ‘Files Changed’ tab
    Either:
  • Documented my work in Confluence, updating any business rules applied or modified. Updated GitHub readme/documentation for the repository if appropriate. List of documentation links added/changed:
  • Confirmed that none of the work that I have undertaken requires any updates to documentation

- Replaced scalar subqueries in self-assessment base fields with LEFT JOINs for Brands, CourseCategories, SelfAssessments, AdminUsers, and NRP lookup tables.
- Simplified UpdateCompetencyRoleProfileLinks to do one conditional update instead of a prior count query.
- Rewrote GetCollaboratorNotification to avoid redundant scalar lookups and fix the malformed SQL.
- Changed HasCompetencyWithSignpostedLearning to SELECT TOP(1) 1 instead of COUNT(*).
GetDashboardDataForAdminId

Fixed hardcoded sd.SupervisorAdminID = 10857 to use @AdminID
GetAvailableCompetencyAssessmentsForDelegate

Replaced correlated scalar subqueries with LEFT JOIN lookups for Brand, NRPProfessionalGroup, NRPSubGroup, and NRPRole
Replaced NOT IN with NOT EXISTS for better SARGability
GetCompetencyAssessmentById

Replaced scalar subqueries with LEFT JOIN lookups for the related metadata fields
ValidateDelegate

Combined the two-step delegate validation into a single query
AddSuperviseDelegate

Cleaned up the SELECT COALESCE(...) query and fixed malformed SQL/C# syntax
Improved null-parameter handling
Replaced repeated/nested scalar subqueries with joins
Added a safe IN @competencyIds parameterized query for GetSelectedCompetencyFlagsByCompetecyIds
Reworked GetCompetencyResourceAssessmentQuestionParameterByCompetencyLearningResourceId to return null cleanly when no resource is found and avoid string interpolation for SQL IN clauses
Made GetBaseFrameworkByFrameworkId / GetBrandedFrameworkByFrameworkId nullable return types consistent
Simplified AddCompetencyLearningResource
Replaced IF NOT EXISTS + repeated lookup with a single SELECT TOP 1 ID
Improved the insert/upsert logic making it cheaper
Improved GetCompetencyResourceAssessmentQuestionParameters by adding an empty-list check before executing the IN @resourceIds query to avoid errors/handling empty inputs
@kevwhitt-hee
kevwhitt-hee requested a review from rshrirohit July 31, 2026 09:09
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