Improve performance#51
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR focuses on improving query performance in the Web layer by reducing heavy includes / repeated subqueries, adding a covering index for CheckResults, and updating related dependencies and tests.
Changes:
- Refactor workspace and check list queries to compute “latest status” data more efficiently and leverage no-tracking reads.
- Replace loading full alert history collections with a direct
COUNT(*)query for alert history counts. - Add a Postgres covering index on
(CheckId, CheckedAt DESC)including commonly-read columns, and bump EF/Npgsql package versions.
Reviewed changes
Copilot reviewed 34 out of 35 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| SAMA.Web/Services/Queries/WorkspaceQueryService.cs | Refactors workspace list/details status counts into a separate query + in-memory aggregation. |
| SAMA.Web/Services/Queries/CheckQueryService.cs | Refactors workspace check list to fetch latest results via a second query instead of including full histories. |
| SAMA.Web/Services/Queries/AlertQueryService.cs | Avoids loading AlertHistories by counting histories via a separate query. |
| SAMA.Web/SAMA.Web.csproj | Updates ASP.NET / EF-related package versions. |
| SAMA.Web/Pages/Shared/WorkspacePageModel.cs | Updates WorkspaceQueryService construction to include ApplicationStateService. |
| SAMA.Tests.Unit/Web/Pages/Workspaces/IndexModelTests.cs | Updates WorkspaceQueryService substitute construction for new constructor signature. |
| SAMA.Tests.Unit/Web/Pages/Workspaces/EditModelTests.cs | Updates WorkspaceQueryService substitute construction for new constructor signature. |
| SAMA.Tests.Unit/Web/Pages/Workspaces/DeleteModelTests.cs | Updates WorkspaceQueryService substitute construction for new constructor signature. |
| SAMA.Tests.Unit/Web/Pages/NotificationChannels/IndexModelTests.cs | Updates WorkspaceQueryService substitute construction for new constructor signature. |
| SAMA.Tests.Unit/Web/Pages/NotificationChannels/EditModelTests.cs | Updates WorkspaceQueryService substitute construction for new constructor signature. |
| SAMA.Tests.Unit/Web/Pages/NotificationChannels/DetailsModelTests.cs | Updates WorkspaceQueryService substitute construction for new constructor signature. |
| SAMA.Tests.Unit/Web/Pages/NotificationChannels/DeleteModelTests.cs | Updates WorkspaceQueryService substitute construction for new constructor signature. |
| SAMA.Tests.Unit/Web/Pages/NotificationChannels/CreateModelTests.cs | Updates WorkspaceQueryService substitute construction for new constructor signature. |
| SAMA.Tests.Unit/Web/Pages/EventSubscriptions/ManageModelTests.cs | Updates WorkspaceQueryService substitute construction for new constructor signature. |
| SAMA.Tests.Unit/Web/Pages/EventSubscriptions/IndexModelTests.cs | Updates WorkspaceQueryService substitute construction for new constructor signature. |
| SAMA.Tests.Unit/Web/Pages/Dashboard/IndexModelTests.cs | Updates WorkspaceQueryService substitute construction for new constructor signature. |
| SAMA.Tests.Unit/Web/Pages/Checks/IndexModelTests.cs | Updates WorkspaceQueryService substitute construction for new constructor signature. |
| SAMA.Tests.Unit/Web/Pages/Checks/EditModelTests.cs | Updates WorkspaceQueryService substitute construction for new constructor signature. |
| SAMA.Tests.Unit/Web/Pages/Checks/DetailsModelTests.cs | Updates WorkspaceQueryService substitute construction for new constructor signature. |
| SAMA.Tests.Unit/Web/Pages/Checks/DeleteModelTests.cs | Updates WorkspaceQueryService substitute construction for new constructor signature. |
| SAMA.Tests.Unit/Web/Pages/Checks/CreateModelTests.cs | Updates WorkspaceQueryService substitute construction for new constructor signature. |
| SAMA.Tests.Unit/Web/Pages/Alerts/IndexModelTests.cs | Updates WorkspaceQueryService substitute construction for new constructor signature. |
| SAMA.Tests.Unit/Web/Pages/Alerts/EditModelTests.cs | Updates WorkspaceQueryService substitute construction for new constructor signature. |
| SAMA.Tests.Unit/Web/Pages/Alerts/DetailsModelTests.cs | Updates WorkspaceQueryService substitute construction for new constructor signature. |
| SAMA.Tests.Unit/Web/Pages/Alerts/DeleteModelTests.cs | Updates WorkspaceQueryService substitute construction for new constructor signature. |
| SAMA.Tests.Unit/Web/Pages/Alerts/CreateModelTests.cs | Updates WorkspaceQueryService substitute construction for new constructor signature. |
| SAMA.Tests.Unit/Web/Pages/Admin/Settings/IndexModelTests.cs | Updates WorkspaceQueryService substitute construction for new constructor signature. |
| SAMA.Tests.Integration/Web/Services/Queries/WorkspaceQueryServiceTests.cs | Adds integration coverage for status counting logic and pending-state rules. |
| SAMA.Tests.Integration/SAMA.Tests.Integration.csproj | Bumps EF / DI / Npgsql package versions for integration tests. |
| SAMA.Shared/SAMA.Shared.csproj | Bumps Microsoft.Extensions.Http package version. |
| SAMA.Data/SAMA.Data.csproj | Bumps EF / Identity EF / Npgsql package versions. |
| SAMA.Data/Migrations/SamaDbContextModelSnapshot.cs | Updates EF model snapshot and index metadata for the new covering index. |
| SAMA.Data/Migrations/20260403004123_AddCoveringIndexForCheckResults.Designer.cs | Adds migration designer for the covering index change. |
| SAMA.Data/Migrations/20260403004123_AddCoveringIndexForCheckResults.cs | Adds migration to replace the prior index with a covering index. |
| SAMA.Data/Configuration/CheckResultConfiguration.cs | Updates EF configuration to define the covering index with included properties. |
Files not reviewed (1)
- SAMA.Data/Migrations/20260403004123_AddCoveringIndexForCheckResults.Designer.cs: Language not supported
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Also update dependencies and fix a small bug