Skip to content

Document URL Service: Batch delete of obsolete URL segment records to avoid SQL Server parameter limit (closes #22339)#22340

Merged
Migaroez merged 3 commits intomainfrom
v17/bugfix/22339-parameter-count-bug-with-document-url-service
Apr 3, 2026
Merged

Document URL Service: Batch delete of obsolete URL segment records to avoid SQL Server parameter limit (closes #22339)#22340
Migaroez merged 3 commits intomainfrom
v17/bugfix/22339-parameter-count-bug-with-document-url-service

Conversation

@AndyButland
Copy link
Copy Markdown
Contributor

@AndyButland AndyButland commented Apr 3, 2026

Description

#22339 has shown an issue for large sites with a lot of languages in migrating to 17.3.

We have an existing operation that removes records from the umbracoDocumentUrl table identified by Ids, that wasn't protected by the usual "groups of" pattern to avoid exceeding the SQL parameter count. This is exercised in a migration for 17.3 introduced in #21558 and fails if the number of document/language records to remove exceeds the 2100 limit.

To fix I've applied the usual pattern of batch the delete of obsolete URL segment records in DocumentUrlRepository.Save() and DocumentUrlAliasRepository.Save() using InGroupsOf(Constants.Sql.MaxParameterCount).

Add an explicit integration test that creates a scenario (110 documents × 10 languages = 2200 stale rows) to verify the fix. The test is marked [Explicit] as it takes 10+ seconds to run.

In addition, there's a bug in the migration itself that was triggering a full rebuild for both SQL Server and SQLite, but the former was a mistake and doing unnecessary work (as the data is already correct following the migration).

Testing

To test I've verified the test fails on SQL Server (LocalDb) without the fix (SqlException error 8003: too many parameters) and passes with the fix in place.

…to avoid exceeding SQL Server's 2100 parameter limit.
Copilot AI review requested due to automatic review settings April 3, 2026 04:35
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a SQL Server “too many parameters” failure during URL segment/alias cache rebuilds by batching deletion of obsolete rows in the document URL repositories, and adds an integration test to reproduce the high-parameter scenario on LocalDb.

Changes:

  • Batch DELETE ... WHERE id IN (...) operations in DocumentUrlRepository.Save() and DocumentUrlAliasRepository.Save() using InGroupsOf(Constants.Sql.MaxParameterCount).
  • Add an explicit integration test that creates >2000 stale URL rows to validate the batching fix (reproducible on SQL Server/LocalDb).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
tests/Umbraco.Tests.Integration/Umbraco.Core/Services/DocumentUrlServiceTests.cs Adds an [Explicit] integration test that sets up >2000 obsolete URL rows and asserts Save() does not throw and leaves only the new invariant rows.
src/Umbraco.Infrastructure/Persistence/Repositories/Implement/DocumentUrlRepository.cs Batches deletion of obsolete umbracoDocumentUrl rows to avoid exceeding SQL Server parameter limits.
src/Umbraco.Infrastructure/Persistence/Repositories/Implement/DocumentUrlAliasRepository.cs Batches deletion of obsolete umbracoDocumentUrlAlias rows to avoid exceeding SQL Server parameter limits.

Copy link
Copy Markdown
Contributor

@Migaroez Migaroez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code changes look good.
Test proves that the repository behind the service can handle more than Constants.Sql.MaxParameterCount of items at once.
Tested on SQL server with repo changes and without. Without fails, with succeeds.

@Migaroez Migaroez merged commit 5127b97 into main Apr 3, 2026
26 of 27 checks passed
@Migaroez Migaroez deleted the v17/bugfix/22339-parameter-count-bug-with-document-url-service branch April 3, 2026 08:51
AndyButland added a commit that referenced this pull request Apr 3, 2026
… avoid SQL Server parameter limit (closes #22339) (#22340)

* Batch delete in DocumentUrlRepository and DocumentUrlAliasRepository to avoid exceeding SQL Server's 2100 parameter limit.

* Address code review feedback.

* Remove the unnecessary trigger rebuild on startup statement in the SQL Server migration path.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants