Compare commits
27 Commits
refactor/U
...
phase-2-qu
| Author | SHA1 | Date | |
|---|---|---|---|
| 4bb1b24f92 | |||
| 1bc741b470 | |||
| dc44bebfcc | |||
| fb20c480e3 | |||
| ff4bdb2509 | |||
| 31dfe07aa7 | |||
| cf8394b6fd | |||
| 36d1fcc8ac | |||
| d78238b247 | |||
| ca739ad64f | |||
| 1d082e1ed6 | |||
| 9962df50ee | |||
| 0351dc06b4 | |||
| b72db59957 | |||
| c9ff758aca | |||
| a079c44afb | |||
| 6db0554b1e | |||
| 0ef17bb1fc | |||
| 3239a4534e | |||
| 7e989c0f8c | |||
| cf74f7850e | |||
| 86b0d3d803 | |||
| 0c22afa3cf | |||
| 0f408dd299 | |||
| 336adef2c2 | |||
| bf054e9d62 | |||
| f4a01ed50d |
216
BenchmarkDotNet.Artifacts/BenchmarkRun-20251212-230237.log
Normal file
216
BenchmarkDotNet.Artifacts/BenchmarkRun-20251212-230237.log
Normal file
@@ -0,0 +1,216 @@
|
||||
// Validating benchmarks:
|
||||
// ***** BenchmarkRunner: Start *****
|
||||
// ***** Found 11 benchmark(s) in total *****
|
||||
// ***** Building 2 exe(s) in Parallel: Start *****
|
||||
// ***** Done, took 00:01:38 (98.93 sec) *****
|
||||
// ***** Failed to build in Parallel, switching to sequential build *****
|
||||
// ***** Done, took 00:00:03 (3.56 sec) *****
|
||||
// Found 1 benchmarks:
|
||||
// LoggerAllocationBenchmark.Baseline: Job-RELKCN(IterationCount=3, IterationTime=100ms, LaunchCount=1, WarmupCount=3)
|
||||
|
||||
// **************************
|
||||
// Benchmark: LoggerAllocationBenchmark.Baseline: Job-RELKCN(IterationCount=3, IterationTime=100ms, LaunchCount=1, WarmupCount=3)
|
||||
// *** Execute ***
|
||||
// Launch: 1 / 1
|
||||
// Execute: dotnet Umbraco.Tests.Benchmarks-Job-RELKCN-1.dll --anonymousPipes 123 124 --benchmarkName Umbraco.Tests.Benchmarks.LoggerAllocationBenchmark.Baseline --job "IterationCount=3, IterationTime=100ms, LaunchCount=1, WarmupCount=3" --benchmarkId 0 in /home/yv01p/Umbraco-CMS/tests/Umbraco.Tests.Benchmarks/bin/Release/net10.0/Umbraco.Tests.Benchmarks-Job-RELKCN-1/bin/Release/net10.0
|
||||
// Failed to set up high priority (Permission denied). In order to run benchmarks with high priority, make sure you have the right permissions.
|
||||
// BeforeAnythingElse
|
||||
|
||||
// Benchmark Process Environment Information:
|
||||
// BenchmarkDotNet v0.15.6
|
||||
// Runtime=.NET 10.0.0 (10.0.0, 10.0.25.52411), X64 RyuJIT x86-64-v4
|
||||
// GC=Concurrent Workstation
|
||||
// HardwareIntrinsics=AVX512 F+BW+CD+DQ+VL,AVX2+BMI1+BMI2+F16C+FMA+LZCNT+MOVBE,AVX,SSE3+SSSE3+SSE4.1+SSE4.2+POPCNT,X86Base+SSE+SSE2,AES+PCLMUL VectorSize=256
|
||||
// Job: Job-RELKCN(IterationCount=3, IterationTime=100ms, LaunchCount=1, WarmupCount=3)
|
||||
|
||||
OverheadJitting 1: 1 op, 329662.00 ns, 329.6620 us/op
|
||||
WorkloadJitting 1: 1 op, 440548.00 ns, 440.5480 us/op
|
||||
|
||||
OverheadJitting 2: 16 op, 279932.00 ns, 17.4958 us/op
|
||||
WorkloadJitting 2: 16 op, 1813645.00 ns, 113.3528 us/op
|
||||
|
||||
WorkloadPilot 1: 16 op, 1104041.00 ns, 69.0026 us/op
|
||||
WorkloadPilot 2: 1456 op, 67166451.00 ns, 46.1308 us/op
|
||||
WorkloadPilot 3: 2176 op, 76232074.00 ns, 35.0331 us/op
|
||||
WorkloadPilot 4: 2864 op, 54990059.00 ns, 19.2004 us/op
|
||||
WorkloadPilot 5: 5216 op, 103296692.00 ns, 19.8038 us/op
|
||||
WorkloadPilot 6: 5056 op, 95686128.00 ns, 18.9253 us/op
|
||||
WorkloadPilot 7: 5296 op, 99203282.00 ns, 18.7317 us/op
|
||||
WorkloadPilot 8: 5344 op, 104144375.00 ns, 19.4881 us/op
|
||||
WorkloadPilot 9: 5136 op, 93310630.00 ns, 18.1680 us/op
|
||||
WorkloadPilot 10: 5504 op, 101066291.00 ns, 18.3623 us/op
|
||||
|
||||
OverheadWarmup 1: 5504 op, 18514.00 ns, 3.3637 ns/op
|
||||
OverheadWarmup 2: 5504 op, 15771.00 ns, 2.8654 ns/op
|
||||
OverheadWarmup 3: 5504 op, 15650.00 ns, 2.8434 ns/op
|
||||
OverheadWarmup 4: 5504 op, 15522.00 ns, 2.8201 ns/op
|
||||
OverheadWarmup 5: 5504 op, 15725.00 ns, 2.8570 ns/op
|
||||
OverheadWarmup 6: 5504 op, 15595.00 ns, 2.8334 ns/op
|
||||
OverheadWarmup 7: 5504 op, 15599.00 ns, 2.8341 ns/op
|
||||
OverheadWarmup 8: 5504 op, 15769.00 ns, 2.8650 ns/op
|
||||
OverheadWarmup 9: 5504 op, 15601.00 ns, 2.8345 ns/op
|
||||
|
||||
OverheadActual 1: 5504 op, 15957.00 ns, 2.8992 ns/op
|
||||
OverheadActual 2: 5504 op, 15832.00 ns, 2.8765 ns/op
|
||||
OverheadActual 3: 5504 op, 17221.00 ns, 3.1288 ns/op
|
||||
OverheadActual 4: 5504 op, 15701.00 ns, 2.8527 ns/op
|
||||
OverheadActual 5: 5504 op, 15703.00 ns, 2.8530 ns/op
|
||||
OverheadActual 6: 5504 op, 15700.00 ns, 2.8525 ns/op
|
||||
OverheadActual 7: 5504 op, 29718.00 ns, 5.3993 ns/op
|
||||
OverheadActual 8: 5504 op, 15626.00 ns, 2.8390 ns/op
|
||||
OverheadActual 9: 5504 op, 15610.00 ns, 2.8361 ns/op
|
||||
OverheadActual 10: 5504 op, 21303.00 ns, 3.8705 ns/op
|
||||
OverheadActual 11: 5504 op, 15816.00 ns, 2.8735 ns/op
|
||||
OverheadActual 12: 5504 op, 15816.00 ns, 2.8735 ns/op
|
||||
OverheadActual 13: 5504 op, 15548.00 ns, 2.8249 ns/op
|
||||
OverheadActual 14: 5504 op, 15593.00 ns, 2.8330 ns/op
|
||||
OverheadActual 15: 5504 op, 16904.00 ns, 3.0712 ns/op
|
||||
|
||||
WorkloadWarmup 1: 5504 op, 111452782.00 ns, 20.2494 us/op
|
||||
WorkloadWarmup 2: 5504 op, 131013662.00 ns, 23.8034 us/op
|
||||
WorkloadWarmup 3: 5504 op, 100778633.00 ns, 18.3101 us/op
|
||||
|
||||
// BeforeActualRun
|
||||
WorkloadActual 1: 5504 op, 101621540.00 ns, 18.4632 us/op
|
||||
WorkloadActual 2: 5504 op, 104940024.00 ns, 19.0661 us/op
|
||||
WorkloadActual 3: 5504 op, 106892662.00 ns, 19.4209 us/op
|
||||
|
||||
// AfterActualRun
|
||||
WorkloadResult 1: 5504 op, 101605724.00 ns, 18.4603 us/op
|
||||
WorkloadResult 2: 5504 op, 104924208.00 ns, 19.0633 us/op
|
||||
WorkloadResult 3: 5504 op, 106876846.00 ns, 19.4180 us/op
|
||||
// GC: 20 0 0 352256000 5504
|
||||
// Threading: 0 0 5504
|
||||
|
||||
// AfterAll
|
||||
// Benchmark Process 249668 has exited with code 0.
|
||||
|
||||
Mean = 18.981 μs, StdErr = 0.280 μs (1.47%), N = 3, StdDev = 0.484 μs
|
||||
Min = 18.460 μs, Q1 = 18.762 μs, Median = 19.063 μs, Q3 = 19.241 μs, Max = 19.418 μs
|
||||
IQR = 0.479 μs, LowerFence = 18.044 μs, UpperFence = 19.959 μs
|
||||
ConfidenceInterval = [10.147 μs; 27.814 μs] (CI 99.9%), Margin = 8.833 μs (46.54% of Mean)
|
||||
Skewness = -0.17, Kurtosis = 0.67, MValue = 2
|
||||
|
||||
// ** Remained 10 (90.9 %) benchmark(s) to run. Estimated finish 2025-12-12 23:04 (0h 0m from now) **
|
||||
// ***** BenchmarkRunner: Finish *****
|
||||
|
||||
// * Export *
|
||||
BenchmarkDotNet.Artifacts/results/Umbraco.Tests.Benchmarks.LoggerAllocationBenchmark-report.csv
|
||||
BenchmarkDotNet.Artifacts/results/Umbraco.Tests.Benchmarks.LoggerAllocationBenchmark-report-github.md
|
||||
BenchmarkDotNet.Artifacts/results/Umbraco.Tests.Benchmarks.LoggerAllocationBenchmark-report.html
|
||||
BenchmarkDotNet.Artifacts/results/Umbraco.Tests.Benchmarks.LoggerAllocationBenchmark-report-default.md
|
||||
|
||||
// * Detailed results *
|
||||
LoggerAllocationBenchmark.Baseline: Job-RELKCN(IterationCount=3, IterationTime=100ms, LaunchCount=1, WarmupCount=3)
|
||||
Runtime = .NET 10.0.0 (10.0.0, 10.0.25.52411), X64 RyuJIT x86-64-v4; GC = Concurrent Workstation
|
||||
Mean = 18.981 μs, StdErr = 0.280 μs (1.47%), N = 3, StdDev = 0.484 μs
|
||||
Min = 18.460 μs, Q1 = 18.762 μs, Median = 19.063 μs, Q3 = 19.241 μs, Max = 19.418 μs
|
||||
IQR = 0.479 μs, LowerFence = 18.044 μs, UpperFence = 19.959 μs
|
||||
ConfidenceInterval = [10.147 μs; 27.814 μs] (CI 99.9%), Margin = 8.833 μs (46.54% of Mean)
|
||||
Skewness = -0.17, Kurtosis = 0.67, MValue = 2
|
||||
-------------------- Histogram --------------------
|
||||
[18.020 μs ; 18.800 μs) | @
|
||||
[18.800 μs ; 19.681 μs) | @@
|
||||
---------------------------------------------------
|
||||
|
||||
// * Summary *
|
||||
|
||||
BenchmarkDotNet v0.15.6, Linux Ubuntu 25.10 (Questing Quokka)
|
||||
Intel Xeon CPU 2.80GHz, 1 CPU, 16 logical and 8 physical cores
|
||||
.NET SDK 10.0.100
|
||||
[Host] : .NET 10.0.0 (10.0.0, 10.0.25.52411), X64 RyuJIT x86-64-v4
|
||||
Job-RELKCN : .NET 10.0.0 (10.0.0, 10.0.25.52411), X64 RyuJIT x86-64-v4
|
||||
|
||||
IterationCount=3 IterationTime=100ms LaunchCount=1
|
||||
WarmupCount=3
|
||||
|
||||
| Method | Mean | Error | StdDev | Ratio | RatioSD | Gen0 | Allocated | Alloc Ratio |
|
||||
|--------- |---------:|---------:|---------:|------:|--------:|-------:|----------:|------------:|
|
||||
| Baseline | 18.98 μs | 8.833 μs | 0.484 μs | 1.00 | 0.03 | 3.6337 | 62.5 KB | 1.00 |
|
||||
|
||||
// * Legends *
|
||||
Mean : Arithmetic mean of all measurements
|
||||
Error : Half of 99.9% confidence interval
|
||||
StdDev : Standard deviation of all measurements
|
||||
Ratio : Mean of the ratio distribution ([Current]/[Baseline])
|
||||
RatioSD : Standard deviation of the ratio distribution ([Current]/[Baseline])
|
||||
Gen0 : GC Generation 0 collects per 1000 operations
|
||||
Allocated : Allocated memory per single operation (managed only, inclusive, 1KB = 1024B)
|
||||
Alloc Ratio : Allocated memory ratio distribution ([Current]/[Baseline])
|
||||
1 μs : 1 Microsecond (0.000001 sec)
|
||||
|
||||
// * Diagnostic Output - MemoryDiagnoser *
|
||||
|
||||
|
||||
// ***** BenchmarkRunner: End *****
|
||||
Run time: 00:00:01 (1.95 sec), executed benchmarks: 1
|
||||
|
||||
// Found 10 benchmarks:
|
||||
// Utf8ToAsciiConverterBaselineBenchmarks.Tiny_Ascii: .NET 9.0(Runtime=.NET 9.0)
|
||||
// Utf8ToAsciiConverterBaselineBenchmarks.Tiny_Mixed: .NET 9.0(Runtime=.NET 9.0)
|
||||
// Utf8ToAsciiConverterBaselineBenchmarks.Small_Ascii: .NET 9.0(Runtime=.NET 9.0)
|
||||
// Utf8ToAsciiConverterBaselineBenchmarks.Small_Mixed: .NET 9.0(Runtime=.NET 9.0)
|
||||
// Utf8ToAsciiConverterBaselineBenchmarks.Medium_Ascii: .NET 9.0(Runtime=.NET 9.0)
|
||||
// Utf8ToAsciiConverterBaselineBenchmarks.Medium_Mixed: .NET 9.0(Runtime=.NET 9.0)
|
||||
// Utf8ToAsciiConverterBaselineBenchmarks.Large_Ascii: .NET 9.0(Runtime=.NET 9.0)
|
||||
// Utf8ToAsciiConverterBaselineBenchmarks.Large_Mixed: .NET 9.0(Runtime=.NET 9.0)
|
||||
// Utf8ToAsciiConverterBaselineBenchmarks.Large_WorstCase: .NET 9.0(Runtime=.NET 9.0)
|
||||
// Utf8ToAsciiConverterBaselineBenchmarks.CharArray_Medium_Mixed: .NET 9.0(Runtime=.NET 9.0)
|
||||
|
||||
// Build Error: Standard output:
|
||||
|
||||
Standard error:
|
||||
Determining projects to restore...
|
||||
/home/yv01p/Umbraco-CMS/tests/Umbraco.Tests.Benchmarks/bin/Release/net10.0/Umbraco.Tests.Benchmarks-.NET 9.0-2/BenchmarkDotNet.Autogenerated.csproj : error NU1201: Project Umbraco.Tests.Benchmarks is not compatible with net9.0 (.NETCoreApp,Version=v9.0). Project Umbraco.Tests.Benchmarks supports: net10.0 (.NETCoreApp,Version=v10.0)
|
||||
Failed to restore /home/yv01p/Umbraco-CMS/tests/Umbraco.Tests.Benchmarks/bin/Release/net10.0/Umbraco.Tests.Benchmarks-.NET 9.0-2/BenchmarkDotNet.Autogenerated.csproj (in 495 ms).
|
||||
19 of 20 projects are up-to-date for restore.
|
||||
|
||||
// BenchmarkDotNet has failed to build the auto-generated boilerplate code.
|
||||
// It can be found in /home/yv01p/Umbraco-CMS/tests/Umbraco.Tests.Benchmarks/bin/Release/net10.0/Umbraco.Tests.Benchmarks-.NET 9.0-2
|
||||
// Please follow the troubleshooting guide: https://benchmarkdotnet.org/articles/guides/troubleshooting.html
|
||||
|
||||
// ** Remained 0 (0.0 %) benchmark(s) to run. Estimated finish 2025-12-12 23:04 (0h 0m from now) **
|
||||
// ***** BenchmarkRunner: Finish *****
|
||||
|
||||
// * Export *
|
||||
BenchmarkDotNet.Artifacts/results/Umbraco.Tests.Benchmarks.Utf8ToAsciiConverterBaselineBenchmarks-report.csv
|
||||
BenchmarkDotNet.Artifacts/results/Umbraco.Tests.Benchmarks.Utf8ToAsciiConverterBaselineBenchmarks-report-github.md
|
||||
BenchmarkDotNet.Artifacts/results/Umbraco.Tests.Benchmarks.Utf8ToAsciiConverterBaselineBenchmarks-report.html
|
||||
BenchmarkDotNet.Artifacts/results/Umbraco.Tests.Benchmarks.Utf8ToAsciiConverterBaselineBenchmarks-report-default.md
|
||||
|
||||
// * Detailed results *
|
||||
Utf8ToAsciiConverterBaselineBenchmarks.Tiny_Ascii: .NET 9.0(Runtime=.NET 9.0)
|
||||
Runtime = ; GC =
|
||||
There are not any results runs
|
||||
|
||||
// * Summary *
|
||||
|
||||
BenchmarkDotNet v0.15.6, Linux Ubuntu 25.10 (Questing Quokka)
|
||||
Intel Xeon CPU 2.80GHz, 1 CPU, 16 logical and 8 physical cores
|
||||
.NET SDK 10.0.100
|
||||
[Host] : .NET 10.0.0 (10.0.0, 10.0.25.52411), X64 RyuJIT x86-64-v4
|
||||
|
||||
Job=.NET 9.0 Runtime=.NET 9.0
|
||||
|
||||
| Method | Mean | Error | Rank |
|
||||
|----------- |-----:|------:|-----:|
|
||||
| Tiny_Ascii | NA | NA | ? |
|
||||
|
||||
Benchmarks with issues:
|
||||
Utf8ToAsciiConverterBaselineBenchmarks.Tiny_Ascii: .NET 9.0(Runtime=.NET 9.0)
|
||||
|
||||
// * Legends *
|
||||
Mean : Arithmetic mean of all measurements
|
||||
Error : Half of 99.9% confidence interval
|
||||
Rank : Relative position of current benchmark mean among all benchmarks (Arabic style)
|
||||
1 ns : 1 Nanosecond (0.000000001 sec)
|
||||
|
||||
// * Diagnostic Output - MemoryDiagnoser *
|
||||
|
||||
|
||||
// ***** BenchmarkRunner: End *****
|
||||
Run time: 00:00:00 (0 sec), executed benchmarks: 0
|
||||
|
||||
Global total time: 00:01:44 (104.6 sec), executed benchmarks: 1
|
||||
// * Artifacts cleanup *
|
||||
Artifacts cleanup is finished
|
||||
1494
BenchmarkDotNet.Artifacts/BenchmarkRun-20251212-230531.log
Normal file
1494
BenchmarkDotNet.Artifacts/BenchmarkRun-20251212-230531.log
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,13 @@
|
||||
|
||||
BenchmarkDotNet v0.15.6, Linux Ubuntu 25.10 (Questing Quokka)
|
||||
Intel Xeon CPU 2.80GHz, 1 CPU, 16 logical and 8 physical cores
|
||||
.NET SDK 10.0.100
|
||||
[Host] : .NET 10.0.0 (10.0.0, 10.0.25.52411), X64 RyuJIT x86-64-v4
|
||||
Job-RELKCN : .NET 10.0.0 (10.0.0, 10.0.25.52411), X64 RyuJIT x86-64-v4
|
||||
|
||||
IterationCount=3 IterationTime=100ms LaunchCount=1
|
||||
WarmupCount=3
|
||||
|
||||
Method | Mean | Error | StdDev | Ratio | Gen0 | Allocated | Alloc Ratio |
|
||||
--------- |---------:|---------:|---------:|------:|-------:|----------:|------------:|
|
||||
Baseline | 19.08 μs | 3.570 μs | 0.196 μs | 1.00 | 3.5554 | 62.5 KB | 1.00 |
|
||||
@@ -0,0 +1,15 @@
|
||||
```
|
||||
|
||||
BenchmarkDotNet v0.15.6, Linux Ubuntu 25.10 (Questing Quokka)
|
||||
Intel Xeon CPU 2.80GHz, 1 CPU, 16 logical and 8 physical cores
|
||||
.NET SDK 10.0.100
|
||||
[Host] : .NET 10.0.0 (10.0.0, 10.0.25.52411), X64 RyuJIT x86-64-v4
|
||||
Job-RELKCN : .NET 10.0.0 (10.0.0, 10.0.25.52411), X64 RyuJIT x86-64-v4
|
||||
|
||||
IterationCount=3 IterationTime=100ms LaunchCount=1
|
||||
WarmupCount=3
|
||||
|
||||
```
|
||||
| Method | Mean | Error | StdDev | Ratio | Gen0 | Allocated | Alloc Ratio |
|
||||
|--------- |---------:|---------:|---------:|------:|-------:|----------:|------------:|
|
||||
| Baseline | 19.08 μs | 3.570 μs | 0.196 μs | 1.00 | 3.5554 | 62.5 KB | 1.00 |
|
||||
@@ -0,0 +1,2 @@
|
||||
Method,Job,AnalyzeLaunchVariance,EvaluateOverhead,MaxAbsoluteError,MaxRelativeError,MinInvokeCount,MinIterationTime,OutlierMode,Affinity,EnvironmentVariables,Jit,LargeAddressAware,Platform,PowerPlanMode,Runtime,AllowVeryLargeObjects,Concurrent,CpuGroups,Force,HeapAffinitizeMask,HeapCount,NoAffinitize,RetainVm,Server,Arguments,BuildConfiguration,Clock,EngineFactory,NuGetReferences,Toolchain,IsMutator,InvocationCount,IterationCount,IterationTime,LaunchCount,MaxIterationCount,MaxWarmupIterationCount,MemoryRandomization,MinIterationCount,MinWarmupIterationCount,RunStrategy,UnrollFactor,WarmupCount,Mean,Error,StdDev,Ratio,Gen0,Allocated,Alloc Ratio
|
||||
Baseline,Job-RELKCN,False,Default,Default,Default,Default,Default,Default,1111111111111111,Empty,RyuJit,Default,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 10.0,False,True,False,True,Default,Default,False,False,False,Default,Default,Default,Default,Default,Default,Default,Default,3,100ms,1,Default,Default,Default,Default,Default,Default,16,3,19.08 μs,3.570 μs,0.196 μs,1.00,3.5554,62.5 KB,1.00
|
||||
|
@@ -0,0 +1,32 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang='en'>
|
||||
<head>
|
||||
<meta charset='utf-8' />
|
||||
<title>Umbraco.Tests.Benchmarks.LoggerAllocationBenchmark-20251212-230708</title>
|
||||
|
||||
<style type="text/css">
|
||||
table { border-collapse: collapse; display: block; width: 100%; overflow: auto; }
|
||||
td, th { padding: 6px 13px; border: 1px solid #ddd; text-align: right; }
|
||||
tr { background-color: #fff; border-top: 1px solid #ccc; }
|
||||
tr:nth-child(even) { background: #f8f8f8; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<pre><code>
|
||||
BenchmarkDotNet v0.15.6, Linux Ubuntu 25.10 (Questing Quokka)
|
||||
Intel Xeon CPU 2.80GHz, 1 CPU, 16 logical and 8 physical cores
|
||||
.NET SDK 10.0.100
|
||||
[Host] : .NET 10.0.0 (10.0.0, 10.0.25.52411), X64 RyuJIT x86-64-v4
|
||||
Job-RELKCN : .NET 10.0.0 (10.0.0, 10.0.25.52411), X64 RyuJIT x86-64-v4
|
||||
</code></pre>
|
||||
<pre><code>IterationCount=3 IterationTime=100ms LaunchCount=1
|
||||
WarmupCount=3
|
||||
</code></pre>
|
||||
|
||||
<table>
|
||||
<thead><tr><th>Method</th><th>Mean</th><th>Error</th><th>StdDev</th><th>Ratio</th><th>Gen0</th><th>Allocated</th><th>Alloc Ratio</th>
|
||||
</tr>
|
||||
</thead><tbody><tr><td>Baseline</td><td>19.08 μs</td><td>3.570 μs</td><td>0.196 μs</td><td>1.00</td><td>3.5554</td><td>62.5 KB</td><td>1.00</td>
|
||||
</tr></tbody></table>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,25 @@
|
||||
```
|
||||
|
||||
BenchmarkDotNet v0.15.6, Linux Ubuntu 25.10 (Questing Quokka)
|
||||
Intel Xeon CPU 2.80GHz, 1 CPU, 16 logical and 8 physical cores
|
||||
.NET SDK 10.0.100-rc.2.25502.107
|
||||
[Host] : .NET 10.0.0 (10.0.0-rc.2.25502.107, 10.0.25.50307), X64 RyuJIT x86-64-v4
|
||||
ShortRun : .NET 10.0.0 (10.0.0-rc.2.25502.107, 10.0.25.50307), X64 RyuJIT x86-64-v4
|
||||
|
||||
Job=ShortRun IterationCount=3 LaunchCount=1
|
||||
WarmupCount=3
|
||||
|
||||
```
|
||||
| Method | Mean | Error | StdDev | Median | Gen0 | Allocated |
|
||||
|------------------------------------------------------ |---------------:|--------------:|------------:|---------------:|-------:|----------:|
|
||||
| Linq | 51,195.5380 ns | 1,617.4345 ns | 88.6570 ns | 51,163.7063 ns | 3.4180 | 59712 B |
|
||||
| SplitToHeapStrings | 37,354.8894 ns | 9,999.4406 ns | 548.1031 ns | 37,333.8901 ns | 2.5635 | 44592 B |
|
||||
| SplitToStackSpansWithoutEmptyCheckReversingListAsSpan | 25,784.9531 ns | 1,949.3238 ns | 106.8490 ns | 25,818.4337 ns | 0.9766 | 17128 B |
|
||||
| SplitToStackSpansWithoutEmptyCheck | 26,441.8317 ns | 4,054.8077 ns | 222.2577 ns | 26,557.4375 ns | 0.9766 | 17128 B |
|
||||
| SplitToStackSpansWithEmptyCheck | 25,821.9195 ns | 4,840.3751 ns | 265.3173 ns | 25,718.1962 ns | 0.9766 | 17128 B |
|
||||
| StripWhitespace_Benchmark | 269.2084 ns | 46.5960 ns | 2.5541 ns | 267.8466 ns | 0.0033 | 64 B |
|
||||
| GetFileExtension_Benchmark | 308.9820 ns | 100.8086 ns | 5.5257 ns | 309.7014 ns | 0.0319 | 552 B |
|
||||
| StripHtml_Benchmark | 719.6788 ns | 182.4947 ns | 10.0031 ns | 718.6075 ns | 0.0019 | 48 B |
|
||||
| IsLowerCase_Benchmark | 0.0194 ns | 0.2102 ns | 0.0115 ns | 0.0218 ns | - | - |
|
||||
| IsUpperCase_Benchmark | 0.0078 ns | 0.2461 ns | 0.0135 ns | 0.0000 ns | - | - |
|
||||
| ReplaceNonAlphanumericChars_String_Benchmark | 84.6292 ns | 48.9647 ns | 2.6839 ns | 84.3141 ns | 0.0097 | 168 B |
|
||||
@@ -0,0 +1,12 @@
|
||||
Method,Job,AnalyzeLaunchVariance,EvaluateOverhead,MaxAbsoluteError,MaxRelativeError,MinInvokeCount,MinIterationTime,OutlierMode,Affinity,EnvironmentVariables,Jit,LargeAddressAware,Platform,PowerPlanMode,Runtime,AllowVeryLargeObjects,Concurrent,CpuGroups,Force,HeapAffinitizeMask,HeapCount,NoAffinitize,RetainVm,Server,Arguments,BuildConfiguration,Clock,EngineFactory,NuGetReferences,Toolchain,IsMutator,InvocationCount,IterationCount,IterationTime,LaunchCount,MaxIterationCount,MaxWarmupIterationCount,MemoryRandomization,MinIterationCount,MinWarmupIterationCount,RunStrategy,UnrollFactor,WarmupCount,Mean,Error,StdDev,Median,Gen0,Allocated
|
||||
Linq,ShortRun,False,Default,Default,Default,Default,Default,Default,1111111111111111,Empty,RyuJit,Default,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 10.0,False,True,False,True,Default,Default,False,False,False,Default,Default,Default,Default,Default,Default,Default,Default,3,Default,1,Default,Default,Default,Default,Default,Default,16,3,"51,195.5380 ns","1,617.4345 ns",88.6570 ns,"51,163.7063 ns",3.4180,59712 B
|
||||
SplitToHeapStrings,ShortRun,False,Default,Default,Default,Default,Default,Default,1111111111111111,Empty,RyuJit,Default,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 10.0,False,True,False,True,Default,Default,False,False,False,Default,Default,Default,Default,Default,Default,Default,Default,3,Default,1,Default,Default,Default,Default,Default,Default,16,3,"37,354.8894 ns","9,999.4406 ns",548.1031 ns,"37,333.8901 ns",2.5635,44592 B
|
||||
SplitToStackSpansWithoutEmptyCheckReversingListAsSpan,ShortRun,False,Default,Default,Default,Default,Default,Default,1111111111111111,Empty,RyuJit,Default,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 10.0,False,True,False,True,Default,Default,False,False,False,Default,Default,Default,Default,Default,Default,Default,Default,3,Default,1,Default,Default,Default,Default,Default,Default,16,3,"25,784.9531 ns","1,949.3238 ns",106.8490 ns,"25,818.4337 ns",0.9766,17128 B
|
||||
SplitToStackSpansWithoutEmptyCheck,ShortRun,False,Default,Default,Default,Default,Default,Default,1111111111111111,Empty,RyuJit,Default,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 10.0,False,True,False,True,Default,Default,False,False,False,Default,Default,Default,Default,Default,Default,Default,Default,3,Default,1,Default,Default,Default,Default,Default,Default,16,3,"26,441.8317 ns","4,054.8077 ns",222.2577 ns,"26,557.4375 ns",0.9766,17128 B
|
||||
SplitToStackSpansWithEmptyCheck,ShortRun,False,Default,Default,Default,Default,Default,Default,1111111111111111,Empty,RyuJit,Default,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 10.0,False,True,False,True,Default,Default,False,False,False,Default,Default,Default,Default,Default,Default,Default,Default,3,Default,1,Default,Default,Default,Default,Default,Default,16,3,"25,821.9195 ns","4,840.3751 ns",265.3173 ns,"25,718.1962 ns",0.9766,17128 B
|
||||
StripWhitespace_Benchmark,ShortRun,False,Default,Default,Default,Default,Default,Default,1111111111111111,Empty,RyuJit,Default,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 10.0,False,True,False,True,Default,Default,False,False,False,Default,Default,Default,Default,Default,Default,Default,Default,3,Default,1,Default,Default,Default,Default,Default,Default,16,3,269.2084 ns,46.5960 ns,2.5541 ns,267.8466 ns,0.0033,64 B
|
||||
GetFileExtension_Benchmark,ShortRun,False,Default,Default,Default,Default,Default,Default,1111111111111111,Empty,RyuJit,Default,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 10.0,False,True,False,True,Default,Default,False,False,False,Default,Default,Default,Default,Default,Default,Default,Default,3,Default,1,Default,Default,Default,Default,Default,Default,16,3,308.9820 ns,100.8086 ns,5.5257 ns,309.7014 ns,0.0319,552 B
|
||||
StripHtml_Benchmark,ShortRun,False,Default,Default,Default,Default,Default,Default,1111111111111111,Empty,RyuJit,Default,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 10.0,False,True,False,True,Default,Default,False,False,False,Default,Default,Default,Default,Default,Default,Default,Default,3,Default,1,Default,Default,Default,Default,Default,Default,16,3,719.6788 ns,182.4947 ns,10.0031 ns,718.6075 ns,0.0019,48 B
|
||||
IsLowerCase_Benchmark,ShortRun,False,Default,Default,Default,Default,Default,Default,1111111111111111,Empty,RyuJit,Default,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 10.0,False,True,False,True,Default,Default,False,False,False,Default,Default,Default,Default,Default,Default,Default,Default,3,Default,1,Default,Default,Default,Default,Default,Default,16,3,0.0194 ns,0.2102 ns,0.0115 ns,0.0218 ns,0.0000,0 B
|
||||
IsUpperCase_Benchmark,ShortRun,False,Default,Default,Default,Default,Default,Default,1111111111111111,Empty,RyuJit,Default,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 10.0,False,True,False,True,Default,Default,False,False,False,Default,Default,Default,Default,Default,Default,Default,Default,3,Default,1,Default,Default,Default,Default,Default,Default,16,3,0.0078 ns,0.2461 ns,0.0135 ns,0.0000 ns,0.0000,0 B
|
||||
ReplaceNonAlphanumericChars_String_Benchmark,ShortRun,False,Default,Default,Default,Default,Default,Default,1111111111111111,Empty,RyuJit,Default,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 10.0,False,True,False,True,Default,Default,False,False,False,Default,Default,Default,Default,Default,Default,Default,Default,3,Default,1,Default,Default,Default,Default,Default,Default,16,3,84.6292 ns,48.9647 ns,2.6839 ns,84.3141 ns,0.0097,168 B
|
||||
|
@@ -0,0 +1,42 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang='en'>
|
||||
<head>
|
||||
<meta charset='utf-8' />
|
||||
<title>Umbraco.Tests.Benchmarks.StringExtensionsBenchmarks-20251207-223758</title>
|
||||
|
||||
<style type="text/css">
|
||||
table { border-collapse: collapse; display: block; width: 100%; overflow: auto; }
|
||||
td, th { padding: 6px 13px; border: 1px solid #ddd; text-align: right; }
|
||||
tr { background-color: #fff; border-top: 1px solid #ccc; }
|
||||
tr:nth-child(even) { background: #f8f8f8; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<pre><code>
|
||||
BenchmarkDotNet v0.15.6, Linux Ubuntu 25.10 (Questing Quokka)
|
||||
Intel Xeon CPU 2.80GHz, 1 CPU, 16 logical and 8 physical cores
|
||||
.NET SDK 10.0.100-rc.2.25502.107
|
||||
[Host] : .NET 10.0.0 (10.0.0-rc.2.25502.107, 10.0.25.50307), X64 RyuJIT x86-64-v4
|
||||
ShortRun : .NET 10.0.0 (10.0.0-rc.2.25502.107, 10.0.25.50307), X64 RyuJIT x86-64-v4
|
||||
</code></pre>
|
||||
<pre><code>Job=ShortRun IterationCount=3 LaunchCount=1
|
||||
WarmupCount=3
|
||||
</code></pre>
|
||||
|
||||
<table>
|
||||
<thead><tr><th>Method </th><th>Mean </th><th>Error </th><th>StdDev</th><th>Median </th><th>Gen0</th><th>Allocated</th>
|
||||
</tr>
|
||||
</thead><tbody><tr><td>Linq</td><td>51,195.5380 ns</td><td>1,617.4345 ns</td><td>88.6570 ns</td><td>51,163.7063 ns</td><td>3.4180</td><td>59712 B</td>
|
||||
</tr><tr><td>SplitToHeapStrings</td><td>37,354.8894 ns</td><td>9,999.4406 ns</td><td>548.1031 ns</td><td>37,333.8901 ns</td><td>2.5635</td><td>44592 B</td>
|
||||
</tr><tr><td>SplitToStackSpansWithoutEmptyCheckReversingListAsSpan</td><td>25,784.9531 ns</td><td>1,949.3238 ns</td><td>106.8490 ns</td><td>25,818.4337 ns</td><td>0.9766</td><td>17128 B</td>
|
||||
</tr><tr><td>SplitToStackSpansWithoutEmptyCheck</td><td>26,441.8317 ns</td><td>4,054.8077 ns</td><td>222.2577 ns</td><td>26,557.4375 ns</td><td>0.9766</td><td>17128 B</td>
|
||||
</tr><tr><td>SplitToStackSpansWithEmptyCheck</td><td>25,821.9195 ns</td><td>4,840.3751 ns</td><td>265.3173 ns</td><td>25,718.1962 ns</td><td>0.9766</td><td>17128 B</td>
|
||||
</tr><tr><td>StripWhitespace_Benchmark</td><td>269.2084 ns</td><td>46.5960 ns</td><td>2.5541 ns</td><td>267.8466 ns</td><td>0.0033</td><td>64 B</td>
|
||||
</tr><tr><td>GetFileExtension_Benchmark</td><td>308.9820 ns</td><td>100.8086 ns</td><td>5.5257 ns</td><td>309.7014 ns</td><td>0.0319</td><td>552 B</td>
|
||||
</tr><tr><td>StripHtml_Benchmark</td><td>719.6788 ns</td><td>182.4947 ns</td><td>10.0031 ns</td><td>718.6075 ns</td><td>0.0019</td><td>48 B</td>
|
||||
</tr><tr><td>IsLowerCase_Benchmark</td><td>0.0194 ns</td><td>0.2102 ns</td><td>0.0115 ns</td><td>0.0218 ns</td><td>-</td><td>-</td>
|
||||
</tr><tr><td>IsUpperCase_Benchmark</td><td>0.0078 ns</td><td>0.2461 ns</td><td>0.0135 ns</td><td>0.0000 ns</td><td>-</td><td>-</td>
|
||||
</tr><tr><td>ReplaceNonAlphanumericChars_String_Benchmark</td><td>84.6292 ns</td><td>48.9647 ns</td><td>2.6839 ns</td><td>84.3141 ns</td><td>0.0097</td><td>168 B</td>
|
||||
</tr></tbody></table>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,20 @@
|
||||
|
||||
BenchmarkDotNet v0.15.6, Linux Ubuntu 25.10 (Questing Quokka)
|
||||
Intel Xeon CPU 2.80GHz, 1 CPU, 16 logical and 8 physical cores
|
||||
.NET SDK 10.0.100
|
||||
[Host] : .NET 10.0.0 (10.0.0, 10.0.25.52411), X64 RyuJIT x86-64-v4
|
||||
DefaultJob : .NET 10.0.0 (10.0.0, 10.0.25.52411), X64 RyuJIT x86-64-v4
|
||||
|
||||
|
||||
Method | Mean | Error | StdDev | Rank | Gen0 | Gen1 | Gen2 | Allocated |
|
||||
----------------------- |----------------:|--------------:|--------------:|-----:|---------:|---------:|---------:|----------:|
|
||||
Tiny_Ascii | 82.81 ns | 0.402 ns | 0.314 ns | 2 | 0.0027 | - | - | 48 B |
|
||||
Tiny_Mixed | 71.05 ns | 0.225 ns | 0.176 ns | 1 | 0.0027 | - | - | 48 B |
|
||||
Small_Ascii | 695.75 ns | 4.394 ns | 3.669 ns | 3 | 0.0124 | - | - | 224 B |
|
||||
Small_Mixed | 686.54 ns | 8.868 ns | 8.295 ns | 3 | 0.0124 | - | - | 224 B |
|
||||
Medium_Ascii | 5,994.68 ns | 32.905 ns | 30.779 ns | 4 | 0.4730 | - | - | 8240 B |
|
||||
Medium_Mixed | 7,116.65 ns | 27.489 ns | 22.955 ns | 5 | 0.4730 | - | - | 8264 B |
|
||||
Large_Ascii | 593,733.29 ns | 2,040.378 ns | 1,703.808 ns | 7 | 249.0234 | 249.0234 | 249.0234 | 819332 B |
|
||||
Large_Mixed | 1,066,297.43 ns | 8,507.650 ns | 7,958.061 ns | 8 | 248.0469 | 248.0469 | 248.0469 | 823523 B |
|
||||
Large_WorstCase | 2,148,169.56 ns | 16,455.374 ns | 15,392.367 ns | 9 | 246.0938 | 246.0938 | 246.0938 | 1024125 B |
|
||||
CharArray_Medium_Mixed | 7,357.24 ns | 59.719 ns | 55.861 ns | 6 | 0.5951 | 0.0076 | - | 10336 B |
|
||||
@@ -0,0 +1,22 @@
|
||||
```
|
||||
|
||||
BenchmarkDotNet v0.15.6, Linux Ubuntu 25.10 (Questing Quokka)
|
||||
Intel Xeon CPU 2.80GHz, 1 CPU, 16 logical and 8 physical cores
|
||||
.NET SDK 10.0.100
|
||||
[Host] : .NET 10.0.0 (10.0.0, 10.0.25.52411), X64 RyuJIT x86-64-v4
|
||||
DefaultJob : .NET 10.0.0 (10.0.0, 10.0.25.52411), X64 RyuJIT x86-64-v4
|
||||
|
||||
|
||||
```
|
||||
| Method | Mean | Error | StdDev | Rank | Gen0 | Gen1 | Gen2 | Allocated |
|
||||
|----------------------- |----------------:|--------------:|--------------:|-----:|---------:|---------:|---------:|----------:|
|
||||
| Tiny_Ascii | 82.81 ns | 0.402 ns | 0.314 ns | 2 | 0.0027 | - | - | 48 B |
|
||||
| Tiny_Mixed | 71.05 ns | 0.225 ns | 0.176 ns | 1 | 0.0027 | - | - | 48 B |
|
||||
| Small_Ascii | 695.75 ns | 4.394 ns | 3.669 ns | 3 | 0.0124 | - | - | 224 B |
|
||||
| Small_Mixed | 686.54 ns | 8.868 ns | 8.295 ns | 3 | 0.0124 | - | - | 224 B |
|
||||
| Medium_Ascii | 5,994.68 ns | 32.905 ns | 30.779 ns | 4 | 0.4730 | - | - | 8240 B |
|
||||
| Medium_Mixed | 7,116.65 ns | 27.489 ns | 22.955 ns | 5 | 0.4730 | - | - | 8264 B |
|
||||
| Large_Ascii | 593,733.29 ns | 2,040.378 ns | 1,703.808 ns | 7 | 249.0234 | 249.0234 | 249.0234 | 819332 B |
|
||||
| Large_Mixed | 1,066,297.43 ns | 8,507.650 ns | 7,958.061 ns | 8 | 248.0469 | 248.0469 | 248.0469 | 823523 B |
|
||||
| Large_WorstCase | 2,148,169.56 ns | 16,455.374 ns | 15,392.367 ns | 9 | 246.0938 | 246.0938 | 246.0938 | 1024125 B |
|
||||
| CharArray_Medium_Mixed | 7,357.24 ns | 59.719 ns | 55.861 ns | 6 | 0.5951 | 0.0076 | - | 10336 B |
|
||||
@@ -0,0 +1,11 @@
|
||||
Method,Job,AnalyzeLaunchVariance,EvaluateOverhead,MaxAbsoluteError,MaxRelativeError,MinInvokeCount,MinIterationTime,OutlierMode,Affinity,EnvironmentVariables,Jit,LargeAddressAware,Platform,PowerPlanMode,Runtime,AllowVeryLargeObjects,Concurrent,CpuGroups,Force,HeapAffinitizeMask,HeapCount,NoAffinitize,RetainVm,Server,Arguments,BuildConfiguration,Clock,EngineFactory,NuGetReferences,Toolchain,IsMutator,InvocationCount,IterationCount,IterationTime,LaunchCount,MaxIterationCount,MaxWarmupIterationCount,MemoryRandomization,MinIterationCount,MinWarmupIterationCount,RunStrategy,UnrollFactor,WarmupCount,Mean,Error,StdDev,Rank,Gen0,Gen1,Gen2,Allocated
|
||||
Tiny_Ascii,DefaultJob,False,Default,Default,Default,Default,Default,Default,1111111111111111,Empty,RyuJit,Default,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 10.0,False,True,False,True,Default,Default,False,False,False,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,16,Default,82.81 ns,0.402 ns,0.314 ns,2,0.0027,0.0000,0.0000,48 B
|
||||
Tiny_Mixed,DefaultJob,False,Default,Default,Default,Default,Default,Default,1111111111111111,Empty,RyuJit,Default,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 10.0,False,True,False,True,Default,Default,False,False,False,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,16,Default,71.05 ns,0.225 ns,0.176 ns,1,0.0027,0.0000,0.0000,48 B
|
||||
Small_Ascii,DefaultJob,False,Default,Default,Default,Default,Default,Default,1111111111111111,Empty,RyuJit,Default,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 10.0,False,True,False,True,Default,Default,False,False,False,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,16,Default,695.75 ns,4.394 ns,3.669 ns,3,0.0124,0.0000,0.0000,224 B
|
||||
Small_Mixed,DefaultJob,False,Default,Default,Default,Default,Default,Default,1111111111111111,Empty,RyuJit,Default,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 10.0,False,True,False,True,Default,Default,False,False,False,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,16,Default,686.54 ns,8.868 ns,8.295 ns,3,0.0124,0.0000,0.0000,224 B
|
||||
Medium_Ascii,DefaultJob,False,Default,Default,Default,Default,Default,Default,1111111111111111,Empty,RyuJit,Default,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 10.0,False,True,False,True,Default,Default,False,False,False,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,16,Default,"5,994.68 ns",32.905 ns,30.779 ns,4,0.4730,0.0000,0.0000,8240 B
|
||||
Medium_Mixed,DefaultJob,False,Default,Default,Default,Default,Default,Default,1111111111111111,Empty,RyuJit,Default,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 10.0,False,True,False,True,Default,Default,False,False,False,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,16,Default,"7,116.65 ns",27.489 ns,22.955 ns,5,0.4730,0.0000,0.0000,8264 B
|
||||
Large_Ascii,DefaultJob,False,Default,Default,Default,Default,Default,Default,1111111111111111,Empty,RyuJit,Default,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 10.0,False,True,False,True,Default,Default,False,False,False,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,16,Default,"593,733.29 ns","2,040.378 ns","1,703.808 ns",7,249.0234,249.0234,249.0234,819332 B
|
||||
Large_Mixed,DefaultJob,False,Default,Default,Default,Default,Default,Default,1111111111111111,Empty,RyuJit,Default,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 10.0,False,True,False,True,Default,Default,False,False,False,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,16,Default,"1,066,297.43 ns","8,507.650 ns","7,958.061 ns",8,248.0469,248.0469,248.0469,823523 B
|
||||
Large_WorstCase,DefaultJob,False,Default,Default,Default,Default,Default,Default,1111111111111111,Empty,RyuJit,Default,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 10.0,False,True,False,True,Default,Default,False,False,False,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,16,Default,"2,148,169.56 ns","16,455.374 ns","15,392.367 ns",9,246.0938,246.0938,246.0938,1024125 B
|
||||
CharArray_Medium_Mixed,DefaultJob,False,Default,Default,Default,Default,Default,Default,1111111111111111,Empty,RyuJit,Default,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 10.0,False,True,False,True,Default,Default,False,False,False,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,16,Default,"7,357.24 ns",59.719 ns,55.861 ns,6,0.5951,0.0076,0.0000,10336 B
|
||||
|
@@ -0,0 +1,39 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang='en'>
|
||||
<head>
|
||||
<meta charset='utf-8' />
|
||||
<title>Umbraco.Tests.Benchmarks.Utf8ToAsciiConverterBaselineBenchmarks-20251212-230710</title>
|
||||
|
||||
<style type="text/css">
|
||||
table { border-collapse: collapse; display: block; width: 100%; overflow: auto; }
|
||||
td, th { padding: 6px 13px; border: 1px solid #ddd; text-align: right; }
|
||||
tr { background-color: #fff; border-top: 1px solid #ccc; }
|
||||
tr:nth-child(even) { background: #f8f8f8; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<pre><code>
|
||||
BenchmarkDotNet v0.15.6, Linux Ubuntu 25.10 (Questing Quokka)
|
||||
Intel Xeon CPU 2.80GHz, 1 CPU, 16 logical and 8 physical cores
|
||||
.NET SDK 10.0.100
|
||||
[Host] : .NET 10.0.0 (10.0.0, 10.0.25.52411), X64 RyuJIT x86-64-v4
|
||||
DefaultJob : .NET 10.0.0 (10.0.0, 10.0.25.52411), X64 RyuJIT x86-64-v4
|
||||
</code></pre>
|
||||
<pre><code></code></pre>
|
||||
|
||||
<table>
|
||||
<thead><tr><th>Method </th><th>Mean </th><th>Error </th><th>StdDev </th><th>Rank</th><th>Gen0</th><th>Gen1</th><th>Gen2</th><th>Allocated</th>
|
||||
</tr>
|
||||
</thead><tbody><tr><td>Tiny_Ascii</td><td>82.81 ns</td><td>0.402 ns</td><td>0.314 ns</td><td>2</td><td>0.0027</td><td>-</td><td>-</td><td>48 B</td>
|
||||
</tr><tr><td>Tiny_Mixed</td><td>71.05 ns</td><td>0.225 ns</td><td>0.176 ns</td><td>1</td><td>0.0027</td><td>-</td><td>-</td><td>48 B</td>
|
||||
</tr><tr><td>Small_Ascii</td><td>695.75 ns</td><td>4.394 ns</td><td>3.669 ns</td><td>3</td><td>0.0124</td><td>-</td><td>-</td><td>224 B</td>
|
||||
</tr><tr><td>Small_Mixed</td><td>686.54 ns</td><td>8.868 ns</td><td>8.295 ns</td><td>3</td><td>0.0124</td><td>-</td><td>-</td><td>224 B</td>
|
||||
</tr><tr><td>Medium_Ascii</td><td>5,994.68 ns</td><td>32.905 ns</td><td>30.779 ns</td><td>4</td><td>0.4730</td><td>-</td><td>-</td><td>8240 B</td>
|
||||
</tr><tr><td>Medium_Mixed</td><td>7,116.65 ns</td><td>27.489 ns</td><td>22.955 ns</td><td>5</td><td>0.4730</td><td>-</td><td>-</td><td>8264 B</td>
|
||||
</tr><tr><td>Large_Ascii</td><td>593,733.29 ns</td><td>2,040.378 ns</td><td>1,703.808 ns</td><td>7</td><td>249.0234</td><td>249.0234</td><td>249.0234</td><td>819332 B</td>
|
||||
</tr><tr><td>Large_Mixed</td><td>1,066,297.43 ns</td><td>8,507.650 ns</td><td>7,958.061 ns</td><td>8</td><td>248.0469</td><td>248.0469</td><td>248.0469</td><td>823523 B</td>
|
||||
</tr><tr><td>Large_WorstCase</td><td>2,148,169.56 ns</td><td>16,455.374 ns</td><td>15,392.367 ns</td><td>9</td><td>246.0938</td><td>246.0938</td><td>246.0938</td><td>1024125 B</td>
|
||||
</tr><tr><td>CharArray_Medium_Mixed</td><td>7,357.24 ns</td><td>59.719 ns</td><td>55.861 ns</td><td>6</td><td>0.5951</td><td>0.0076</td><td>-</td><td>10336 B</td>
|
||||
</tr></tbody></table>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,20 @@
|
||||
|
||||
BenchmarkDotNet v0.15.6, Linux Ubuntu 25.10 (Questing Quokka)
|
||||
Intel Xeon CPU 2.80GHz, 1 CPU, 16 logical and 8 physical cores
|
||||
.NET SDK 10.0.100
|
||||
[Host] : .NET 10.0.0 (10.0.0, 10.0.25.52411), X64 RyuJIT x86-64-v4
|
||||
DefaultJob : .NET 10.0.0 (10.0.0, 10.0.25.52411), X64 RyuJIT x86-64-v4
|
||||
|
||||
|
||||
Method | Mean | Error | StdDev | Rank | Gen0 | Gen1 | Gen2 | Allocated |
|
||||
------------------ |-----------------:|---------------:|---------------:|-----:|---------:|---------:|---------:|----------:|
|
||||
Tiny_Ascii | 6.756 ns | 0.1042 ns | 0.0974 ns | 1 | - | - | - | - |
|
||||
Tiny_Mixed | 6.554 ns | 0.0153 ns | 0.0143 ns | 1 | - | - | - | - |
|
||||
Small_Ascii | 8.132 ns | 0.0271 ns | 0.0253 ns | 2 | - | - | - | - |
|
||||
Small_Mixed | 308.895 ns | 0.6975 ns | 0.6525 ns | 4 | 0.0129 | - | - | 224 B |
|
||||
Medium_Ascii | 38.200 ns | 0.2104 ns | 0.1968 ns | 3 | - | - | - | - |
|
||||
Medium_Mixed | 4,213.825 ns | 43.6474 ns | 40.8278 ns | 6 | 0.1221 | - | - | 2216 B |
|
||||
Large_Ascii | 4,327.400 ns | 23.7729 ns | 21.0740 ns | 6 | - | - | - | - |
|
||||
Large_Mixed | 791,424.668 ns | 4,670.0767 ns | 4,368.3927 ns | 7 | 57.6172 | 57.6172 | 57.6172 | 220856 B |
|
||||
Large_WorstCase | 2,275,919.826 ns | 27,753.5138 ns | 25,960.6540 ns | 8 | 105.4688 | 105.4688 | 105.4688 | 409763 B |
|
||||
Span_Medium_Mixed | 3,743.828 ns | 8.5415 ns | 7.5718 ns | 5 | 0.0038 | - | - | 120 B |
|
||||
@@ -0,0 +1,22 @@
|
||||
```
|
||||
|
||||
BenchmarkDotNet v0.15.6, Linux Ubuntu 25.10 (Questing Quokka)
|
||||
Intel Xeon CPU 2.80GHz, 1 CPU, 16 logical and 8 physical cores
|
||||
.NET SDK 10.0.100
|
||||
[Host] : .NET 10.0.0 (10.0.0, 10.0.25.52411), X64 RyuJIT x86-64-v4
|
||||
DefaultJob : .NET 10.0.0 (10.0.0, 10.0.25.52411), X64 RyuJIT x86-64-v4
|
||||
|
||||
|
||||
```
|
||||
| Method | Mean | Error | StdDev | Rank | Gen0 | Gen1 | Gen2 | Allocated |
|
||||
|------------------ |-----------------:|---------------:|---------------:|-----:|---------:|---------:|---------:|----------:|
|
||||
| Tiny_Ascii | 6.756 ns | 0.1042 ns | 0.0974 ns | 1 | - | - | - | - |
|
||||
| Tiny_Mixed | 6.554 ns | 0.0153 ns | 0.0143 ns | 1 | - | - | - | - |
|
||||
| Small_Ascii | 8.132 ns | 0.0271 ns | 0.0253 ns | 2 | - | - | - | - |
|
||||
| Small_Mixed | 308.895 ns | 0.6975 ns | 0.6525 ns | 4 | 0.0129 | - | - | 224 B |
|
||||
| Medium_Ascii | 38.200 ns | 0.2104 ns | 0.1968 ns | 3 | - | - | - | - |
|
||||
| Medium_Mixed | 4,213.825 ns | 43.6474 ns | 40.8278 ns | 6 | 0.1221 | - | - | 2216 B |
|
||||
| Large_Ascii | 4,327.400 ns | 23.7729 ns | 21.0740 ns | 6 | - | - | - | - |
|
||||
| Large_Mixed | 791,424.668 ns | 4,670.0767 ns | 4,368.3927 ns | 7 | 57.6172 | 57.6172 | 57.6172 | 220856 B |
|
||||
| Large_WorstCase | 2,275,919.826 ns | 27,753.5138 ns | 25,960.6540 ns | 8 | 105.4688 | 105.4688 | 105.4688 | 409763 B |
|
||||
| Span_Medium_Mixed | 3,743.828 ns | 8.5415 ns | 7.5718 ns | 5 | 0.0038 | - | - | 120 B |
|
||||
@@ -0,0 +1,11 @@
|
||||
Method,Job,AnalyzeLaunchVariance,EvaluateOverhead,MaxAbsoluteError,MaxRelativeError,MinInvokeCount,MinIterationTime,OutlierMode,Affinity,EnvironmentVariables,Jit,LargeAddressAware,Platform,PowerPlanMode,Runtime,AllowVeryLargeObjects,Concurrent,CpuGroups,Force,HeapAffinitizeMask,HeapCount,NoAffinitize,RetainVm,Server,Arguments,BuildConfiguration,Clock,EngineFactory,NuGetReferences,Toolchain,IsMutator,InvocationCount,IterationCount,IterationTime,LaunchCount,MaxIterationCount,MaxWarmupIterationCount,MemoryRandomization,MinIterationCount,MinWarmupIterationCount,RunStrategy,UnrollFactor,WarmupCount,Mean,Error,StdDev,Rank,Gen0,Gen1,Gen2,Allocated
|
||||
Tiny_Ascii,DefaultJob,False,Default,Default,Default,Default,Default,Default,1111111111111111,Empty,RyuJit,Default,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 10.0,False,True,False,True,Default,Default,False,False,False,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,16,Default,6.756 ns,0.1042 ns,0.0974 ns,1,0.0000,0.0000,0.0000,0 B
|
||||
Tiny_Mixed,DefaultJob,False,Default,Default,Default,Default,Default,Default,1111111111111111,Empty,RyuJit,Default,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 10.0,False,True,False,True,Default,Default,False,False,False,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,16,Default,6.554 ns,0.0153 ns,0.0143 ns,1,0.0000,0.0000,0.0000,0 B
|
||||
Small_Ascii,DefaultJob,False,Default,Default,Default,Default,Default,Default,1111111111111111,Empty,RyuJit,Default,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 10.0,False,True,False,True,Default,Default,False,False,False,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,16,Default,8.132 ns,0.0271 ns,0.0253 ns,2,0.0000,0.0000,0.0000,0 B
|
||||
Small_Mixed,DefaultJob,False,Default,Default,Default,Default,Default,Default,1111111111111111,Empty,RyuJit,Default,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 10.0,False,True,False,True,Default,Default,False,False,False,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,16,Default,308.895 ns,0.6975 ns,0.6525 ns,4,0.0129,0.0000,0.0000,224 B
|
||||
Medium_Ascii,DefaultJob,False,Default,Default,Default,Default,Default,Default,1111111111111111,Empty,RyuJit,Default,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 10.0,False,True,False,True,Default,Default,False,False,False,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,16,Default,38.200 ns,0.2104 ns,0.1968 ns,3,0.0000,0.0000,0.0000,0 B
|
||||
Medium_Mixed,DefaultJob,False,Default,Default,Default,Default,Default,Default,1111111111111111,Empty,RyuJit,Default,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 10.0,False,True,False,True,Default,Default,False,False,False,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,16,Default,"4,213.825 ns",43.6474 ns,40.8278 ns,6,0.1221,0.0000,0.0000,2216 B
|
||||
Large_Ascii,DefaultJob,False,Default,Default,Default,Default,Default,Default,1111111111111111,Empty,RyuJit,Default,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 10.0,False,True,False,True,Default,Default,False,False,False,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,16,Default,"4,327.400 ns",23.7729 ns,21.0740 ns,6,0.0000,0.0000,0.0000,0 B
|
||||
Large_Mixed,DefaultJob,False,Default,Default,Default,Default,Default,Default,1111111111111111,Empty,RyuJit,Default,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 10.0,False,True,False,True,Default,Default,False,False,False,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,16,Default,"791,424.668 ns","4,670.0767 ns","4,368.3927 ns",7,57.6172,57.6172,57.6172,220856 B
|
||||
Large_WorstCase,DefaultJob,False,Default,Default,Default,Default,Default,Default,1111111111111111,Empty,RyuJit,Default,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 10.0,False,True,False,True,Default,Default,False,False,False,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,16,Default,"2,275,919.826 ns","27,753.5138 ns","25,960.6540 ns",8,105.4688,105.4688,105.4688,409763 B
|
||||
Span_Medium_Mixed,DefaultJob,False,Default,Default,Default,Default,Default,Default,1111111111111111,Empty,RyuJit,Default,X64,8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c,.NET 10.0,False,True,False,True,Default,Default,False,False,False,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,Default,16,Default,"3,743.828 ns",8.5415 ns,7.5718 ns,5,0.0038,0.0000,0.0000,120 B
|
||||
|
@@ -0,0 +1,39 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang='en'>
|
||||
<head>
|
||||
<meta charset='utf-8' />
|
||||
<title>Umbraco.Tests.Benchmarks.Utf8ToAsciiConverterBenchmarks-20251213-034127</title>
|
||||
|
||||
<style type="text/css">
|
||||
table { border-collapse: collapse; display: block; width: 100%; overflow: auto; }
|
||||
td, th { padding: 6px 13px; border: 1px solid #ddd; text-align: right; }
|
||||
tr { background-color: #fff; border-top: 1px solid #ccc; }
|
||||
tr:nth-child(even) { background: #f8f8f8; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<pre><code>
|
||||
BenchmarkDotNet v0.15.6, Linux Ubuntu 25.10 (Questing Quokka)
|
||||
Intel Xeon CPU 2.80GHz, 1 CPU, 16 logical and 8 physical cores
|
||||
.NET SDK 10.0.100
|
||||
[Host] : .NET 10.0.0 (10.0.0, 10.0.25.52411), X64 RyuJIT x86-64-v4
|
||||
DefaultJob : .NET 10.0.0 (10.0.0, 10.0.25.52411), X64 RyuJIT x86-64-v4
|
||||
</code></pre>
|
||||
<pre><code></code></pre>
|
||||
|
||||
<table>
|
||||
<thead><tr><th>Method </th><th>Mean </th><th>Error </th><th>StdDev </th><th>Rank</th><th>Gen0</th><th>Gen1</th><th>Gen2</th><th>Allocated</th>
|
||||
</tr>
|
||||
</thead><tbody><tr><td>Tiny_Ascii</td><td>6.756 ns</td><td>0.1042 ns</td><td>0.0974 ns</td><td>1</td><td>-</td><td>-</td><td>-</td><td>-</td>
|
||||
</tr><tr><td>Tiny_Mixed</td><td>6.554 ns</td><td>0.0153 ns</td><td>0.0143 ns</td><td>1</td><td>-</td><td>-</td><td>-</td><td>-</td>
|
||||
</tr><tr><td>Small_Ascii</td><td>8.132 ns</td><td>0.0271 ns</td><td>0.0253 ns</td><td>2</td><td>-</td><td>-</td><td>-</td><td>-</td>
|
||||
</tr><tr><td>Small_Mixed</td><td>308.895 ns</td><td>0.6975 ns</td><td>0.6525 ns</td><td>4</td><td>0.0129</td><td>-</td><td>-</td><td>224 B</td>
|
||||
</tr><tr><td>Medium_Ascii</td><td>38.200 ns</td><td>0.2104 ns</td><td>0.1968 ns</td><td>3</td><td>-</td><td>-</td><td>-</td><td>-</td>
|
||||
</tr><tr><td>Medium_Mixed</td><td>4,213.825 ns</td><td>43.6474 ns</td><td>40.8278 ns</td><td>6</td><td>0.1221</td><td>-</td><td>-</td><td>2216 B</td>
|
||||
</tr><tr><td>Large_Ascii</td><td>4,327.400 ns</td><td>23.7729 ns</td><td>21.0740 ns</td><td>6</td><td>-</td><td>-</td><td>-</td><td>-</td>
|
||||
</tr><tr><td>Large_Mixed</td><td>791,424.668 ns</td><td>4,670.0767 ns</td><td>4,368.3927 ns</td><td>7</td><td>57.6172</td><td>57.6172</td><td>57.6172</td><td>220856 B</td>
|
||||
</tr><tr><td>Large_WorstCase</td><td>2,275,919.826 ns</td><td>27,753.5138 ns</td><td>25,960.6540 ns</td><td>8</td><td>105.4688</td><td>105.4688</td><td>105.4688</td><td>409763 B</td>
|
||||
</tr><tr><td>Span_Medium_Mixed</td><td>3,743.828 ns</td><td>8.5415 ns</td><td>7.5718 ns</td><td>5</td><td>0.0038</td><td>-</td><td>-</td><td>120 B</td>
|
||||
</tr></tbody></table>
|
||||
</body>
|
||||
</html>
|
||||
838
benchmark-6db0554b1e.txt
Normal file
838
benchmark-6db0554b1e.txt
Normal file
@@ -0,0 +1,838 @@
|
||||
Determining projects to restore...
|
||||
All projects are up-to-date for restore.
|
||||
Umbraco.Core -> /home/yv01p/Umbraco-CMS/src/Umbraco.Core/bin/Debug/net10.0/Umbraco.Core.dll
|
||||
Umbraco.Infrastructure -> /home/yv01p/Umbraco-CMS/src/Umbraco.Infrastructure/bin/Debug/net10.0/Umbraco.Infrastructure.dll
|
||||
Umbraco.PublishedCache.HybridCache -> /home/yv01p/Umbraco-CMS/src/Umbraco.PublishedCache.HybridCache/bin/Debug/net10.0/Umbraco.PublishedCache.HybridCache.dll
|
||||
Umbraco.Cms.Persistence.EFCore -> /home/yv01p/Umbraco-CMS/src/Umbraco.Cms.Persistence.EFCore/bin/Debug/net10.0/Umbraco.Cms.Persistence.EFCore.dll
|
||||
Umbraco.Examine.Lucene -> /home/yv01p/Umbraco-CMS/src/Umbraco.Examine.Lucene/bin/Debug/net10.0/Umbraco.Examine.Lucene.dll
|
||||
Umbraco.Cms.Persistence.SqlServer -> /home/yv01p/Umbraco-CMS/src/Umbraco.Cms.Persistence.SqlServer/bin/Debug/net10.0/Umbraco.Cms.Persistence.SqlServer.dll
|
||||
Umbraco.Cms.Persistence.Sqlite -> /home/yv01p/Umbraco-CMS/src/Umbraco.Cms.Persistence.Sqlite/bin/Debug/net10.0/Umbraco.Cms.Persistence.Sqlite.dll
|
||||
Umbraco.Cms.Persistence.EFCore.SqlServer -> /home/yv01p/Umbraco-CMS/src/Umbraco.Cms.Persistence.EFCore.SqlServer/bin/Debug/net10.0/Umbraco.Cms.Persistence.EFCore.SqlServer.dll
|
||||
Umbraco.Cms.Persistence.EFCore.Sqlite -> /home/yv01p/Umbraco-CMS/src/Umbraco.Cms.Persistence.EFCore.Sqlite/bin/Debug/net10.0/Umbraco.Cms.Persistence.EFCore.Sqlite.dll
|
||||
Umbraco.Web.Common -> /home/yv01p/Umbraco-CMS/src/Umbraco.Web.Common/bin/Debug/net10.0/Umbraco.Web.Common.dll
|
||||
Umbraco.Cms.Api.Common -> /home/yv01p/Umbraco-CMS/src/Umbraco.Cms.Api.Common/bin/Debug/net10.0/Umbraco.Cms.Api.Common.dll
|
||||
Umbraco.Web.Website -> /home/yv01p/Umbraco-CMS/src/Umbraco.Web.Website/bin/Debug/net10.0/Umbraco.Web.Website.dll
|
||||
Umbraco.Cms.Imaging.ImageSharp -> /home/yv01p/Umbraco-CMS/src/Umbraco.Cms.Imaging.ImageSharp/bin/Debug/net10.0/Umbraco.Cms.Imaging.ImageSharp.dll
|
||||
Umbraco.Cms.Api.Delivery -> /home/yv01p/Umbraco-CMS/src/Umbraco.Cms.Api.Delivery/bin/Debug/net10.0/Umbraco.Cms.Api.Delivery.dll
|
||||
Umbraco.Cms.Api.Management -> /home/yv01p/Umbraco-CMS/src/Umbraco.Cms.Api.Management/bin/Debug/net10.0/Umbraco.Cms.Api.Management.dll
|
||||
Skip BuildBackoffice target because 'wwwroot/umbraco/backoffice' already exists
|
||||
Skip BuildLogin target because 'wwwroot/umbraco/login' already exists
|
||||
Umbraco.Cms.StaticAssets -> /home/yv01p/Umbraco-CMS/src/Umbraco.Cms.StaticAssets/bin/Debug/net10.0/Umbraco.Cms.StaticAssets.dll
|
||||
Umbraco.Cms.Targets -> /home/yv01p/Umbraco-CMS/src/Umbraco.Cms.Targets/bin/Debug/net10.0/Umbraco.Cms.Targets.dll
|
||||
Umbraco.Cms -> /home/yv01p/Umbraco-CMS/src/Umbraco.Cms/bin/Debug/net10.0/Umbraco.Cms.dll
|
||||
Umbraco.Tests.Common -> /home/yv01p/Umbraco-CMS/tests/Umbraco.Tests.Common/bin/Debug/net10.0/Umbraco.Tests.Common.dll
|
||||
Umbraco.Tests.Integration -> /home/yv01p/Umbraco-CMS/tests/Umbraco.Tests.Integration/bin/Debug/net10.0/Umbraco.Tests.Integration.dll
|
||||
Copying JSON schema files into project directory: appsettings-schema.Umbraco.Cms.json
|
||||
Copying JSON schema files into project directory: umbraco-package-schema.json
|
||||
Adding JSON schema references to appsettings-schema.json: https://json.schemastore.org/appsettings.json;appsettings-schema.Umbraco.Cms.json#
|
||||
Test run for /home/yv01p/Umbraco-CMS/tests/Umbraco.Tests.Integration/bin/Debug/net10.0/Umbraco.Tests.Integration.dll (.NETCoreApp,Version=v10.0)
|
||||
VSTest version 18.0.1 (x64)
|
||||
|
||||
Starting test execution, please wait...
|
||||
A total of 1 test files matched the specified pattern.
|
||||
/home/yv01p/Umbraco-CMS/tests/Umbraco.Tests.Integration/bin/Debug/net10.0/Umbraco.Tests.Integration.dll
|
||||
NUnit Adapter 4.6.0.0: Test execution started
|
||||
Running selected tests in /home/yv01p/Umbraco-CMS/tests/Umbraco.Tests.Integration/bin/Debug/net10.0/Umbraco.Tests.Integration.dll
|
||||
NUnit3TestExecutor discovered 33 of 33 NUnit test cases using Current Discovery mode, Non-Explicit run
|
||||
******************************************************************************
|
||||
* Umbraco.Tests.Integration
|
||||
*
|
||||
* DatabaseType : Sqlite
|
||||
* UmbracoVersion : 17.1.0--rc.preview.219
|
||||
* WorkingDirectory : /home/yv01p/Umbraco-CMS/tests/Umbraco.Tests.Integration/TEMP
|
||||
******************************************************************************
|
||||
Start test 1: Benchmark_BaselineComparison[BENCHMARK] BaselineComparison: 1357ms (135.70ms/item, 10 items)
|
||||
[BASELINE] Total time for representative operations: 1357ms
|
||||
[BENCHMARK_JSON][
|
||||
{
|
||||
"Name": "BaselineComparison",
|
||||
"ElapsedMs": 1357,
|
||||
"ItemCount": 10,
|
||||
"MsPerItem": 135.7
|
||||
}
|
||||
][/BENCHMARK_JSON]
|
||||
Passed
|
||||
Passed Benchmark_BaselineComparison [3 s]
|
||||
Standard Output Messages:
|
||||
Start test 1: Benchmark_BaselineComparison[BENCHMARK] BaselineComparison: 1357ms (135.70ms/item, 10 items)
|
||||
[BASELINE] Total time for representative operations: 1357ms
|
||||
[BENCHMARK_JSON][
|
||||
{
|
||||
"Name": "BaselineComparison",
|
||||
"ElapsedMs": 1357,
|
||||
"ItemCount": 10,
|
||||
"MsPerItem": 135.7
|
||||
}
|
||||
][/BENCHMARK_JSON]
|
||||
Passed
|
||||
|
||||
Start test 2: Benchmark_Copy_Recursive_100Items[BENCHMARK] Copy_Recursive_100Items: 2809ms (27.81ms/item, 101 items)
|
||||
[BENCHMARK_JSON][
|
||||
{
|
||||
"Name": "Copy_Recursive_100Items",
|
||||
"ElapsedMs": 2809,
|
||||
"ItemCount": 101,
|
||||
"MsPerItem": 27.81188118811881
|
||||
}
|
||||
][/BENCHMARK_JSON]
|
||||
Passed
|
||||
Passed Benchmark_Copy_Recursive_100Items [5 s]
|
||||
Standard Output Messages:
|
||||
Start test 2: Benchmark_Copy_Recursive_100Items[BENCHMARK] Copy_Recursive_100Items: 2809ms (27.81ms/item, 101 items)
|
||||
[BENCHMARK_JSON][
|
||||
{
|
||||
"Name": "Copy_Recursive_100Items",
|
||||
"ElapsedMs": 2809,
|
||||
"ItemCount": 101,
|
||||
"MsPerItem": 27.81188118811881
|
||||
}
|
||||
][/BENCHMARK_JSON]
|
||||
Passed
|
||||
|
||||
Start test 3: Benchmark_Copy_SingleItem[BENCHMARK] Copy_SingleItem: 30ms (30.00ms/item, 1 items)
|
||||
[BENCHMARK_JSON][
|
||||
{
|
||||
"Name": "Copy_SingleItem",
|
||||
"ElapsedMs": 30,
|
||||
"ItemCount": 1,
|
||||
"MsPerItem": 30
|
||||
}
|
||||
][/BENCHMARK_JSON]
|
||||
Passed
|
||||
Passed Benchmark_Copy_SingleItem [565 ms]
|
||||
Standard Output Messages:
|
||||
Start test 3: Benchmark_Copy_SingleItem[BENCHMARK] Copy_SingleItem: 30ms (30.00ms/item, 1 items)
|
||||
[BENCHMARK_JSON][
|
||||
{
|
||||
"Name": "Copy_SingleItem",
|
||||
"ElapsedMs": 30,
|
||||
"ItemCount": 1,
|
||||
"MsPerItem": 30
|
||||
}
|
||||
][/BENCHMARK_JSON]
|
||||
Passed
|
||||
|
||||
Start test 4: Benchmark_Count_ByContentType[BENCHMARK] Count_ByContentType: 1ms (0.00ms/item, 1000 items)
|
||||
[BENCHMARK_JSON][
|
||||
{
|
||||
"Name": "Count_ByContentType",
|
||||
"ElapsedMs": 1,
|
||||
"ItemCount": 1000,
|
||||
"MsPerItem": 0.001
|
||||
}
|
||||
][/BENCHMARK_JSON]
|
||||
Passed
|
||||
Passed Benchmark_Count_ByContentType [8 s]
|
||||
Standard Output Messages:
|
||||
Start test 4: Benchmark_Count_ByContentType[BENCHMARK] Count_ByContentType: 1ms (0.00ms/item, 1000 items)
|
||||
[BENCHMARK_JSON][
|
||||
{
|
||||
"Name": "Count_ByContentType",
|
||||
"ElapsedMs": 1,
|
||||
"ItemCount": 1000,
|
||||
"MsPerItem": 0.001
|
||||
}
|
||||
][/BENCHMARK_JSON]
|
||||
Passed
|
||||
|
||||
Start test 5: Benchmark_CountDescendants_LargeTree[BENCHMARK] CountDescendants_LargeTree: 1ms (0.00ms/item, 1000 items)
|
||||
[BENCHMARK_JSON][
|
||||
{
|
||||
"Name": "CountDescendants_LargeTree",
|
||||
"ElapsedMs": 1,
|
||||
"ItemCount": 1000,
|
||||
"MsPerItem": 0.001
|
||||
}
|
||||
][/BENCHMARK_JSON]
|
||||
Passed
|
||||
Passed Benchmark_CountDescendants_LargeTree [7 s]
|
||||
Standard Output Messages:
|
||||
Start test 5: Benchmark_CountDescendants_LargeTree[BENCHMARK] CountDescendants_LargeTree: 1ms (0.00ms/item, 1000 items)
|
||||
[BENCHMARK_JSON][
|
||||
{
|
||||
"Name": "CountDescendants_LargeTree",
|
||||
"ElapsedMs": 1,
|
||||
"ItemCount": 1000,
|
||||
"MsPerItem": 0.001
|
||||
}
|
||||
][/BENCHMARK_JSON]
|
||||
Passed
|
||||
|
||||
Start test 6: Benchmark_Delete_SingleItem[BENCHMARK] Delete_SingleItem: 35ms (35.00ms/item, 1 items)
|
||||
[BENCHMARK_JSON][
|
||||
{
|
||||
"Name": "Delete_SingleItem",
|
||||
"ElapsedMs": 35,
|
||||
"ItemCount": 1,
|
||||
"MsPerItem": 35
|
||||
}
|
||||
][/BENCHMARK_JSON]
|
||||
Passed
|
||||
Passed Benchmark_Delete_SingleItem [291 ms]
|
||||
Standard Output Messages:
|
||||
Start test 6: Benchmark_Delete_SingleItem[BENCHMARK] Delete_SingleItem: 35ms (35.00ms/item, 1 items)
|
||||
[BENCHMARK_JSON][
|
||||
{
|
||||
"Name": "Delete_SingleItem",
|
||||
"ElapsedMs": 35,
|
||||
"ItemCount": 1,
|
||||
"MsPerItem": 35
|
||||
}
|
||||
][/BENCHMARK_JSON]
|
||||
Passed
|
||||
|
||||
Start test 7: Benchmark_Delete_WithDescendants[BENCHMARK] Delete_WithDescendants: 243ms (2.41ms/item, 101 items)
|
||||
[BENCHMARK_JSON][
|
||||
{
|
||||
"Name": "Delete_WithDescendants",
|
||||
"ElapsedMs": 243,
|
||||
"ItemCount": 101,
|
||||
"MsPerItem": 2.405940594059406
|
||||
}
|
||||
][/BENCHMARK_JSON]
|
||||
Passed
|
||||
Start test 8: Benchmark_DeleteVersions_ByDate[BENCHMARK] DeleteVersions_ByDate: 5ms (0.05ms/item, 100 items)
|
||||
[BENCHMARK_JSON][
|
||||
{
|
||||
"Name": "DeleteVersions_ByDate",
|
||||
"ElapsedMs": 5,
|
||||
"ItemCount": 100,
|
||||
"MsPerItem": 0.05
|
||||
}
|
||||
][/BENCHMARK_JSON]
|
||||
Passed
|
||||
Passed Benchmark_Delete_WithDescendants [1 s]
|
||||
Standard Output Messages:
|
||||
Start test 7: Benchmark_Delete_WithDescendants[BENCHMARK] Delete_WithDescendants: 243ms (2.41ms/item, 101 items)
|
||||
[BENCHMARK_JSON][
|
||||
{
|
||||
"Name": "Delete_WithDescendants",
|
||||
"ElapsedMs": 243,
|
||||
"ItemCount": 101,
|
||||
"MsPerItem": 2.405940594059406
|
||||
}
|
||||
][/BENCHMARK_JSON]
|
||||
Passed
|
||||
|
||||
Passed Benchmark_DeleteVersions_ByDate [1 s]
|
||||
Standard Output Messages:
|
||||
Start test 8: Benchmark_DeleteVersions_ByDate[BENCHMARK] DeleteVersions_ByDate: 5ms (0.05ms/item, 100 items)
|
||||
[BENCHMARK_JSON][
|
||||
{
|
||||
"Name": "DeleteVersions_ByDate",
|
||||
"ElapsedMs": 5,
|
||||
"ItemCount": 100,
|
||||
"MsPerItem": 0.05
|
||||
}
|
||||
][/BENCHMARK_JSON]
|
||||
Passed
|
||||
|
||||
Start test 9: Benchmark_EmptyRecycleBin_100Items[BENCHMARK] EmptyRecycleBin_100Items: 847ms (8.47ms/item, 100 items)
|
||||
[BENCHMARK_JSON][
|
||||
{
|
||||
"Name": "EmptyRecycleBin_100Items",
|
||||
"ElapsedMs": 847,
|
||||
"ItemCount": 100,
|
||||
"MsPerItem": 8.47
|
||||
}
|
||||
][/BENCHMARK_JSON]
|
||||
Passed
|
||||
Passed Benchmark_EmptyRecycleBin_100Items [3 s]
|
||||
Standard Output Messages:
|
||||
Start test 9: Benchmark_EmptyRecycleBin_100Items[BENCHMARK] EmptyRecycleBin_100Items: 847ms (8.47ms/item, 100 items)
|
||||
[BENCHMARK_JSON][
|
||||
{
|
||||
"Name": "EmptyRecycleBin_100Items",
|
||||
"ElapsedMs": 847,
|
||||
"ItemCount": 100,
|
||||
"MsPerItem": 8.47
|
||||
}
|
||||
][/BENCHMARK_JSON]
|
||||
Passed
|
||||
|
||||
Start test 10: Benchmark_GetAncestors_DeepHierarchy[BENCHMARK] GetAncestors_DeepHierarchy: 31ms (3.10ms/item, 10 items)
|
||||
[BENCHMARK_JSON][
|
||||
{
|
||||
"Name": "GetAncestors_DeepHierarchy",
|
||||
"ElapsedMs": 31,
|
||||
"ItemCount": 10,
|
||||
"MsPerItem": 3.1
|
||||
}
|
||||
][/BENCHMARK_JSON]
|
||||
Passed
|
||||
Start test 11: Benchmark_GetById_Single[BENCHMARK] GetById_Single: 8ms (8.00ms/item, 1 items)
|
||||
[BENCHMARK_JSON][
|
||||
{
|
||||
"Name": "GetById_Single",
|
||||
"ElapsedMs": 8,
|
||||
"ItemCount": 1,
|
||||
"MsPerItem": 8
|
||||
}
|
||||
][/BENCHMARK_JSON]
|
||||
Passed
|
||||
Passed Benchmark_GetAncestors_DeepHierarchy [391 ms]
|
||||
Standard Output Messages:
|
||||
Start test 10: Benchmark_GetAncestors_DeepHierarchy[BENCHMARK] GetAncestors_DeepHierarchy: 31ms (3.10ms/item, 10 items)
|
||||
[BENCHMARK_JSON][
|
||||
{
|
||||
"Name": "GetAncestors_DeepHierarchy",
|
||||
"ElapsedMs": 31,
|
||||
"ItemCount": 10,
|
||||
"MsPerItem": 3.1
|
||||
}
|
||||
][/BENCHMARK_JSON]
|
||||
Passed
|
||||
|
||||
Passed Benchmark_GetById_Single [279 ms]
|
||||
Standard Output Messages:
|
||||
Start test 11: Benchmark_GetById_Single[BENCHMARK] GetById_Single: 8ms (8.00ms/item, 1 items)
|
||||
[BENCHMARK_JSON][
|
||||
{
|
||||
"Name": "GetById_Single",
|
||||
"ElapsedMs": 8,
|
||||
"ItemCount": 1,
|
||||
"MsPerItem": 8
|
||||
}
|
||||
][/BENCHMARK_JSON]
|
||||
Passed
|
||||
|
||||
Start test 12: Benchmark_GetByIds_BatchOf100[BENCHMARK] GetByIds_BatchOf100: 14ms (0.14ms/item, 100 items)
|
||||
[BENCHMARK_JSON][
|
||||
{
|
||||
"Name": "GetByIds_BatchOf100",
|
||||
"ElapsedMs": 14,
|
||||
"ItemCount": 100,
|
||||
"MsPerItem": 0.14
|
||||
}
|
||||
][/BENCHMARK_JSON]
|
||||
Passed
|
||||
Start test 13: Benchmark_GetContentSchedulesByIds_100Items[BENCHMARK] GetContentSchedulesByIds_100Items: 1ms (0.01ms/item, 100 items)
|
||||
[BENCHMARK_JSON][
|
||||
{
|
||||
"Name": "GetContentSchedulesByIds_100Items",
|
||||
"ElapsedMs": 1,
|
||||
"ItemCount": 100,
|
||||
"MsPerItem": 0.01
|
||||
}
|
||||
][/BENCHMARK_JSON]
|
||||
Passed
|
||||
Passed Benchmark_GetByIds_BatchOf100 [1 s]
|
||||
Standard Output Messages:
|
||||
Start test 12: Benchmark_GetByIds_BatchOf100[BENCHMARK] GetByIds_BatchOf100: 14ms (0.14ms/item, 100 items)
|
||||
[BENCHMARK_JSON][
|
||||
{
|
||||
"Name": "GetByIds_BatchOf100",
|
||||
"ElapsedMs": 14,
|
||||
"ItemCount": 100,
|
||||
"MsPerItem": 0.14
|
||||
}
|
||||
][/BENCHMARK_JSON]
|
||||
Passed
|
||||
|
||||
Passed Benchmark_GetContentSchedulesByIds_100Items [1 s]
|
||||
Standard Output Messages:
|
||||
Start test 13: Benchmark_GetContentSchedulesByIds_100Items[BENCHMARK] GetContentSchedulesByIds_100Items: 1ms (0.01ms/item, 100 items)
|
||||
[BENCHMARK_JSON][
|
||||
{
|
||||
"Name": "GetContentSchedulesByIds_100Items",
|
||||
"ElapsedMs": 1,
|
||||
"ItemCount": 100,
|
||||
"MsPerItem": 0.01
|
||||
}
|
||||
][/BENCHMARK_JSON]
|
||||
Passed
|
||||
|
||||
Start test 14: Benchmark_GetPagedChildren_100Items[BENCHMARK] GetPagedChildren_100Items: 16ms (0.16ms/item, 100 items)
|
||||
[BENCHMARK_JSON][
|
||||
{
|
||||
"Name": "GetPagedChildren_100Items",
|
||||
"ElapsedMs": 16,
|
||||
"ItemCount": 100,
|
||||
"MsPerItem": 0.16
|
||||
}
|
||||
][/BENCHMARK_JSON]
|
||||
Passed
|
||||
Passed Benchmark_GetPagedChildren_100Items [1 s]
|
||||
Standard Output Messages:
|
||||
Start test 14: Benchmark_GetPagedChildren_100Items[BENCHMARK] GetPagedChildren_100Items: 16ms (0.16ms/item, 100 items)
|
||||
[BENCHMARK_JSON][
|
||||
{
|
||||
"Name": "GetPagedChildren_100Items",
|
||||
"ElapsedMs": 16,
|
||||
"ItemCount": 100,
|
||||
"MsPerItem": 0.16
|
||||
}
|
||||
][/BENCHMARK_JSON]
|
||||
Passed
|
||||
|
||||
Start test 15: Benchmark_GetPagedDescendants_DeepTree[BENCHMARK] GetPagedDescendants_DeepTree: 25ms (0.08ms/item, 300 items)
|
||||
[BENCHMARK_JSON][
|
||||
{
|
||||
"Name": "GetPagedDescendants_DeepTree",
|
||||
"ElapsedMs": 25,
|
||||
"ItemCount": 300,
|
||||
"MsPerItem": 0.08333333333333333
|
||||
}
|
||||
][/BENCHMARK_JSON]
|
||||
Passed
|
||||
Passed Benchmark_GetPagedDescendants_DeepTree [2 s]
|
||||
Standard Output Messages:
|
||||
Start test 15: Benchmark_GetPagedDescendants_DeepTree[BENCHMARK] GetPagedDescendants_DeepTree: 25ms (0.08ms/item, 300 items)
|
||||
[BENCHMARK_JSON][
|
||||
{
|
||||
"Name": "GetPagedDescendants_DeepTree",
|
||||
"ElapsedMs": 25,
|
||||
"ItemCount": 300,
|
||||
"MsPerItem": 0.08333333333333333
|
||||
}
|
||||
][/BENCHMARK_JSON]
|
||||
Passed
|
||||
|
||||
Start test 16: Benchmark_GetVersions_ItemWith100Versions[BENCHMARK] GetVersions_ItemWith100Versions: 11ms (0.11ms/item, 100 items)
|
||||
[BENCHMARK_JSON][
|
||||
{
|
||||
"Name": "GetVersions_ItemWith100Versions",
|
||||
"ElapsedMs": 11,
|
||||
"ItemCount": 100,
|
||||
"MsPerItem": 0.11
|
||||
}
|
||||
][/BENCHMARK_JSON]
|
||||
Failed
|
||||
Failed Benchmark_GetVersions_ItemWith100Versions [1 s]
|
||||
Error Message:
|
||||
Expected: greater than or equal to 100
|
||||
But was: 1
|
||||
|
||||
Stack Trace:
|
||||
at Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services.ContentServiceRefactoringBenchmarks.Benchmark_GetVersions_ItemWith100Versions() in /home/yv01p/Umbraco-CMS/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentServiceRefactoringBenchmarks.cs:line 972
|
||||
|
||||
1) at Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services.ContentServiceRefactoringBenchmarks.Benchmark_GetVersions_ItemWith100Versions() in /home/yv01p/Umbraco-CMS/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentServiceRefactoringBenchmarks.cs:line 972
|
||||
|
||||
|
||||
Standard Output Messages:
|
||||
Start test 16: Benchmark_GetVersions_ItemWith100Versions[BENCHMARK] GetVersions_ItemWith100Versions: 11ms (0.11ms/item, 100 items)
|
||||
[BENCHMARK_JSON][
|
||||
{
|
||||
"Name": "GetVersions_ItemWith100Versions",
|
||||
"ElapsedMs": 11,
|
||||
"ItemCount": 100,
|
||||
"MsPerItem": 0.11
|
||||
}
|
||||
][/BENCHMARK_JSON]
|
||||
Failed
|
||||
|
||||
Start test 17: Benchmark_GetVersionsSlim_Paged[BENCHMARK] GetVersionsSlim_Paged: 8ms (0.80ms/item, 10 items)
|
||||
[BENCHMARK_JSON][
|
||||
{
|
||||
"Name": "GetVersionsSlim_Paged",
|
||||
"ElapsedMs": 8,
|
||||
"ItemCount": 10,
|
||||
"MsPerItem": 0.8
|
||||
}
|
||||
][/BENCHMARK_JSON]
|
||||
Failed
|
||||
Failed Benchmark_GetVersionsSlim_Paged [1 s]
|
||||
Error Message:
|
||||
Expected: 10
|
||||
But was: 1
|
||||
|
||||
Stack Trace:
|
||||
at Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services.ContentServiceRefactoringBenchmarks.Benchmark_GetVersionsSlim_Paged() in /home/yv01p/Umbraco-CMS/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentServiceRefactoringBenchmarks.cs:line 1000
|
||||
|
||||
1) at Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services.ContentServiceRefactoringBenchmarks.Benchmark_GetVersionsSlim_Paged() in /home/yv01p/Umbraco-CMS/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentServiceRefactoringBenchmarks.cs:line 1000
|
||||
|
||||
|
||||
Standard Output Messages:
|
||||
Start test 17: Benchmark_GetVersionsSlim_Paged[BENCHMARK] GetVersionsSlim_Paged: 8ms (0.80ms/item, 10 items)
|
||||
[BENCHMARK_JSON][
|
||||
{
|
||||
"Name": "GetVersionsSlim_Paged",
|
||||
"ElapsedMs": 8,
|
||||
"ItemCount": 10,
|
||||
"MsPerItem": 0.8
|
||||
}
|
||||
][/BENCHMARK_JSON]
|
||||
Failed
|
||||
|
||||
Start test 18: Benchmark_HasChildren_100Nodes[BENCHMARK] HasChildren_100Nodes: 65ms (0.65ms/item, 100 items)
|
||||
[BENCHMARK_JSON][
|
||||
{
|
||||
"Name": "HasChildren_100Nodes",
|
||||
"ElapsedMs": 65,
|
||||
"ItemCount": 100,
|
||||
"MsPerItem": 0.65
|
||||
}
|
||||
][/BENCHMARK_JSON]
|
||||
Failed
|
||||
Start test 19: Benchmark_Move_SingleItem[BENCHMARK] Move_SingleItem: 22ms (22.00ms/item, 1 items)
|
||||
[BENCHMARK_JSON][
|
||||
{
|
||||
"Name": "Move_SingleItem",
|
||||
"ElapsedMs": 22,
|
||||
"ItemCount": 1,
|
||||
"MsPerItem": 22
|
||||
}
|
||||
][/BENCHMARK_JSON]
|
||||
Passed
|
||||
Failed Benchmark_HasChildren_100Nodes [1 s]
|
||||
Error Message:
|
||||
Expected: 50
|
||||
But was: 100
|
||||
|
||||
Stack Trace:
|
||||
at Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services.ContentServiceRefactoringBenchmarks.Benchmark_HasChildren_100Nodes() in /home/yv01p/Umbraco-CMS/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentServiceRefactoringBenchmarks.cs:line 424
|
||||
|
||||
1) at Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services.ContentServiceRefactoringBenchmarks.Benchmark_HasChildren_100Nodes() in /home/yv01p/Umbraco-CMS/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentServiceRefactoringBenchmarks.cs:line 424
|
||||
|
||||
|
||||
Standard Output Messages:
|
||||
Start test 18: Benchmark_HasChildren_100Nodes[BENCHMARK] HasChildren_100Nodes: 65ms (0.65ms/item, 100 items)
|
||||
[BENCHMARK_JSON][
|
||||
{
|
||||
"Name": "HasChildren_100Nodes",
|
||||
"ElapsedMs": 65,
|
||||
"ItemCount": 100,
|
||||
"MsPerItem": 0.65
|
||||
}
|
||||
][/BENCHMARK_JSON]
|
||||
Failed
|
||||
|
||||
Passed Benchmark_Move_SingleItem [419 ms]
|
||||
Standard Output Messages:
|
||||
Start test 19: Benchmark_Move_SingleItem[BENCHMARK] Move_SingleItem: 22ms (22.00ms/item, 1 items)
|
||||
[BENCHMARK_JSON][
|
||||
{
|
||||
"Name": "Move_SingleItem",
|
||||
"ElapsedMs": 22,
|
||||
"ItemCount": 1,
|
||||
"MsPerItem": 22
|
||||
}
|
||||
][/BENCHMARK_JSON]
|
||||
Passed
|
||||
|
||||
Start test 20: Benchmark_Move_WithDescendants[BENCHMARK] Move_WithDescendants: 592ms (5.86ms/item, 101 items)
|
||||
[BENCHMARK_JSON][
|
||||
{
|
||||
"Name": "Move_WithDescendants",
|
||||
"ElapsedMs": 592,
|
||||
"ItemCount": 101,
|
||||
"MsPerItem": 5.861386138613861
|
||||
}
|
||||
][/BENCHMARK_JSON]
|
||||
Passed
|
||||
Passed Benchmark_Move_WithDescendants [1 s]
|
||||
Standard Output Messages:
|
||||
Start test 20: Benchmark_Move_WithDescendants[BENCHMARK] Move_WithDescendants: 592ms (5.86ms/item, 101 items)
|
||||
[BENCHMARK_JSON][
|
||||
{
|
||||
"Name": "Move_WithDescendants",
|
||||
"ElapsedMs": 592,
|
||||
"ItemCount": 101,
|
||||
"MsPerItem": 5.861386138613861
|
||||
}
|
||||
][/BENCHMARK_JSON]
|
||||
Passed
|
||||
|
||||
Start test 21: Benchmark_MoveToRecycleBin_LargeTree[BENCHMARK] MoveToRecycleBin_LargeTree: 8955ms (8.95ms/item, 1001 items)
|
||||
[BENCHMARK_JSON][
|
||||
{
|
||||
"Name": "MoveToRecycleBin_LargeTree",
|
||||
"ElapsedMs": 8955,
|
||||
"ItemCount": 1001,
|
||||
"MsPerItem": 8.946053946053945
|
||||
}
|
||||
][/BENCHMARK_JSON]
|
||||
Passed
|
||||
Passed Benchmark_MoveToRecycleBin_LargeTree [17 s]
|
||||
Standard Output Messages:
|
||||
Start test 21: Benchmark_MoveToRecycleBin_LargeTree[BENCHMARK] MoveToRecycleBin_LargeTree: 8955ms (8.95ms/item, 1001 items)
|
||||
[BENCHMARK_JSON][
|
||||
{
|
||||
"Name": "MoveToRecycleBin_LargeTree",
|
||||
"ElapsedMs": 8955,
|
||||
"ItemCount": 1001,
|
||||
"MsPerItem": 8.946053946053945
|
||||
}
|
||||
][/BENCHMARK_JSON]
|
||||
Passed
|
||||
|
||||
Start test 22: Benchmark_MoveToRecycleBin_Published[BENCHMARK] MoveToRecycleBin_Published: 34ms (34.00ms/item, 1 items)
|
||||
[BENCHMARK_JSON][
|
||||
{
|
||||
"Name": "MoveToRecycleBin_Published",
|
||||
"ElapsedMs": 34,
|
||||
"ItemCount": 1,
|
||||
"MsPerItem": 34
|
||||
}
|
||||
][/BENCHMARK_JSON]
|
||||
Passed
|
||||
Passed Benchmark_MoveToRecycleBin_Published [426 ms]
|
||||
Standard Output Messages:
|
||||
Start test 22: Benchmark_MoveToRecycleBin_Published[BENCHMARK] MoveToRecycleBin_Published: 34ms (34.00ms/item, 1 items)
|
||||
[BENCHMARK_JSON][
|
||||
{
|
||||
"Name": "MoveToRecycleBin_Published",
|
||||
"ElapsedMs": 34,
|
||||
"ItemCount": 1,
|
||||
"MsPerItem": 34
|
||||
}
|
||||
][/BENCHMARK_JSON]
|
||||
Passed
|
||||
|
||||
Start test 23: Benchmark_PerformScheduledPublishfail: Umbraco.Cms.Core.Services.ContentService[0]
|
||||
Failed to publish document id=1059, reason=FailedPublishPathNotPublished.
|
||||
[BENCHMARK] PerformScheduledPublish: 2526ms (25.26ms/item, 100 items)
|
||||
[BENCHMARK_JSON][
|
||||
{
|
||||
"Name": "PerformScheduledPublish",
|
||||
"ElapsedMs": 2526,
|
||||
"ItemCount": 100,
|
||||
"MsPerItem": 25.26
|
||||
}
|
||||
][/BENCHMARK_JSON]
|
||||
Passed
|
||||
Passed Benchmark_PerformScheduledPublish [3 s]
|
||||
Standard Output Messages:
|
||||
Start test 23: Benchmark_PerformScheduledPublishfail: Umbraco.Cms.Core.Services.ContentService[0]
|
||||
Failed to publish document id=1059, reason=FailedPublishPathNotPublished.
|
||||
[BENCHMARK] PerformScheduledPublish: 2526ms (25.26ms/item, 100 items)
|
||||
[BENCHMARK_JSON][
|
||||
{
|
||||
"Name": "PerformScheduledPublish",
|
||||
"ElapsedMs": 2526,
|
||||
"ItemCount": 100,
|
||||
"MsPerItem": 25.26
|
||||
}
|
||||
][/BENCHMARK_JSON]
|
||||
Passed
|
||||
|
||||
Start test 24: Benchmark_Publish_BatchOf100[BENCHMARK] Publish_BatchOf100: 2456ms (24.56ms/item, 100 items)
|
||||
[BENCHMARK_JSON][
|
||||
{
|
||||
"Name": "Publish_BatchOf100",
|
||||
"ElapsedMs": 2456,
|
||||
"ItemCount": 100,
|
||||
"MsPerItem": 24.56
|
||||
}
|
||||
][/BENCHMARK_JSON]
|
||||
Passed
|
||||
Passed Benchmark_Publish_BatchOf100 [3 s]
|
||||
Standard Output Messages:
|
||||
Start test 24: Benchmark_Publish_BatchOf100[BENCHMARK] Publish_BatchOf100: 2456ms (24.56ms/item, 100 items)
|
||||
[BENCHMARK_JSON][
|
||||
{
|
||||
"Name": "Publish_BatchOf100",
|
||||
"ElapsedMs": 2456,
|
||||
"ItemCount": 100,
|
||||
"MsPerItem": 24.56
|
||||
}
|
||||
][/BENCHMARK_JSON]
|
||||
Passed
|
||||
|
||||
Start test 25: Benchmark_Publish_SingleItem[BENCHMARK] Publish_SingleItem: 21ms (21.00ms/item, 1 items)
|
||||
[BENCHMARK_JSON][
|
||||
{
|
||||
"Name": "Publish_SingleItem",
|
||||
"ElapsedMs": 21,
|
||||
"ItemCount": 1,
|
||||
"MsPerItem": 21
|
||||
}
|
||||
][/BENCHMARK_JSON]
|
||||
Passed
|
||||
Start test 26: Benchmark_PublishBranch_DeepTree[BENCHMARK] PublishBranch_DeepTree: 51ms (0.50ms/item, 101 items)
|
||||
[BENCHMARK_JSON][
|
||||
{
|
||||
"Name": "PublishBranch_DeepTree",
|
||||
"ElapsedMs": 51,
|
||||
"ItemCount": 101,
|
||||
"MsPerItem": 0.504950495049505
|
||||
}
|
||||
][/BENCHMARK_JSON]
|
||||
Passed
|
||||
Passed Benchmark_Publish_SingleItem [318 ms]
|
||||
Standard Output Messages:
|
||||
Start test 25: Benchmark_Publish_SingleItem[BENCHMARK] Publish_SingleItem: 21ms (21.00ms/item, 1 items)
|
||||
[BENCHMARK_JSON][
|
||||
{
|
||||
"Name": "Publish_SingleItem",
|
||||
"ElapsedMs": 21,
|
||||
"ItemCount": 1,
|
||||
"MsPerItem": 21
|
||||
}
|
||||
][/BENCHMARK_JSON]
|
||||
Passed
|
||||
|
||||
Passed Benchmark_PublishBranch_DeepTree [1 s]
|
||||
Standard Output Messages:
|
||||
Start test 26: Benchmark_PublishBranch_DeepTree[BENCHMARK] PublishBranch_DeepTree: 51ms (0.50ms/item, 101 items)
|
||||
[BENCHMARK_JSON][
|
||||
{
|
||||
"Name": "PublishBranch_DeepTree",
|
||||
"ElapsedMs": 51,
|
||||
"ItemCount": 101,
|
||||
"MsPerItem": 0.504950495049505
|
||||
}
|
||||
][/BENCHMARK_JSON]
|
||||
Passed
|
||||
|
||||
Start test 27: Benchmark_PublishBranch_ShallowTree[BENCHMARK] PublishBranch_ShallowTree: 50ms (0.50ms/item, 101 items)
|
||||
[BENCHMARK_JSON][
|
||||
{
|
||||
"Name": "PublishBranch_ShallowTree",
|
||||
"ElapsedMs": 50,
|
||||
"ItemCount": 101,
|
||||
"MsPerItem": 0.49504950495049505
|
||||
}
|
||||
][/BENCHMARK_JSON]
|
||||
Passed
|
||||
Passed Benchmark_PublishBranch_ShallowTree [1 s]
|
||||
Standard Output Messages:
|
||||
Start test 27: Benchmark_PublishBranch_ShallowTree[BENCHMARK] PublishBranch_ShallowTree: 50ms (0.50ms/item, 101 items)
|
||||
[BENCHMARK_JSON][
|
||||
{
|
||||
"Name": "PublishBranch_ShallowTree",
|
||||
"ElapsedMs": 50,
|
||||
"ItemCount": 101,
|
||||
"MsPerItem": 0.49504950495049505
|
||||
}
|
||||
][/BENCHMARK_JSON]
|
||||
Passed
|
||||
|
||||
Start test 28: Benchmark_Rollback_ToVersion Failed
|
||||
Failed Benchmark_Rollback_ToVersion [417 ms]
|
||||
Error Message:
|
||||
Need at least 6 versions for rollback test
|
||||
Expected: greater than or equal to 6
|
||||
But was: 1
|
||||
|
||||
Stack Trace:
|
||||
at Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services.ContentServiceRefactoringBenchmarks.Benchmark_Rollback_ToVersion() in /home/yv01p/Umbraco-CMS/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentServiceRefactoringBenchmarks.cs:line 1022
|
||||
|
||||
1) at Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services.ContentServiceRefactoringBenchmarks.Benchmark_Rollback_ToVersion() in /home/yv01p/Umbraco-CMS/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentServiceRefactoringBenchmarks.cs:line 1022
|
||||
|
||||
|
||||
Standard Output Messages:
|
||||
Start test 28: Benchmark_Rollback_ToVersion Failed
|
||||
|
||||
Start test 29: Benchmark_Save_BatchOf100[BENCHMARK] Save_BatchOf100: 676ms (6.76ms/item, 100 items)
|
||||
[BENCHMARK_JSON][
|
||||
{
|
||||
"Name": "Save_BatchOf100",
|
||||
"ElapsedMs": 676,
|
||||
"ItemCount": 100,
|
||||
"MsPerItem": 6.76
|
||||
}
|
||||
][/BENCHMARK_JSON]
|
||||
Passed
|
||||
Passed Benchmark_Save_BatchOf100 [1 s]
|
||||
Standard Output Messages:
|
||||
Start test 29: Benchmark_Save_BatchOf100[BENCHMARK] Save_BatchOf100: 676ms (6.76ms/item, 100 items)
|
||||
[BENCHMARK_JSON][
|
||||
{
|
||||
"Name": "Save_BatchOf100",
|
||||
"ElapsedMs": 676,
|
||||
"ItemCount": 100,
|
||||
"MsPerItem": 6.76
|
||||
}
|
||||
][/BENCHMARK_JSON]
|
||||
Passed
|
||||
|
||||
Start test 30: Benchmark_Save_BatchOf1000[BENCHMARK] Save_BatchOf1000: 7649ms (7.65ms/item, 1000 items)
|
||||
[BENCHMARK_JSON][
|
||||
{
|
||||
"Name": "Save_BatchOf1000",
|
||||
"ElapsedMs": 7649,
|
||||
"ItemCount": 1000,
|
||||
"MsPerItem": 7.649
|
||||
}
|
||||
][/BENCHMARK_JSON]
|
||||
Passed
|
||||
Passed Benchmark_Save_BatchOf1000 [8 s]
|
||||
Standard Output Messages:
|
||||
Start test 30: Benchmark_Save_BatchOf1000[BENCHMARK] Save_BatchOf1000: 7649ms (7.65ms/item, 1000 items)
|
||||
[BENCHMARK_JSON][
|
||||
{
|
||||
"Name": "Save_BatchOf1000",
|
||||
"ElapsedMs": 7649,
|
||||
"ItemCount": 1000,
|
||||
"MsPerItem": 7.649
|
||||
}
|
||||
][/BENCHMARK_JSON]
|
||||
Passed
|
||||
|
||||
Start test 31: Benchmark_Save_SingleItem[BENCHMARK] Save_SingleItem: 7ms (7.00ms/item, 1 items)
|
||||
[BENCHMARK_JSON][
|
||||
{
|
||||
"Name": "Save_SingleItem",
|
||||
"ElapsedMs": 7,
|
||||
"ItemCount": 1,
|
||||
"MsPerItem": 7
|
||||
}
|
||||
][/BENCHMARK_JSON]
|
||||
Passed
|
||||
Passed Benchmark_Save_SingleItem [306 ms]
|
||||
Standard Output Messages:
|
||||
Start test 31: Benchmark_Save_SingleItem[BENCHMARK] Save_SingleItem: 7ms (7.00ms/item, 1 items)
|
||||
[BENCHMARK_JSON][
|
||||
{
|
||||
"Name": "Save_SingleItem",
|
||||
"ElapsedMs": 7,
|
||||
"ItemCount": 1,
|
||||
"MsPerItem": 7
|
||||
}
|
||||
][/BENCHMARK_JSON]
|
||||
Passed
|
||||
|
||||
Start test 32: Benchmark_Sort_100Children[BENCHMARK] Sort_100Children: 758ms (7.58ms/item, 100 items)
|
||||
[BENCHMARK_JSON][
|
||||
{
|
||||
"Name": "Sort_100Children",
|
||||
"ElapsedMs": 758,
|
||||
"ItemCount": 100,
|
||||
"MsPerItem": 7.58
|
||||
}
|
||||
][/BENCHMARK_JSON]
|
||||
Passed
|
||||
Start test 33: Benchmark_Unpublish_SingleItem[BENCHMARK] Unpublish_SingleItem: 23ms (23.00ms/item, 1 items)
|
||||
[BENCHMARK_JSON][
|
||||
{
|
||||
"Name": "Unpublish_SingleItem",
|
||||
"ElapsedMs": 23,
|
||||
"ItemCount": 1,
|
||||
"MsPerItem": 23
|
||||
}
|
||||
][/BENCHMARK_JSON]
|
||||
Passed
|
||||
NUnit Adapter 4.6.0.0: Test execution complete
|
||||
Passed Benchmark_Sort_100Children [1 s]
|
||||
Standard Output Messages:
|
||||
Start test 32: Benchmark_Sort_100Children[BENCHMARK] Sort_100Children: 758ms (7.58ms/item, 100 items)
|
||||
[BENCHMARK_JSON][
|
||||
{
|
||||
"Name": "Sort_100Children",
|
||||
"ElapsedMs": 758,
|
||||
"ItemCount": 100,
|
||||
"MsPerItem": 7.58
|
||||
}
|
||||
][/BENCHMARK_JSON]
|
||||
Passed
|
||||
|
||||
Passed Benchmark_Unpublish_SingleItem [411 ms]
|
||||
Standard Output Messages:
|
||||
Start test 33: Benchmark_Unpublish_SingleItem[BENCHMARK] Unpublish_SingleItem: 23ms (23.00ms/item, 1 items)
|
||||
[BENCHMARK_JSON][
|
||||
{
|
||||
"Name": "Unpublish_SingleItem",
|
||||
"ElapsedMs": 23,
|
||||
"ItemCount": 1,
|
||||
"MsPerItem": 23
|
||||
}
|
||||
][/BENCHMARK_JSON]
|
||||
Passed
|
||||
|
||||
|
||||
Test Run Failed.
|
||||
Total tests: 33
|
||||
Passed: 29
|
||||
Failed: 4
|
||||
Total time: 1.4469 Minutes
|
||||
@@ -0,0 +1,192 @@
|
||||
# Critical Architectural Review: ContentService Refactoring Design
|
||||
|
||||
**Reviewed Document:** `docs/plans/2025-12-19-contentservice-refactor-design.md`
|
||||
**Review Date:** 2025-12-19
|
||||
**Reviewer Role:** Senior Principal Software Architect
|
||||
|
||||
---
|
||||
|
||||
## 1. Overall Assessment
|
||||
|
||||
**Strengths:**
|
||||
- Correctly identifies a real maintainability problem (~3800 lines monolith)
|
||||
- Preserves backward compatibility via facade pattern (essential for Umbraco ecosystem)
|
||||
- Clear separation by functional domain (CRUD, Publishing, Move)
|
||||
- Aligns with Umbraco's existing layered architecture (interfaces in Core, implementations in Infrastructure)
|
||||
|
||||
**Major Concerns:**
|
||||
- **Naming collision** with existing `ContentPublishingService` already in codebase
|
||||
- **Cross-service transaction coordination** inadequately addressed
|
||||
- **Arbitrary public/internal distinction** doesn't match actual usage patterns
|
||||
- **Missing mapping** for several existing methods that don't fit cleanly into proposed services
|
||||
|
||||
---
|
||||
|
||||
## 2. Critical Issues
|
||||
|
||||
### 2.1 Naming Collision with Existing ContentPublishingService
|
||||
|
||||
**Description:** A `ContentPublishingService` already exists at `src/Umbraco.Core/Services/ContentPublishingService.cs:16` with interface `IContentPublishingService`. The proposed `IContentPublishingService` would directly conflict.
|
||||
|
||||
**Impact:** Build failure or confusing namespace disambiguation; existing consumers of `IContentPublishingService` would break or become ambiguous.
|
||||
|
||||
**Suggestion:** Rename the proposed interface to `IContentPublishOperationService` or `IContentPublicationService`, OR refactor the existing `ContentPublishingService` to use the new infrastructure.
|
||||
|
||||
---
|
||||
|
||||
### 2.2 Cross-Service Dependencies Create Circular Risk
|
||||
|
||||
**Description:** The proposed services have intrinsic coupling:
|
||||
- `MoveToRecycleBin` (Move) fires `ContentUnpublishedNotification` for published content (requires Publishing awareness)
|
||||
- `Publish` (Publishing) calls `Save` internally (requires CRUD)
|
||||
- `Copy` (Move) calls `Save` and checks `GetPermissions` (requires CRUD and Permissions)
|
||||
|
||||
**Impact:** Either circular dependencies between services OR the facade must orchestrate complex multi-service operations, defeating decomposition benefits.
|
||||
|
||||
**Suggestion:** Extract a shared `ContentOperationOrchestrator` that coordinates cross-cutting operations, or make Publishing/Move depend on CRUD (unidirectional), with explicit dependency documentation.
|
||||
|
||||
---
|
||||
|
||||
### 2.3 Transaction Boundary Ownership Unclear
|
||||
|
||||
**Description:** The design states "Ensure scopes work across service calls" but doesn't specify:
|
||||
- Who creates the scope when `ContentMoveService.MoveToRecycleBin` needs to unpublish content?
|
||||
- Can services assume they're called within an existing scope, or must each method create its own?
|
||||
- How do nested scope behaviors work when Service A calls Service B?
|
||||
|
||||
**Impact:** Inconsistent transaction handling could lead to partial commits, audit log inconsistencies, or notification ordering issues.
|
||||
|
||||
**Suggestion:** Define explicit scope ownership rules:
|
||||
- **Option A:** All public service methods create their own scope (simple, but nested operations may have issues)
|
||||
- **Option B:** Services accept optional `ICoreScope` parameter for caller-managed transactions
|
||||
- **Option C:** Use ambient scope pattern consistently (document the pattern)
|
||||
|
||||
---
|
||||
|
||||
### 2.4 Arbitrary Public vs Internal Classification
|
||||
|
||||
**Description:** The design classifies:
|
||||
- **Public:** CRUD, Publishing, Move
|
||||
- **Internal:** Versioning, Query, Permission, Blueprint
|
||||
|
||||
But examining actual usage:
|
||||
- `GetVersions`, `Rollback`, `DeleteVersions` are public on `IContentService`
|
||||
- `GetPermissions`, `SetPermissions` are public on `IContentService`
|
||||
- `GetPagedChildren`, `GetAncestors`, `Count` are frequently used externally
|
||||
- Blueprints have public API methods
|
||||
|
||||
**Impact:** Internal helpers cannot be injected by consumers who need specific functionality. Forces continued use of `IContentService` facade for everything.
|
||||
|
||||
**Suggestion:** Either:
|
||||
- Make Query and Versioning public (they represent distinct concerns API consumers need)
|
||||
- OR keep all as internal and document that `IContentService` remains the public API (current approach but explicitly stated)
|
||||
|
||||
---
|
||||
|
||||
### 2.5 Missing Method Mappings
|
||||
|
||||
**Description:** Several existing methods don't cleanly map to proposed services:
|
||||
|
||||
| Method | Proposed Location | Problem |
|
||||
|--------|------------------|---------|
|
||||
| `SendToPublication` | ? | Not listed, involves Save + events |
|
||||
| `CheckDataIntegrity` | ? | Not listed, infrastructure concern |
|
||||
| `DeleteOfTypes` | CRUD? Move? | Moves children to bin, then deletes |
|
||||
| `CommitDocumentChanges` | Publishing? | Internal but critical for scheduling |
|
||||
| `GetPublishedChildren` | Query? Publishing? | Uses Published status (domain crossover) |
|
||||
|
||||
**Impact:** Implementation will encounter methods that don't fit, leading to ad-hoc placement or leaky abstractions.
|
||||
|
||||
**Suggestion:** Create explicit method-to-service mapping table covering ALL 80+ methods in current `IContentService`. Identify "orchestration" methods that may stay in facade.
|
||||
|
||||
---
|
||||
|
||||
### 2.6 Notification Consistency Risk
|
||||
|
||||
**Description:** ContentService fires ~20 different notification types (`ContentSaving`, `ContentPublishing`, `ContentMoving`, etc.) with specific state propagation via `WithStateFrom()`. Splitting services means:
|
||||
- Each service must correctly fire its subset of notifications
|
||||
- State must be preserved across service boundaries
|
||||
- Notification ordering must remain consistent
|
||||
|
||||
**Impact:** Breaking notification contracts would affect cache invalidation, webhooks, search indexing, and third-party packages.
|
||||
|
||||
**Suggestion:** Add explicit notification responsibility matrix to design. Consider a `ContentNotificationService` that centralizes notification logic, called by all sub-services.
|
||||
|
||||
---
|
||||
|
||||
## 3. Alternative Architectural Challenge
|
||||
|
||||
### Alternative: Vertical Slicing by Operation Complexity
|
||||
|
||||
Instead of horizontal domain slicing (CRUD/Publishing/Move), slice vertically by operation complexity:
|
||||
|
||||
**Proposed Structure:**
|
||||
1. `ContentReadService` - All read operations (Get, Count, Query, Versions read-only)
|
||||
2. `ContentWriteService` - All simple mutations (Create, Save, Delete)
|
||||
3. `ContentWorkflowService` - All complex stateful operations (Publish, Unpublish, Schedule, Move, MoveToRecycleBin)
|
||||
|
||||
**Pro:** Matches actual dependency patterns - reads are independent, writes have minimal coupling, workflows can depend on both. Simpler transaction model.
|
||||
|
||||
**Con:** Workflows service could still grow large; doesn't solve the "where does Copy go" problem.
|
||||
|
||||
---
|
||||
|
||||
## 4. Minor Issues & Improvements
|
||||
|
||||
### 4.1 Line Count Estimates May Be Optimistic
|
||||
|
||||
The `ContentPublishingService` is estimated at ~800 lines, but `CommitDocumentChangesInternal` alone is 330+ lines with complex culture/scheduling logic. Consider splitting publishing into Immediate vs Scheduled sub-components.
|
||||
|
||||
### 4.2 Missing Async Consideration
|
||||
|
||||
Existing `EmptyRecycleBinAsync` suggests async patterns are emerging. New services should define async-first interfaces where database operations are involved.
|
||||
|
||||
### 4.3 No Explicit Interface for ContentServiceBase
|
||||
|
||||
The design shows `ContentServiceBase` as abstract class but doesn't specify if it implements any interface. Consider `IContentServiceBase` for testing.
|
||||
|
||||
### 4.4 Helper Naming Convention
|
||||
|
||||
"Helper" suffix is discouraged in modern .NET. Consider `ContentVersionManager`, `ContentQueryExecutor`, etc.
|
||||
|
||||
---
|
||||
|
||||
## 5. Questions for Clarification
|
||||
|
||||
1. **Existing IContentPublishingService:** Should the current `ContentPublishingService` be refactored to use the new infrastructure, replaced, or renamed?
|
||||
|
||||
2. **Branch Publishing:** The complex `PublishBranch` operation (200+ lines) spans publishing AND tree traversal. Which service owns it?
|
||||
|
||||
3. **Locking Strategy:** Current code uses explicit `scope.WriteLock(Constants.Locks.ContentTree)`. Will each sub-service acquire locks independently, or is there a coordination pattern?
|
||||
|
||||
4. **Culture-Variant Complexity:** The `CommitDocumentChangesInternal` method handles 15+ different publish result types with culture awareness. Is this complexity remaining in one place or distributed?
|
||||
|
||||
5. **RepositoryService Base Class:** Current `ContentService : RepositoryService`. Do new services also inherit this, or get dependencies differently?
|
||||
|
||||
---
|
||||
|
||||
## 6. Final Recommendation
|
||||
|
||||
### Major Revisions Needed
|
||||
|
||||
The design addresses a real problem and the overall direction is sound, but implementation will hit significant obstacles without addressing the following:
|
||||
|
||||
| Priority | Action Item | Status |
|
||||
|----------|-------------|--------|
|
||||
| **P0** | Resolve naming collision with existing `ContentPublishingService` | Required |
|
||||
| **P0** | Document transaction/scope ownership explicitly | Required |
|
||||
| **P0** | Create complete method mapping covering all 80+ IContentService methods | Required |
|
||||
| **P1** | Define notification responsibility matrix per service | Required |
|
||||
| **P1** | Reconsider public/internal classification based on actual API usage patterns | Recommended |
|
||||
| **P1** | Address cross-service dependency direction (who can call whom) | Recommended |
|
||||
|
||||
Once these are addressed, the refactoring approach is viable and would meaningfully improve maintainability.
|
||||
|
||||
---
|
||||
|
||||
## Appendix: Key Files Reviewed
|
||||
|
||||
- `src/Umbraco.Core/Services/ContentService.cs` (3824 lines)
|
||||
- `src/Umbraco.Core/Services/IContentService.cs` (522 lines, ~80 methods)
|
||||
- `src/Umbraco.Core/Services/ContentPublishingService.cs` (existing, conflicts with proposal)
|
||||
- `src/Umbraco.Core/CLAUDE.md` (architecture patterns reference)
|
||||
@@ -0,0 +1,469 @@
|
||||
# Critical Architectural Review: ContentService Refactoring Design v1.5
|
||||
|
||||
**Reviewed Document:** `docs/plans/2025-12-19-contentservice-refactor-design.md`
|
||||
**Review Date:** 2025-12-20
|
||||
**Reviewer Role:** Senior Principal Software Architect
|
||||
**Document Revision:** 1.5 (includes performance benchmarks)
|
||||
**Review Revision:** 2.0 (incorporates clarifications and deep-dive analysis)
|
||||
|
||||
---
|
||||
|
||||
## Executive Summary
|
||||
|
||||
The ContentService refactoring design is **approved with changes**. The core architecture is sound, the phased approach provides good risk mitigation, and the design addresses a real maintainability problem. This review incorporates deep-dive analysis of locking infrastructure, performance testing strategy, and clarifications on key architectural decisions.
|
||||
|
||||
### Key Clarifications Incorporated
|
||||
|
||||
| Question | Decision |
|
||||
|----------|----------|
|
||||
| IContentService facade lifespan | **Remains indefinitely** - not deprecated |
|
||||
| Persistence layer | **NPoco repositories first** - EF Core migration is separate concern |
|
||||
| Hierarchical locking | **Phase 9** - post-refactoring optimization |
|
||||
| Performance testing | **Extend existing pattern** - use integration test infrastructure |
|
||||
|
||||
---
|
||||
|
||||
## 1. Overall Assessment
|
||||
|
||||
### Strengths
|
||||
|
||||
- **Comprehensive method mapping** - All 80+ `IContentService` methods explicitly mapped to target services
|
||||
- **Clear dependency direction** - Unidirectional: PublishOperation/Move → CRUD only; no circular dependencies
|
||||
- **Solid transaction model** - Ambient scope pattern well-documented with facade orchestration
|
||||
- **Extensive notification matrix** - Each notification assigned to specific service with state preservation
|
||||
- **Test-first approach** - 15 targeted integration tests + benchmarks with phase gates
|
||||
- **Performance awareness** - N+1 queries and memory allocation issues identified with specific line numbers
|
||||
|
||||
### Concerns Addressed in This Review
|
||||
|
||||
| Concern | Resolution |
|
||||
|---------|------------|
|
||||
| Lock contention bottleneck | Defer to Phase 9; document lock contracts during extraction |
|
||||
| Benchmark infrastructure gaps | Extend existing `ContentServicePerformanceTest` pattern |
|
||||
| Performance optimization timing | Separate from extraction phases |
|
||||
| Baseline comparison workflow | Structured JSON output with manual comparison |
|
||||
|
||||
---
|
||||
|
||||
## 2. Critical Issues
|
||||
|
||||
### 2.1 Lock Contention Architecture (Documented Limitation)
|
||||
|
||||
**Current State Analysis:**
|
||||
|
||||
The ContentService contains 58 lock acquisition points:
|
||||
- 31 `ReadLock(Constants.Locks.ContentTree)`
|
||||
- 27 `WriteLock(Constants.Locks.ContentTree)`
|
||||
- All use the SAME global lock
|
||||
|
||||
**Primary Bottleneck - `PerformMoveLocked` (lines 2570-2620):**
|
||||
|
||||
```csharp
|
||||
// Holds WriteLock while iterating ALL descendants
|
||||
const int pageSize = 500;
|
||||
do {
|
||||
foreach (IContent descendant in descendants) {
|
||||
PerformMoveContentLocked(descendant, userId, trash); // DB write per item
|
||||
}
|
||||
} while (total > pageSize);
|
||||
```
|
||||
|
||||
Moving a tree with 5,000 descendants holds the global lock for the duration of 5,000+ database writes.
|
||||
|
||||
**Decision:** Accept as known limitation during extraction phases. Implement hierarchical locking in Phase 9.
|
||||
|
||||
**Mitigation:** Each new service must document its lock contract (see Section 5.2).
|
||||
|
||||
---
|
||||
|
||||
### 2.2 Performance Optimization Phasing
|
||||
|
||||
**Issue:** The design mixes 20+ performance optimizations with refactoring phases without clear separation.
|
||||
|
||||
**Resolution:** Performance optimizations are separated into distinct phases:
|
||||
|
||||
| Phase | Focus | Performance Work |
|
||||
|-------|-------|------------------|
|
||||
| 0-8 | Extraction | **None** - preserve existing behavior |
|
||||
| 9 | Locking | Hierarchical/fine-grained locking |
|
||||
| 10+ | Optimization | N+1 fixes, memory allocation, caching |
|
||||
|
||||
**Rationale:**
|
||||
1. Mixing refactoring with optimization compounds risk
|
||||
2. Benchmarks can measure each improvement independently
|
||||
3. Extraction phases remain focused on code organization
|
||||
|
||||
---
|
||||
|
||||
### 2.3 Benchmark Infrastructure
|
||||
|
||||
**Issue:** The design proposed custom benchmark infrastructure (33 tests, JSON output, regression detection) that duplicates effort.
|
||||
|
||||
**Resolution:** Extend existing `ContentServicePerformanceTest` pattern.
|
||||
|
||||
**Existing Infrastructure:**
|
||||
- `ContentServicePerformanceTest.cs` - Established pattern with `Stopwatch`
|
||||
- `[LongRunning]` attribute - Category filter for slow tests
|
||||
- `TestProfiler` - MiniProfiler integration for SQL tracing
|
||||
- `UmbracoIntegrationTestWithContent` - Base class with pre-created content
|
||||
- Full DI + SQLite database - Integration test infrastructure
|
||||
|
||||
**New Infrastructure Created:**
|
||||
- `ContentServiceBenchmarkBase.cs` - Extends existing pattern with structured output
|
||||
- JSON markers for automated extraction: `[BENCHMARK_JSON]...[/BENCHMARK_JSON]`
|
||||
- `MeasureAndRecord()` helper methods
|
||||
|
||||
**Benchmark Execution:**
|
||||
```bash
|
||||
# Capture baseline (before Phase 0)
|
||||
dotnet test tests/Umbraco.Tests.Integration \
|
||||
--filter "Category=Benchmark" \
|
||||
--logger "console;verbosity=detailed" | tee benchmark-baseline.txt
|
||||
|
||||
# Extract JSON results
|
||||
grep -oP '\[BENCHMARK_JSON\]\K.*(?=\[/BENCHMARK_JSON\])' benchmark-baseline.txt > baseline.json
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 2.4 DeleteOfType/DeleteOfTypes Placement
|
||||
|
||||
**Issue:** These methods are mapped to `IContentCrudService` but require orchestration (move descendants to bin first).
|
||||
|
||||
**Resolution:** Move to Facade.
|
||||
|
||||
**Updated Facade Orchestration Methods:**
|
||||
|
||||
| Method | Why in Facade |
|
||||
|--------|---------------|
|
||||
| `MoveToRecycleBin` | Unpublishes content then moves |
|
||||
| `DeleteOfType` | Moves descendants to bin, then deletes type content |
|
||||
| `DeleteOfTypes` | Moves descendants to bin, then deletes multiple type content |
|
||||
|
||||
---
|
||||
|
||||
## 3. Architectural Decisions
|
||||
|
||||
### 3.1 IContentService Facade Permanence
|
||||
|
||||
**Decision:** The `IContentService` facade remains indefinitely as the stable public API.
|
||||
|
||||
**Implications:**
|
||||
- External consumers (packages, integrations) continue using `IContentService`
|
||||
- New granular services (`IContentCrudService`, etc.) are available for internal use and advanced scenarios
|
||||
- No deprecation warnings on `IContentService`
|
||||
- Facade overhead is acceptable for API stability
|
||||
|
||||
**Documentation Requirement:** Add to design document:
|
||||
> The `IContentService` interface and its facade implementation are permanent public API.
|
||||
> The granular services provide decomposition benefits internally while maintaining
|
||||
> backward compatibility for all existing consumers.
|
||||
|
||||
---
|
||||
|
||||
### 3.2 NPoco Repository Implementation
|
||||
|
||||
**Decision:** Implement all new services against NPoco repositories first.
|
||||
|
||||
**Implications:**
|
||||
- Use existing `IDocumentRepository` (NPoco-based)
|
||||
- No EF Core dependencies in initial implementation
|
||||
- EF Core migration is a separate initiative
|
||||
- Services are persistence-agnostic via repository interfaces
|
||||
|
||||
**Implementation Pattern:**
|
||||
```csharp
|
||||
public class ContentCrudService : ContentServiceBase, IContentCrudService
|
||||
{
|
||||
private readonly IDocumentRepository _documentRepository; // NPoco
|
||||
|
||||
// Implementation uses existing repository patterns
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 3.3 Hierarchical Locking (Phase 9)
|
||||
|
||||
**Decision:** Defer hierarchical/fine-grained locking to Phase 9, after extraction is complete.
|
||||
|
||||
**Rationale:**
|
||||
1. **Clearer ownership** - After extraction, each service owns its locks
|
||||
2. **Easier to reason about** - 10-15 lock points per service vs. 58 in monolith
|
||||
3. **Measurable** - Benchmarks show actual impact
|
||||
4. **Risk isolation** - Locking changes isolated from refactoring
|
||||
|
||||
**Phase 9 Scope:**
|
||||
- Design lock hierarchy (path-based or operation-based)
|
||||
- Update scope infrastructure if needed
|
||||
- Migrate each service to granular locks
|
||||
- Benchmark comparison
|
||||
|
||||
**Estimated Effort:** 3-5 days
|
||||
|
||||
**Possible Approaches:**
|
||||
```csharp
|
||||
// Option A: Path-based locks (lock subtree only)
|
||||
scope.WriteLock(Constants.Locks.ContentTree, content.Path);
|
||||
|
||||
// Option B: Operation-specific locks
|
||||
scope.WriteLock(Constants.Locks.ContentTreeMove);
|
||||
scope.WriteLock(Constants.Locks.ContentTreePublish);
|
||||
|
||||
// Option C: Hybrid (operation + path)
|
||||
scope.WriteLock(Constants.Locks.ContentTreeMove, content.Path);
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 4. Performance Testing Strategy
|
||||
|
||||
### 4.1 Benchmark Timing
|
||||
|
||||
| Checkpoint | When | Purpose |
|
||||
|------------|------|---------|
|
||||
| **Baseline** | Before Phase 0 | Capture current behavior before ANY changes |
|
||||
| **Phase 1** | After CRUD Service | Validate foundation patterns |
|
||||
| **Phase 5** | After Publish Operation | Highest-risk phase (N+1 hotspots) |
|
||||
| **Phase 8** | After Facade | Final validation - all services integrated |
|
||||
| **Phase 9** | After Locking | Measure lock optimization impact |
|
||||
|
||||
**Exception Rule:** If a phase encounters unexpected complexity or touches a known hotspot, run benchmarks immediately after.
|
||||
|
||||
### 4.2 Prioritized Benchmarks
|
||||
|
||||
Based on identified hotspots in the design document:
|
||||
|
||||
| Priority | Benchmark | Target | Hotspot |
|
||||
|----------|-----------|--------|---------|
|
||||
| **P0** | `GetContentSchedulesByIds_100Items` | N+1 at line 1025-1049 | `_idKeyMap.GetIdForKey` loop |
|
||||
| **P0** | `PublishBranch_100Items` | Lock contention | Tree traversal under lock |
|
||||
| **P0** | `MoveToRecycleBin_LargeTree` | Lock duration | `PerformMoveLocked` line 2600+ |
|
||||
| **P1** | `Save_BatchOf100` | Core CRUD | Baseline mutation performance |
|
||||
| **P1** | `GetAncestors_10Levels` | N+1 prone | Repeated single lookups line 792 |
|
||||
| **P1** | `EmptyRecycleBin_100Items` | Lock duration | Delete loop under lock |
|
||||
| **P2** | `Sort_100Children` | Notification ordering | Cross-service coordination |
|
||||
| **P2** | `Copy_Recursive_50Items` | Cross-service | Recursive operation |
|
||||
|
||||
### 4.3 Baseline Comparison Workflow
|
||||
|
||||
**Capture:**
|
||||
```bash
|
||||
dotnet test tests/Umbraco.Tests.Integration \
|
||||
--filter "Category=Benchmark&FullyQualifiedName~ContentServiceRefactoringBenchmarks" \
|
||||
--logger "console;verbosity=detailed" 2>&1 | tee benchmark-$(git rev-parse --short HEAD).txt
|
||||
```
|
||||
|
||||
**Compare:**
|
||||
```bash
|
||||
# Manual comparison of JSON outputs
|
||||
diff baseline.json current.json
|
||||
|
||||
# Or simple script
|
||||
jq -s '.[0] as $base | .[1] | to_entries | map({
|
||||
name: .key,
|
||||
baseline: $base[.key].ElapsedMs,
|
||||
current: .value.ElapsedMs,
|
||||
change: ((.value.ElapsedMs - $base[.key].ElapsedMs) / $base[.key].ElapsedMs * 100 | round)
|
||||
})' baseline.json current.json
|
||||
```
|
||||
|
||||
**Regression Threshold:** 20% degradation triggers investigation (manual, not automated).
|
||||
|
||||
---
|
||||
|
||||
## 5. Implementation Requirements
|
||||
|
||||
### 5.1 Updated Phase Structure
|
||||
|
||||
| Phase | Service | Lock Documentation | Benchmarks |
|
||||
|-------|---------|-------------------|------------|
|
||||
| 0 | Write tests | N/A | **Run baseline** |
|
||||
| 1 | CRUD Service | Document lock contract | **Run benchmarks** |
|
||||
| 2 | Query Service | Document lock contract | - |
|
||||
| 3 | Version Service | Document lock contract | - |
|
||||
| 4 | Move Service | Document lock contract | - |
|
||||
| 5 | Publish Operation | Document lock contract | **Run benchmarks** |
|
||||
| 6 | Permission Manager | Document lock contract | - |
|
||||
| 7 | Blueprint Manager | Document lock contract | - |
|
||||
| 8 | Facade | Verify all contracts | **Run benchmarks** |
|
||||
| 9 | Locking Optimization | Implement changes | **Run benchmarks** |
|
||||
| 10+ | Performance Optimization | N/A | Per-optimization |
|
||||
|
||||
### 5.2 Lock Contract Documentation Template
|
||||
|
||||
Each new service interface must include:
|
||||
|
||||
```csharp
|
||||
/// <summary>
|
||||
/// Provides move, copy, and recycle bin operations for content.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para><strong>Lock Contract:</strong></para>
|
||||
/// <list type="bullet">
|
||||
/// <item><c>WriteLock(ContentTree)</c>: Move, MoveToRecycleBin, Copy, Sort, EmptyRecycleBin</item>
|
||||
/// <item><c>ReadLock(ContentTree)</c>: GetPagedContentInRecycleBin, RecycleBinSmells</item>
|
||||
/// </list>
|
||||
///
|
||||
/// <para><strong>Lock Duration Concerns:</strong></para>
|
||||
/// <list type="bullet">
|
||||
/// <item>Move/MoveToRecycleBin: Iterates descendants, O(n) lock duration</item>
|
||||
/// <item>EmptyRecycleBin: Deletes all bin content, O(n) lock duration</item>
|
||||
/// </list>
|
||||
///
|
||||
/// <para><strong>Phase 9 Optimization Opportunity:</strong></para>
|
||||
/// <list type="bullet">
|
||||
/// <item>Move/Copy: Could use subtree locks (lock path prefix)</item>
|
||||
/// <item>Sort: Only needs lock on parent node</item>
|
||||
/// </list>
|
||||
/// </remarks>
|
||||
public interface IContentMoveService
|
||||
{
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
### 5.3 Git Checkpoint Strategy
|
||||
|
||||
Add to regression protocol:
|
||||
|
||||
```
|
||||
1. Create tagged commit at each phase gate completion
|
||||
git tag phase-1-complete -m "CRUD Service extraction complete"
|
||||
|
||||
2. If phase fails testing, revert to previous tag
|
||||
git reset --hard phase-0-complete
|
||||
|
||||
3. Benchmark results stored with commit hash
|
||||
benchmark-{commit-hash}.json
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 6. Minor Issues & Improvements
|
||||
|
||||
### 6.1 Phase Gate Test Commands
|
||||
|
||||
**Issue:** Current filter matches too broadly.
|
||||
|
||||
**Fix:**
|
||||
```bash
|
||||
# Refactoring-specific tests (fast feedback)
|
||||
dotnet test tests/Umbraco.Tests.Integration \
|
||||
--filter "FullyQualifiedName~ContentServiceRefactoringTests"
|
||||
|
||||
# All ContentService tests (phase gate) - more specific
|
||||
dotnet test tests/Umbraco.Tests.Integration \
|
||||
--filter "FullyQualifiedName~Umbraco.Infrastructure.Services.ContentService"
|
||||
```
|
||||
|
||||
### 6.2 API Layer Impact
|
||||
|
||||
**Clarification needed:** The Management API (`Umbraco.Cms.Api.Management`) exposes content operations.
|
||||
|
||||
**Resolution:** No API changes required.
|
||||
|
||||
> The existing `IContentPublishingService` (API layer) continues to use `IContentService` facade.
|
||||
> After refactoring, it indirectly uses new services through the unchanged facade interface.
|
||||
> No API version bump or endpoint changes needed.
|
||||
|
||||
### 6.3 Existing Benchmarks Project
|
||||
|
||||
**Analysis:** The `Umbraco.Tests.Benchmarks` project with BenchmarkDotNet does NOT meet the needs:
|
||||
|
||||
| Requirement | Status |
|
||||
|-------------|--------|
|
||||
| BenchmarkDotNet | Available (v0.15.6) |
|
||||
| Database access | Missing |
|
||||
| Service DI container | Missing |
|
||||
| Integration test base class | Missing |
|
||||
|
||||
**Decision:** Use integration test infrastructure instead. The existing `ContentServicePerformanceTest` pattern is battle-tested and provides full database/DI access.
|
||||
|
||||
---
|
||||
|
||||
## 7. Questions Resolved
|
||||
|
||||
| # | Question | Resolution |
|
||||
|---|----------|------------|
|
||||
| 1 | Baseline timing | Before Phase 0, before any code changes |
|
||||
| 2 | BenchmarkDotNet vs custom | Extend existing integration test pattern |
|
||||
| 3 | Lock contention acceptance | Accept during extraction; optimize in Phase 9 |
|
||||
| 4 | Facade deprecation path | No deprecation - remains indefinitely |
|
||||
| 5 | EF Core vs NPoco | NPoco first; EF Core migration is separate |
|
||||
|
||||
---
|
||||
|
||||
## 8. First Component to Fail Analysis
|
||||
|
||||
Under increasing concurrent load, the following failure sequence is predicted:
|
||||
|
||||
| Order | Component | Failure Mode | Mitigation |
|
||||
|-------|-----------|--------------|------------|
|
||||
| 1st | `GetContentSchedulesByIds` | N+1 queries exhaust connection pool (~50 concurrent) | Phase 10: Batch lookup |
|
||||
| 2nd | `PublishBranch` | Lock held during tree traversal blocks all writes | Phase 9: Subtree locks |
|
||||
| 3rd | `PerformMoveLocked` | Lock held for O(n) descendants causes timeouts | Phase 9: Batch updates |
|
||||
|
||||
All three are documented in the design's Performance Optimizations section. The question of whether optimization is required before or after extraction is now resolved: **after** (Phase 9+).
|
||||
|
||||
---
|
||||
|
||||
## 9. Final Recommendation
|
||||
|
||||
### Approved With Changes
|
||||
|
||||
The design is approved for implementation with the following required changes:
|
||||
|
||||
| Priority | Action Item | Category |
|
||||
|----------|-------------|----------|
|
||||
| **P0** | Add Phase 9 for hierarchical locking to phase list | Scope |
|
||||
| **P0** | Move `DeleteOfType`/`DeleteOfTypes` to Facade | Design |
|
||||
| **P0** | Add lock contract documentation requirement to each service | Process |
|
||||
| **P1** | Add git checkpoint strategy to regression protocol | Process |
|
||||
| **P1** | Clarify facade permanence in design document | Documentation |
|
||||
| **P1** | Add "NPoco first" constraint to implementation notes | Documentation |
|
||||
| **P2** | Fix phase gate test filter commands | Documentation |
|
||||
| **P2** | Add API layer impact note (no changes needed) | Documentation |
|
||||
|
||||
### Implementation Ready
|
||||
|
||||
Once the above changes are incorporated into the design document, implementation can proceed. The phased approach with test gates provides good risk mitigation for a refactoring of this scope.
|
||||
|
||||
---
|
||||
|
||||
## Appendix A: Files Created During Review
|
||||
|
||||
| File | Purpose |
|
||||
|------|---------|
|
||||
| `tests/.../Testing/ContentServiceBenchmarkBase.cs` | Benchmark infrastructure base class |
|
||||
|
||||
## Appendix B: Key Source Files Analyzed
|
||||
|
||||
| File | Lines | Purpose |
|
||||
|------|-------|---------|
|
||||
| `src/Umbraco.Core/Services/ContentService.cs` | 3823 | Current monolithic implementation |
|
||||
| `src/Umbraco.Core/Services/IContentPublishingService.cs` | 57 | Existing API-layer service (no collision) |
|
||||
| `tests/.../Services/ContentServicePerformanceTest.cs` | 280 | Existing benchmark pattern |
|
||||
| `tests/.../Testing/UmbracoIntegrationTestWithContent.cs` | 83 | Integration test base |
|
||||
| `tests/Umbraco.Tests.Benchmarks/*.cs` | Various | BenchmarkDotNet project (not suitable) |
|
||||
|
||||
## Appendix C: Lock Inventory Summary
|
||||
|
||||
**Current ContentService Lock Distribution:**
|
||||
|
||||
| Lock Type | Count | Operations |
|
||||
|-----------|-------|------------|
|
||||
| `ReadLock(ContentTree)` | 31 | Get*, Count*, Has*, IsPath*, RecycleBinSmells |
|
||||
| `WriteLock(ContentTree)` | 27 | Save, Delete, Publish, Unpublish, Move, Copy, Sort |
|
||||
|
||||
**Post-Refactoring Distribution (estimated):**
|
||||
|
||||
| Service | ReadLocks | WriteLocks |
|
||||
|---------|-----------|------------|
|
||||
| ContentCrudService | 8 | 4 |
|
||||
| ContentQueryService | 12 | 0 |
|
||||
| ContentVersionService | 4 | 3 |
|
||||
| ContentMoveService | 2 | 8 |
|
||||
| ContentPublishOperationService | 5 | 10 |
|
||||
| ContentPermissionManager | 0 | 2 |
|
||||
| ContentBlueprintManager | 2 | 4 |
|
||||
@@ -0,0 +1,669 @@
|
||||
# Critical Architectural Review: ContentService Refactoring Design v1.6
|
||||
|
||||
**Reviewed Document:** `docs/plans/2025-12-19-contentservice-refactor-design.md`
|
||||
**Review Date:** 2025-12-20
|
||||
**Reviewer Role:** Senior Principal Software Architect
|
||||
**Document Revision:** 1.6 (post-critical-review changes applied)
|
||||
**Review Revision:** 3.0
|
||||
|
||||
---
|
||||
|
||||
## Executive Summary
|
||||
|
||||
The ContentService refactoring design v1.6 is **approved with changes**. The design has matured through two prior reviews and addresses the core architectural challenges. This review identifies remaining refinements and documents resolutions for all outstanding issues.
|
||||
|
||||
### Resolution Summary
|
||||
|
||||
| Issue | Decision |
|
||||
|-------|----------|
|
||||
| Facade permanence | Keep facade, mark for future deprecation |
|
||||
| Regression threshold | Add automated guard script |
|
||||
| Cross-service failures | Add failure mode documentation |
|
||||
| Phase 9 scope | Split into sub-phases 9a-9d |
|
||||
| Phase 0 deliverables | Add test/benchmark file creation |
|
||||
| ContentServiceBase testing | Add unit tests |
|
||||
| Async expansion | Defer to future initiative |
|
||||
| Rollback triggers | Document for future reference (not required) |
|
||||
|
||||
---
|
||||
|
||||
## 1. Overall Assessment
|
||||
|
||||
### Strengths
|
||||
|
||||
- **Mature design** - Two prior reviews have addressed major structural issues (naming, transactions, method mapping)
|
||||
- **Comprehensive documentation** - Lock contracts, notification matrix, 80+ method mapping all present
|
||||
- **Risk-conscious phasing** - Clear separation of extraction (0-8), locking (9), optimization (10+)
|
||||
- **Test-first approach** - 15 targeted tests + 33 benchmarks with phase gates
|
||||
- **Architectural alignment** - Follows Umbraco Core patterns (interface-first, notification system, scoping)
|
||||
|
||||
### Issues Addressed in This Review
|
||||
|
||||
| Category | Severity | Issue | Resolution |
|
||||
|----------|----------|-------|------------|
|
||||
| Strategic | Medium | Facade permanence | Future deprecation noted |
|
||||
| Operational | Medium | Manual regression threshold | Automated guard added |
|
||||
| Technical | Low-Medium | Cross-service failure modes | Documentation added |
|
||||
| Process | Low | Phase 9 scope | Split into sub-phases |
|
||||
|
||||
---
|
||||
|
||||
## 2. Critical Issues and Resolutions
|
||||
|
||||
### 2.1 Facade Deprecation Strategy
|
||||
|
||||
**Issue:** The design declared `IContentService` as "permanent public API" with no deprecation path, creating indefinite dual-maintenance burden.
|
||||
|
||||
**Resolution:** The facade remains the stable public API for this refactoring but will be marked for future deprecation.
|
||||
|
||||
**Required Design Update:**
|
||||
|
||||
```markdown
|
||||
### Facade Deprecation Strategy
|
||||
|
||||
> The `IContentService` interface and its facade implementation remain the **stable public API**
|
||||
> for this refactoring initiative. External consumers should continue using `IContentService`.
|
||||
>
|
||||
> **Future Deprecation:** In a future major version, `IContentService` will be marked as
|
||||
> `[Obsolete]` with guidance to migrate to granular services (`IContentCrudService`,
|
||||
> `IContentPublishOperationService`, etc.). The deprecation timeline will be announced
|
||||
> separately and will include:
|
||||
> - Minimum 2 major versions warning period
|
||||
> - Migration guide documentation
|
||||
> - Analyzer rules to identify usage patterns
|
||||
>
|
||||
> For now, the granular services are available for:
|
||||
> - Internal Umbraco code
|
||||
> - Advanced scenarios requiring fine-grained control
|
||||
> - Early adopters willing to accept API changes
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 2.2 Automated Regression Guard
|
||||
|
||||
**Issue:** The design specified "20% degradation triggers investigation (manual, not automated)" which risks regressions slipping through unnoticed.
|
||||
|
||||
**Resolution:** Add an automated guard script to the phase gate process.
|
||||
|
||||
**Required Design Update - Add to "Benchmark Execution Commands" section:**
|
||||
|
||||
```markdown
|
||||
### Automated Regression Detection
|
||||
|
||||
Add this script to CI or use at each phase gate:
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
# regression-guard.sh - Fails if any benchmark regresses >20%
|
||||
|
||||
set -e
|
||||
|
||||
BASELINE_FILE="${1:-baseline.json}"
|
||||
CURRENT_FILE="${2:-current.json}"
|
||||
THRESHOLD=${3:-20}
|
||||
|
||||
if [ ! -f "$BASELINE_FILE" ] || [ ! -f "$CURRENT_FILE" ]; then
|
||||
echo "Usage: regression-guard.sh <baseline.json> <current.json> [threshold]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Calculate regressions and count violations
|
||||
REGRESSION_COUNT=$(jq -s --argjson threshold "$THRESHOLD" '
|
||||
.[0].results as $base |
|
||||
.[1].results |
|
||||
to_entries |
|
||||
map(
|
||||
select(
|
||||
$base[.key] != null and
|
||||
((.value.elapsedMs - $base[.key].elapsedMs) / $base[.key].elapsedMs * 100) > $threshold
|
||||
) |
|
||||
{
|
||||
name: .key,
|
||||
baseline: $base[.key].elapsedMs,
|
||||
current: .value.elapsedMs,
|
||||
change: (((.value.elapsedMs - $base[.key].elapsedMs) / $base[.key].elapsedMs * 100) | . * 10 | round / 10)
|
||||
}
|
||||
)
|
||||
' "$BASELINE_FILE" "$CURRENT_FILE" | jq 'length')
|
||||
|
||||
if [ "$REGRESSION_COUNT" -gt 0 ]; then
|
||||
echo "ERROR: $REGRESSION_COUNT benchmark(s) regressed more than ${THRESHOLD}%"
|
||||
echo ""
|
||||
echo "Regressions detected:"
|
||||
jq -s --argjson threshold "$THRESHOLD" '
|
||||
.[0].results as $base |
|
||||
.[1].results |
|
||||
to_entries |
|
||||
map(
|
||||
select(
|
||||
$base[.key] != null and
|
||||
((.value.elapsedMs - $base[.key].elapsedMs) / $base[.key].elapsedMs * 100) > $threshold
|
||||
)
|
||||
) |
|
||||
.[] |
|
||||
" - \(.key): \($base[.key].elapsedMs)ms -> \(.value.elapsedMs)ms (+\(((.value.elapsedMs - $base[.key].elapsedMs) / $base[.key].elapsedMs * 100) | . * 10 | round / 10)%)"
|
||||
' "$BASELINE_FILE" "$CURRENT_FILE" -r
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "SUCCESS: No regressions exceeding ${THRESHOLD}% threshold"
|
||||
exit 0
|
||||
```
|
||||
|
||||
**Usage at Phase Gates:**
|
||||
|
||||
```bash
|
||||
# After running benchmarks at a phase gate
|
||||
./regression-guard.sh baseline.json current.json 20
|
||||
|
||||
# Returns exit code 0 if all benchmarks within threshold
|
||||
# Returns exit code 1 if any benchmark regresses >20%
|
||||
```
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 2.3 Cross-Service Failure Mode Documentation
|
||||
|
||||
**Issue:** The design documented happy-path orchestration but didn't specify failure scenarios for facade methods that coordinate multiple services.
|
||||
|
||||
**Resolution:** Add explicit failure mode documentation.
|
||||
|
||||
**Required Design Update - Add new section:**
|
||||
|
||||
```markdown
|
||||
## Failure Mode Documentation
|
||||
|
||||
### Orchestrated Operation Failure Behavior
|
||||
|
||||
The facade methods that coordinate multiple services use ambient scope transactions. All operations within a scope are atomic - if any operation fails, the entire transaction rolls back.
|
||||
|
||||
| Facade Method | Step 1 | Step 2 | Failure During Step 1 | Failure During Step 2 |
|
||||
|---------------|--------|--------|----------------------|----------------------|
|
||||
| `MoveToRecycleBin` | Unpublish (if published) | Move to bin | No changes persisted, content remains published | Entire operation rolls back, content remains published at original location |
|
||||
| `DeleteOfType` | Move descendants to bin | Delete type content | No changes persisted | Entire operation rolls back, descendants remain at original locations |
|
||||
| `DeleteOfTypes` | Move descendants to bin | Delete types content | No changes persisted | Entire operation rolls back, descendants remain at original locations |
|
||||
|
||||
### Transaction Rollback Guarantees
|
||||
|
||||
```csharp
|
||||
// Example: MoveToRecycleBin transaction boundary
|
||||
public OperationResult MoveToRecycleBin(IContent content, int userId)
|
||||
{
|
||||
using ICoreScope scope = ScopeProvider.CreateCoreScope();
|
||||
|
||||
try
|
||||
{
|
||||
// Step 1: Unpublish if published
|
||||
if (content.Published)
|
||||
{
|
||||
var unpublishResult = _publishOperationService.Unpublish(content, "*", userId);
|
||||
if (!unpublishResult.Success)
|
||||
{
|
||||
// Scope NOT completed - transaction rolls back
|
||||
return OperationResult.Failed(...);
|
||||
}
|
||||
}
|
||||
|
||||
// Step 2: Move to recycle bin
|
||||
var moveResult = _moveService.MoveToRecycleBinInternal(content, userId);
|
||||
if (!moveResult.Success)
|
||||
{
|
||||
// Scope NOT completed - Unpublish also rolls back
|
||||
return moveResult;
|
||||
}
|
||||
|
||||
scope.Complete(); // Only now does transaction commit
|
||||
return moveResult;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// Scope disposed without Complete() - full rollback
|
||||
throw;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Notification Failure Handling
|
||||
|
||||
If a notification handler throws an exception:
|
||||
|
||||
1. **Cancellable notifications** (`*Saving`, `*Publishing`, etc.): Operation is aborted, transaction rolls back
|
||||
2. **Post-operation notifications** (`*Saved`, `*Published`, etc.): Exception propagates, but database changes are already committed
|
||||
|
||||
**Important:** Post-operation notification failures can leave the system in an inconsistent state where database changes are persisted but downstream effects (cache invalidation, webhooks) may be incomplete. This is existing behavior that is preserved in the refactoring.
|
||||
|
||||
### State After Failed Operations
|
||||
|
||||
| Scenario | Content State | Cache State | Notifications Fired |
|
||||
|----------|--------------|-------------|---------------------|
|
||||
| Unpublish fails during MoveToRecycleBin | Unchanged (published, original location) | Unchanged | `ContentUnpublishingNotification` only |
|
||||
| Move fails after successful unpublish | Unchanged (published, original location)* | Unchanged | None persisted |
|
||||
| Notification handler throws on `ContentMovedNotification` | Moved to bin | May be stale | Partial |
|
||||
|
||||
*Due to transaction rollback, the unpublish is also reverted.
|
||||
|
||||
### Recommended Error Handling Pattern
|
||||
|
||||
```csharp
|
||||
// Consumer code handling orchestrated operations
|
||||
var result = contentService.MoveToRecycleBin(content, userId);
|
||||
if (!result.Success)
|
||||
{
|
||||
// Content is guaranteed to be in original state
|
||||
// No partial changes have been persisted
|
||||
logger.LogWarning("MoveToRecycleBin failed: {Status}", result.OperationStatus);
|
||||
}
|
||||
```
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 2.4 Phase 9 Split Into Sub-Phases
|
||||
|
||||
**Issue:** Phase 9 (Hierarchical Locking) was described as a single phase but encompasses significant infrastructure changes with 58 lock acquisition points to migrate.
|
||||
|
||||
**Resolution:** Split Phase 9 into sub-phases for better risk management.
|
||||
|
||||
**Required Design Update - Replace Phase 9 in implementation order:**
|
||||
|
||||
```markdown
|
||||
### Phase 9: Locking Optimization (Split)
|
||||
|
||||
Phase 9 is split into sub-phases for risk management:
|
||||
|
||||
| Sub-Phase | Focus | Gate | Benchmarks |
|
||||
|-----------|-------|------|------------|
|
||||
| 9a | Lock hierarchy design + scope infrastructure changes | Design reviewed, infrastructure tests pass | - |
|
||||
| 9b | Migrate services with existing lock semantics (behavioral parity) | All tests pass, no behavioral change | - |
|
||||
| 9c | Optimize hot paths (Move, PublishBranch) with granular locks | All tests pass | **Run benchmarks** |
|
||||
| 9d | Final validation and documentation | All tests pass, lock contracts updated | **Run benchmarks** |
|
||||
|
||||
#### Phase 9a: Lock Hierarchy Design
|
||||
|
||||
**Deliverables:**
|
||||
- Lock hierarchy design document (path-based vs operation-based vs hybrid)
|
||||
- Scope infrastructure changes (if needed)
|
||||
- Unit tests for new locking primitives
|
||||
|
||||
**Possible Approaches:**
|
||||
```csharp
|
||||
// Option A: Path-based locks (lock subtree only)
|
||||
scope.WriteLock(Constants.Locks.ContentTree, content.Path);
|
||||
|
||||
// Option B: Operation-specific locks
|
||||
scope.WriteLock(Constants.Locks.ContentTreeMove);
|
||||
scope.WriteLock(Constants.Locks.ContentTreePublish);
|
||||
|
||||
// Option C: Hybrid (operation + path)
|
||||
scope.WriteLock(Constants.Locks.ContentTreeMove, content.Path);
|
||||
```
|
||||
|
||||
#### Phase 9b: Behavioral Parity Migration
|
||||
|
||||
**Deliverables:**
|
||||
- Each service updated to use new lock infrastructure
|
||||
- Existing lock behavior preserved (same scope, same duration)
|
||||
- All integration tests pass without modification
|
||||
|
||||
**Key Rule:** No optimization in this phase. Goal is to prove the new infrastructure works.
|
||||
|
||||
#### Phase 9c: Hot Path Optimization
|
||||
|
||||
**Deliverables:**
|
||||
- `PerformMoveLocked` optimized (batch updates, reduced lock duration)
|
||||
- `PublishBranch` optimized (subtree locks where applicable)
|
||||
- Lock contention tests added
|
||||
|
||||
**Target Improvements:**
|
||||
- Move operations: Lock duration reduced from O(n) to O(batch)
|
||||
- Branch publish: Concurrent non-overlapping branches enabled
|
||||
|
||||
#### Phase 9d: Validation and Documentation
|
||||
|
||||
**Deliverables:**
|
||||
- All lock contracts in interface documentation updated
|
||||
- Performance comparison report (baseline vs post-optimization)
|
||||
- Lock contention metrics documented
|
||||
|
||||
**Git Checkpoints:**
|
||||
```bash
|
||||
git tag phase-9a-complete -m "Lock infrastructure ready"
|
||||
git tag phase-9b-complete -m "Services migrated to new locks (parity)"
|
||||
git tag phase-9c-complete -m "Hot paths optimized"
|
||||
git tag phase-9d-complete -m "Phase 9 complete - locking optimization done"
|
||||
```
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 2.5 Phase 0 Deliverables Expansion
|
||||
|
||||
**Issue:** Phase 0 was described as "Write Tests" but didn't explicitly include benchmark file creation or baseline capture.
|
||||
|
||||
**Resolution:** Expand Phase 0 deliverables.
|
||||
|
||||
**Required Design Update - Replace Phase 0 details:**
|
||||
|
||||
```markdown
|
||||
### Phase 0: Test and Benchmark Infrastructure
|
||||
|
||||
**Deliverables Checklist:**
|
||||
|
||||
- [ ] Create `ContentServiceRefactoringTests.cs` (15 integration tests)
|
||||
- 2 notification ordering tests
|
||||
- 3 sort operation tests
|
||||
- 3 DeleteOfType tests
|
||||
- 4 permission tests
|
||||
- 3 transaction boundary tests
|
||||
|
||||
- [ ] Create `ContentServiceRefactoringBenchmarks.cs` (33 benchmarks)
|
||||
- 7 CRUD operation benchmarks
|
||||
- 6 query operation benchmarks
|
||||
- 7 publish operation benchmarks
|
||||
- 8 move operation benchmarks
|
||||
- 4 version operation benchmarks
|
||||
- 1 baseline comparison test
|
||||
|
||||
- [ ] Create `ContentServiceBaseTests.cs` (unit tests for shared infrastructure)
|
||||
- Audit helper method tests
|
||||
- Scope provider access pattern tests
|
||||
- Logger injection tests
|
||||
|
||||
- [ ] Run baseline capture
|
||||
```bash
|
||||
dotnet test tests/Umbraco.Tests.Integration \
|
||||
--filter "Category=Benchmark&FullyQualifiedName~ContentServiceRefactoringBenchmarks" \
|
||||
--logger "console;verbosity=detailed" | tee benchmark-baseline.txt
|
||||
|
||||
# Extract JSON
|
||||
grep -oP '\[BENCHMARK_JSON\]\K.*(?=\[/BENCHMARK_JSON\])' benchmark-baseline.txt > baseline.json
|
||||
|
||||
# Tag baseline commit
|
||||
git tag phase-0-baseline -m "Baseline benchmarks captured"
|
||||
```
|
||||
|
||||
- [ ] Verify all 15 tests pass against current ContentService
|
||||
- [ ] Verify all 33 benchmarks complete without error
|
||||
- [ ] Commit baseline.json to repository for comparison
|
||||
|
||||
**Gate:** All tests pass, baseline captured, tagged commit created.
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 2.6 ContentServiceBase Unit Tests
|
||||
|
||||
**Issue:** The design introduces `ContentServiceBase` as shared infrastructure but the 15 new tests focus on behavior validation, not base class coverage.
|
||||
|
||||
**Resolution:** Add unit tests for ContentServiceBase.
|
||||
|
||||
**Required Design Update - Add to Phase 0 deliverables and Test Strategy section:**
|
||||
|
||||
```markdown
|
||||
### ContentServiceBase Unit Tests
|
||||
|
||||
Create `tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Services/ContentServiceBaseTests.cs`:
|
||||
|
||||
```csharp
|
||||
[TestFixture]
|
||||
public class ContentServiceBaseTests
|
||||
{
|
||||
// Audit helper method tests
|
||||
[Test]
|
||||
public void Audit_WithValidParameters_CreatesAuditEntry()
|
||||
{
|
||||
// Arrange
|
||||
var auditService = Substitute.For<IAuditService>();
|
||||
var service = CreateTestService(auditService: auditService);
|
||||
|
||||
// Act
|
||||
service.TestAudit(AuditType.Save, userId: 1, objectId: 100, message: "Test");
|
||||
|
||||
// Assert
|
||||
auditService.Received(1).Write(
|
||||
Arg.Is<int>(1),
|
||||
Arg.Is<string>("Test"),
|
||||
Arg.Any<string>(),
|
||||
Arg.Is<int>(100));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Audit_WithNullMessage_UsesDefaultMessage()
|
||||
{
|
||||
// Verify default audit message behavior
|
||||
}
|
||||
|
||||
// Scope provider access pattern tests
|
||||
[Test]
|
||||
public void CreateScope_ReturnsValidCoreScope()
|
||||
{
|
||||
// Verify scope creation works correctly
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CreateScope_WithAmbientScope_ReusesExisting()
|
||||
{
|
||||
// Verify ambient scope detection
|
||||
}
|
||||
|
||||
// Logger injection tests
|
||||
[Test]
|
||||
public void Logger_IsInjectedCorrectly()
|
||||
{
|
||||
// Verify logger is accessible and functional
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Logger_UsesCorrectCategoryName()
|
||||
{
|
||||
// Verify log category matches service type
|
||||
}
|
||||
|
||||
// Repository access tests
|
||||
[Test]
|
||||
public void DocumentRepository_IsAccessibleWithinScope()
|
||||
{
|
||||
// Verify repository access pattern
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Test Count:** 7 unit tests for ContentServiceBase infrastructure.
|
||||
|
||||
**Updated Test Summary:**
|
||||
|
||||
| Test File | Test Count | Purpose |
|
||||
|-----------|------------|---------|
|
||||
| `ContentServiceRefactoringTests.cs` | 15 | Integration tests for behavior validation |
|
||||
| `ContentServiceRefactoringBenchmarks.cs` | 33 | Performance benchmarks |
|
||||
| `ContentServiceBaseTests.cs` | 7 | Unit tests for shared infrastructure |
|
||||
| **Total** | **55** | |
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 2.7 Async Expansion Strategy
|
||||
|
||||
**Issue:** The design mentioned async overloads for long-running operations but interface definitions showed only `EmptyRecycleBinAsync`.
|
||||
|
||||
**Resolution:** Async expansion is deferred to a future initiative.
|
||||
|
||||
**Required Design Update - Replace Async Considerations section:**
|
||||
|
||||
```markdown
|
||||
## Async Considerations
|
||||
|
||||
### Current State
|
||||
|
||||
Only `EmptyRecycleBinAsync` currently has an async variant. This refactoring preserves the existing async surface.
|
||||
|
||||
### Future Async Expansion (Deferred)
|
||||
|
||||
The following operations are candidates for async variants in a future initiative:
|
||||
|
||||
| Operation | Reason for Async | Priority |
|
||||
|-----------|-----------------|----------|
|
||||
| `PublishBranch` | Tree traversal with many DB operations | High |
|
||||
| `DeleteOfType`/`DeleteOfTypes` | Bulk operations | Medium |
|
||||
| `Save` (batch) | Large batch operations | Medium |
|
||||
| `Copy` (recursive) | Deep copy operations | Low |
|
||||
|
||||
**Decision:** Async expansion is out of scope for this refactoring. A separate initiative should address async patterns across all Umbraco services consistently.
|
||||
|
||||
**Tracking:** Create issue "Async service methods initiative" post-refactoring.
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 2.8 Production Rollback Triggers (Future Reference)
|
||||
|
||||
**Issue:** No guidance for production deployment rollback decisions.
|
||||
|
||||
**Resolution:** Document rollback triggers for future reference, but they are not required for this initiative.
|
||||
|
||||
**Required Design Update - Add new section:**
|
||||
|
||||
```markdown
|
||||
## Production Deployment Guidance (Future Reference)
|
||||
|
||||
This section documents rollback considerations for production deployments. These are **not required** for this refactoring initiative but are preserved for future reference.
|
||||
|
||||
### Rollback Trigger Indicators
|
||||
|
||||
If deploying phases incrementally to production, consider rollback if:
|
||||
|
||||
| Indicator | Threshold | Action |
|
||||
|-----------|-----------|--------|
|
||||
| Lock timeout rate | >5% increase | Investigate, consider pausing |
|
||||
| P99 latency | >50% degradation | Rollback to previous phase |
|
||||
| Error rate | >1% increase | Rollback immediately |
|
||||
| CPU utilization | >30% increase sustained | Investigate before proceeding |
|
||||
|
||||
### Rollback Procedure
|
||||
|
||||
```bash
|
||||
# Rollback to previous phase
|
||||
git checkout phase-{N-1}-complete
|
||||
|
||||
# Rebuild and redeploy
|
||||
dotnet build -c Release
|
||||
# ... deployment steps ...
|
||||
```
|
||||
|
||||
### Phase-Specific Risks
|
||||
|
||||
| Phase | Risk Level | Special Considerations |
|
||||
|-------|------------|------------------------|
|
||||
| 1-3 | Low | Read-heavy, minimal locking changes |
|
||||
| 4 | Medium | Move/Copy affect tree structure |
|
||||
| 5 | High | Publishing is core functionality |
|
||||
| 6-7 | Low | Permissions and blueprints are isolated |
|
||||
| 8 | Medium | Facade wiring affects all operations |
|
||||
| 9a-9d | High | Locking changes affect concurrency |
|
||||
|
||||
### Monitoring Recommendations
|
||||
|
||||
For production deployments, ensure monitoring covers:
|
||||
- Content operation latency (Save, Publish, Move)
|
||||
- Lock acquisition time
|
||||
- Database connection pool utilization
|
||||
- Cache hit/miss rates
|
||||
- Notification handler execution time
|
||||
|
||||
**Note:** This guidance is for future production deployments. The refactoring should be thoroughly tested in non-production environments before any production consideration.
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 3. Alternative Architectural Approaches
|
||||
|
||||
### Considered: Event-Sourced State Changes
|
||||
|
||||
An alternative approach using event sourcing was considered:
|
||||
- All content mutations emit domain events
|
||||
- Repository changes become projections
|
||||
- Notifications become event handlers
|
||||
- Locking becomes optimistic concurrency
|
||||
|
||||
**Decision:** The current approach (decomposition with existing patterns) is appropriate. Event sourcing would require a massive architectural shift that doesn't fit Umbraco's existing patterns. If Phase 9 locking optimization proves insufficient for high-concurrency scenarios, event sourcing could be revisited as a longer-term solution.
|
||||
|
||||
---
|
||||
|
||||
## 4. Final Recommendation
|
||||
|
||||
### Approved With Required Changes
|
||||
|
||||
The design is approved for implementation after incorporating the changes documented in this review.
|
||||
|
||||
### Required Changes Summary
|
||||
|
||||
| Priority | Change | Section |
|
||||
|----------|--------|---------|
|
||||
| **P0** | Add facade deprecation strategy | 2.1 |
|
||||
| **P0** | Add automated regression guard script | 2.2 |
|
||||
| **P0** | Add failure mode documentation | 2.3 |
|
||||
| **P0** | Split Phase 9 into 9a-9d | 2.4 |
|
||||
| **P0** | Expand Phase 0 deliverables | 2.5 |
|
||||
| **P1** | Add ContentServiceBase unit tests | 2.6 |
|
||||
| **P1** | Document async expansion as future work | 2.7 |
|
||||
| **P2** | Add production rollback guidance | 2.8 |
|
||||
|
||||
### Implementation Readiness
|
||||
|
||||
Once the above changes are incorporated into the design document (resulting in version 1.7), implementation can proceed with Phase 0.
|
||||
|
||||
---
|
||||
|
||||
## Appendix A: Review History
|
||||
|
||||
| Review | Date | Key Issues | Resolution |
|
||||
|--------|------|------------|------------|
|
||||
| 1.0 | 2025-12-19 | Naming collision, transaction boundaries, method mapping | Addressed in v1.1-1.3 |
|
||||
| 2.0 | 2025-12-20 | Lock contention, benchmark infrastructure, Phase 9 scope | Addressed in v1.4-1.6 |
|
||||
| 3.0 | 2025-12-20 | Facade strategy, regression automation, failure modes | This review |
|
||||
|
||||
## Appendix B: Cumulative Issue Tracker
|
||||
|
||||
| Issue | Review Identified | Resolution | Design Version |
|
||||
|-------|------------------|------------|----------------|
|
||||
| Naming collision | 1.0 | Renamed to IContentPublishOperationService | 1.1 |
|
||||
| Transaction boundaries | 1.0 | Ambient scope pattern documented | 1.2 |
|
||||
| Method mapping | 1.0 | Complete 80+ method mapping | 1.2 |
|
||||
| Public/internal classification | 1.0 | Query and Versioning promoted to public | 1.2 |
|
||||
| Notification matrix | 1.0 | Matrix added | 1.3 |
|
||||
| Lock contention | 2.0 | Deferred to Phase 9 | 1.5 |
|
||||
| Benchmark infrastructure | 2.0 | Integration test pattern | 1.5 |
|
||||
| Git checkpoints | 2.0 | Tagging convention added | 1.6 |
|
||||
| Facade permanence | 2.0 | Future deprecation noted | **1.7** |
|
||||
| Regression automation | 3.0 | Guard script added | **1.7** |
|
||||
| Failure modes | 3.0 | Documentation added | **1.7** |
|
||||
| Phase 9 scope | 3.0 | Split into 9a-9d | **1.7** |
|
||||
| Phase 0 deliverables | 3.0 | Expanded checklist | **1.7** |
|
||||
| ContentServiceBase tests | 3.0 | Unit tests added | **1.7** |
|
||||
| Async expansion | 3.0 | Deferred to future | **1.7** |
|
||||
| Rollback triggers | 3.0 | Documented for reference | **1.7** |
|
||||
|
||||
## Appendix C: Updated Phase Structure
|
||||
|
||||
| Phase | Description | Gate | Benchmarks |
|
||||
|-------|-------------|------|------------|
|
||||
| 0 | Test and benchmark infrastructure | All tests pass, baseline captured | **Baseline** |
|
||||
| 1 | CRUD Service | All tests pass | **Run** |
|
||||
| 2 | Query Service | All tests pass | - |
|
||||
| 3 | Version Service | All tests pass | - |
|
||||
| 4 | Move Service | All tests pass | - |
|
||||
| 5 | Publish Operation Service | All tests pass | **Run** |
|
||||
| 6 | Permission Manager | All tests pass | - |
|
||||
| 7 | Blueprint Manager | All tests pass | - |
|
||||
| 8 | Facade | Full suite passes | **Run** |
|
||||
| 9a | Lock hierarchy design | Design reviewed | - |
|
||||
| 9b | Lock migration (parity) | All tests pass | - |
|
||||
| 9c | Hot path optimization | All tests pass | **Run** |
|
||||
| 9d | Validation and documentation | All tests pass | **Run** |
|
||||
| 10+ | Performance optimization | Per-optimization | Per-optimization |
|
||||
|
||||
---
|
||||
|
||||
*End of Critical Architectural Review v3.0*
|
||||
1024
docs/plans/2025-12-19-contentservice-refactor-design.md
Normal file
1024
docs/plans/2025-12-19-contentservice-refactor-design.md
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,349 @@
|
||||
# Critical Implementation Review: ContentService Phase 0 Implementation Plan
|
||||
|
||||
**Date**: 2025-12-20
|
||||
**Reviewer**: Claude (Critical Implementation Review)
|
||||
**Document Reviewed**: `docs/plans/2025-12-20-contentservice-refactor-phase0-implementation.md`
|
||||
**Status**: Approve with Changes
|
||||
|
||||
---
|
||||
|
||||
## 1. Overall Assessment
|
||||
|
||||
### Strengths
|
||||
|
||||
- **Well-structured incremental tasks** with clear commit boundaries and verification steps
|
||||
- **Comprehensive test coverage** for identified gaps (15 integration tests + 33 benchmarks)
|
||||
- **Good use of existing infrastructure** (`UmbracoIntegrationTestWithContent`, `ContentServiceBenchmarkBase`)
|
||||
- **Proper notification handler isolation** using static state with thread-safe locking
|
||||
- **Clear test naming** following the `Method_Scenario_ExpectedBehavior` convention
|
||||
|
||||
### Major Concerns
|
||||
|
||||
1. **Missing `[NonParallelizable]` attribute** risks test flakiness due to static state sharing
|
||||
2. **Incorrect using directive instruction** in Task 6 (references infrastructure scope when base class already provides access)
|
||||
3. **Non-portable shell commands** in Task 10 (`grep -oP` is GNU grep-specific)
|
||||
4. **No benchmark warmup iterations** leading to JIT-skewed baseline measurements
|
||||
5. **Missing null assertions** on template retrieval causing potential `NullReferenceException`
|
||||
6. **Design document inconsistency** with Test 1 expected behavior (now verified and corrected)
|
||||
|
||||
---
|
||||
|
||||
## 2. Critical Issues
|
||||
|
||||
### Issue 1: Missing `[NonParallelizable]` Attribute - Test Flakiness Risk
|
||||
|
||||
**Location**: Task 1, line 43-49 (test class skeleton)
|
||||
|
||||
**Description**: The `RefactoringTestNotificationHandler` uses static mutable state (`_notificationOrder` list). NUnit can run tests in parallel by default. Without `[NonParallelizable]`, concurrent tests will corrupt the shared notification list.
|
||||
|
||||
**Why it matters**: Random test failures in CI will undermine confidence in the refactoring safety net.
|
||||
|
||||
**Fix**: Add `[NonParallelizable]` attribute to the test class:
|
||||
```csharp
|
||||
[TestFixture]
|
||||
[NonParallelizable] // ← ADD THIS
|
||||
[UmbracoTest(
|
||||
Database = UmbracoTestOptions.Database.NewSchemaPerTest,
|
||||
PublishedRepositoryEvents = true,
|
||||
WithApplication = true,
|
||||
Logger = UmbracoTestOptions.Logger.Console)]
|
||||
internal sealed class ContentServiceRefactoringTests : UmbracoIntegrationTestWithContent
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Issue 2: Incorrect Using Directive in Task 6
|
||||
|
||||
**Location**: Task 6, Step 1 (lines 863-867)
|
||||
|
||||
**Description**: The plan instructs adding `using Umbraco.Cms.Infrastructure.Scoping;` but `ScopeProvider` is already accessible via the `UmbracoIntegrationTestWithContent` base class. Adding this directive is unnecessary and could cause confusion about scope ownership.
|
||||
|
||||
**Why it matters**: Misleading instructions waste implementation time and create confusion about the scoping architecture.
|
||||
|
||||
**Fix**: Remove the instruction to add the using directive entirely. The test code should work as-is since `ScopeProvider` is inherited from the base class.
|
||||
|
||||
---
|
||||
|
||||
### Issue 3: Non-Portable Shell Commands in Task 10
|
||||
|
||||
**Location**: Task 10, Step 2 (lines 2291-2293)
|
||||
|
||||
**Description**: The command `grep -oP '\[BENCHMARK_JSON\]\K.*(?=\[/BENCHMARK_JSON\])'` uses Perl regex (`-P`) which is GNU grep-specific. This will fail on:
|
||||
- macOS (uses BSD grep)
|
||||
- Windows (no native grep)
|
||||
- Alpine Linux Docker containers (uses BusyBox grep)
|
||||
|
||||
**Why it matters**: CI/CD pipelines and developers on macOS/Windows cannot capture baselines.
|
||||
|
||||
**Fix**: Replace with portable alternative:
|
||||
|
||||
```bash
|
||||
# Option A: sed (POSIX-compliant)
|
||||
sed -n 's/.*\[BENCHMARK_JSON\]\(.*\)\[\/BENCHMARK_JSON\].*/\1/p' benchmark-*.txt > docs/plans/baseline-phase0.json
|
||||
|
||||
# Option B: Python (cross-platform)
|
||||
python3 -c "
|
||||
import re, sys
|
||||
for line in sys.stdin:
|
||||
m = re.search(r'\[BENCHMARK_JSON\](.*)\[/BENCHMARK_JSON\]', line)
|
||||
if m: print(m.group(1))
|
||||
" < benchmark-*.txt > docs/plans/baseline-phase0.json
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Issue 4: No Benchmark Warmup Iterations
|
||||
|
||||
**Location**: `ContentServiceBenchmarkBase.cs`, lines 58-64
|
||||
|
||||
**Description**: The `MeasureAndRecord` method immediately runs the action and records timing. JIT compilation, database connection pooling, and cache warming occur during the first run, skewing results.
|
||||
|
||||
**Why it matters**: Baseline metrics will include warmup overhead, making comparison with post-refactoring runs unreliable. First runs can be 2-10x slower than steady-state.
|
||||
|
||||
**Fix**: Update `MeasureAndRecord` to include warmup:
|
||||
|
||||
```csharp
|
||||
protected long MeasureAndRecord(string name, int itemCount, Action action, bool skipWarmup = false)
|
||||
{
|
||||
// Warmup iteration: triggers JIT compilation, warms connection pool and caches.
|
||||
// Skipped for destructive operations that would fail on second execution.
|
||||
if (!skipWarmup)
|
||||
{
|
||||
action();
|
||||
}
|
||||
|
||||
// Measured iteration
|
||||
var sw = Stopwatch.StartNew();
|
||||
action();
|
||||
sw.Stop();
|
||||
|
||||
RecordBenchmark(name, sw.ElapsedMilliseconds, itemCount);
|
||||
return sw.ElapsedMilliseconds;
|
||||
}
|
||||
```
|
||||
|
||||
For destructive operations (Delete, EmptyRecycleBin), use `skipWarmup: true` and provide separate warmup content manually in the test.
|
||||
|
||||
---
|
||||
|
||||
### Issue 5: Missing Null Assertion on Template Retrieval
|
||||
|
||||
**Location**: Task 4, Step 1 (line 515); Task 4, Step 3 (line 570); Task 4, Step 5 (lines 614-622)
|
||||
|
||||
**Description**: The code uses `FileService.GetTemplate("defaultTemplate")!` with a null-forgiving operator. If the template doesn't exist, the test will throw a cryptic `NullReferenceException` deep in content creation rather than failing fast with a clear message.
|
||||
|
||||
**Why it matters**: Test failures will be harder to diagnose; developers will waste time investigating null reference exceptions.
|
||||
|
||||
**Fix**: Add explicit assertion:
|
||||
```csharp
|
||||
var template = FileService.GetTemplate("defaultTemplate");
|
||||
Assert.That(template, Is.Not.Null, "Default template must exist for test setup");
|
||||
var childContentType = ContentTypeBuilder.CreateSimpleContentType(
|
||||
"childType", "Child Type", defaultTemplateId: template.Id);
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Issue 6: Design Document Inconsistency - Test 1 Expected Behavior (VERIFIED)
|
||||
|
||||
**Location**: Design document lines 1211-1217 vs. Implementation plan Task 2
|
||||
|
||||
**Description**: The design document previously stated that `MoveToRecycleBin` fires `ContentUnpublishingNotification` and `ContentUnpublishedNotification` before move notifications.
|
||||
|
||||
**Verification**: Source code analysis of `ContentService.cs` lines 2457-2461 confirms:
|
||||
|
||||
```csharp
|
||||
// if it's published we may want to force-unpublish it - that would be backward-compatible... but...
|
||||
// making a radical decision here: trashing is equivalent to moving under an unpublished node so
|
||||
// it's NOT unpublishing, only the content is now masked - allowing us to restore it if wanted
|
||||
// if (content.HasPublishedVersion)
|
||||
// { }
|
||||
```
|
||||
|
||||
**Confirmed Behavior**: MoveToRecycleBin fires ONLY:
|
||||
1. `ContentMovingToRecycleBinNotification` (cancellable)
|
||||
2. `ContentMovedToRecycleBinNotification`
|
||||
|
||||
**NO unpublish notifications are fired.** Content is "masked" not "unpublished".
|
||||
|
||||
**Fix**: The design document Test 1 specification should be corrected to:
|
||||
|
||||
```markdown
|
||||
**Test 1: MoveToRecycleBin_PublishedContent_FiresNotificationsInCorrectOrder**
|
||||
|
||||
Verifies that for published content, `MoveToRecycleBin` fires notifications in order:
|
||||
1. `ContentMovingToRecycleBinNotification`
|
||||
2. `ContentMovedToRecycleBinNotification`
|
||||
|
||||
> **Note:** MoveToRecycleBin does NOT fire unpublish notifications. As per the design in
|
||||
> `ContentService.cs` (lines 2457-2461): "trashing is equivalent to moving under an unpublished
|
||||
> node so it's NOT unpublishing, only the content is now masked - allowing us to restore it if wanted."
|
||||
```
|
||||
|
||||
The implementation plan (Task 2) is **correct** - the design document was incorrect.
|
||||
|
||||
---
|
||||
|
||||
## 3. Minor Issues & Improvements
|
||||
|
||||
### 3.1 Benchmark Class Should Have `[NonParallelizable]` Too
|
||||
|
||||
**Location**: Task 7 (benchmark class)
|
||||
|
||||
The benchmark class should also be non-parallelizable to avoid database contention during performance measurements.
|
||||
|
||||
```csharp
|
||||
[TestFixture]
|
||||
[NonParallelizable] // ← ADD THIS
|
||||
[UmbracoTest(...)]
|
||||
[Category("Benchmark")]
|
||||
[Category("LongRunning")]
|
||||
internal sealed class ContentServiceRefactoringBenchmarks : ContentServiceBenchmarkBase
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 3.2 Test 15 Stale Reference Comment
|
||||
|
||||
**Location**: Task 6, Test 15 (lines 960-993)
|
||||
|
||||
The test modifies a content object inside a scope, then re-fetches after rollback. The stale `content` reference could cause confusion. Add clarifying comment:
|
||||
|
||||
```csharp
|
||||
// Note: The `content` variable still reflects the in-transaction state.
|
||||
// We must re-fetch from database to verify rollback.
|
||||
var afterRollback = ContentService.GetById(contentId);
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 3.3 Hardcoded Permission Characters
|
||||
|
||||
**Location**: Tests 9-12 (Task 5)
|
||||
|
||||
Tests use hardcoded permission characters like `"F"`, `"U"`, `"P"`. Consider using constants for maintainability:
|
||||
|
||||
```csharp
|
||||
// Current
|
||||
ContentService.SetPermission(content, "F", new[] { adminGroup.Id });
|
||||
|
||||
// Improved (if constants exist)
|
||||
ContentService.SetPermission(content, ActionBrowse.ActionLetter.ToString(), new[] { adminGroup.Id });
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 3.4 Benchmark JSON Output Should Include Git Commit Hash
|
||||
|
||||
**Location**: `ContentServiceBenchmarkBase.cs`, `OutputBenchmarkResults` method
|
||||
|
||||
The JSON output doesn't include the git commit hash, making it harder to correlate results with code versions.
|
||||
|
||||
**Suggested Enhancement**:
|
||||
```csharp
|
||||
var output = new {
|
||||
commit = Environment.GetEnvironmentVariable("GIT_COMMIT") ?? "unknown",
|
||||
timestamp = DateTime.UtcNow,
|
||||
results = _results
|
||||
};
|
||||
var json = JsonSerializer.Serialize(output, ...);
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 3.5 Consider `TestCaseSource` for DeleteOfType Tests
|
||||
|
||||
Tests 6, 7, 8 have significant setup duplication for creating content types. Consider extracting shared setup or using `[TestCaseSource]` for parameterized tests in future iterations.
|
||||
|
||||
---
|
||||
|
||||
## 4. Questions Resolved
|
||||
|
||||
| Question | Resolution |
|
||||
|----------|------------|
|
||||
| Test 1 Behavior | **Verified via source code**: MoveToRecycleBin does NOT fire unpublish notifications. Content is "masked" not "unpublished". |
|
||||
| Warmup Strategy | **Recommended**: Single warmup iteration before measurement; `skipWarmup` parameter for destructive operations. |
|
||||
| CI Integration | **Confirmed**: Benchmarks run only at phase gates, skipped on PRs via `[LongRunning]` category. |
|
||||
|
||||
---
|
||||
|
||||
## 5. Summary of Required Changes
|
||||
|
||||
### Must Fix Before Execution
|
||||
|
||||
| # | Issue | Location | Fix |
|
||||
|---|-------|----------|-----|
|
||||
| 1 | Missing `[NonParallelizable]` | Task 1, line 43 | Add attribute to test class |
|
||||
| 2 | Incorrect using directive | Task 6, Step 1 | Remove instruction entirely |
|
||||
| 3 | Non-portable `grep -oP` | Task 10, Step 2 | Replace with `sed` or Python |
|
||||
| 4 | No benchmark warmup | `ContentServiceBenchmarkBase.cs` | Add warmup iteration to `MeasureAndRecord` |
|
||||
| 5 | Missing null assertion | Tasks 4 (3 locations) | Add `Assert.That(template, Is.Not.Null, ...)` |
|
||||
|
||||
### Should Fix
|
||||
|
||||
| # | Issue | Location | Fix |
|
||||
|---|-------|----------|-----|
|
||||
| 6 | Design doc Test 1 spec | Design document lines 1211-1217 | Correct to match actual behavior |
|
||||
| 7 | Benchmark class parallelization | Task 7 | Add `[NonParallelizable]` |
|
||||
|
||||
### Optional Improvements
|
||||
|
||||
| # | Issue | Location | Suggestion |
|
||||
|---|-------|----------|------------|
|
||||
| 8 | Stale reference clarity | Task 6, Test 15 | Add clarifying comment |
|
||||
| 9 | Hardcoded permissions | Task 5 | Use constants if available |
|
||||
| 10 | Git commit in JSON | `ContentServiceBenchmarkBase.cs` | Include commit hash in output |
|
||||
|
||||
---
|
||||
|
||||
## 6. Final Recommendation
|
||||
|
||||
**Approve with Changes**
|
||||
|
||||
The Phase 0 implementation plan is well-structured and addresses legitimate test coverage gaps. The 5 required fixes are straightforward and don't require architectural changes. Once applied, this plan will provide a reliable safety net for the ContentService refactoring.
|
||||
|
||||
**Gate Criteria After Fixes**:
|
||||
- [ ] All 15 integration tests pass
|
||||
- [ ] All 33 benchmarks complete without error
|
||||
- [ ] Baseline JSON captured with portable command
|
||||
- [ ] `phase-0-baseline` git tag created
|
||||
|
||||
---
|
||||
|
||||
## Appendix: Verified Source Code References
|
||||
|
||||
### MoveToRecycleBin Notification Sequence
|
||||
|
||||
**File**: `src/Umbraco.Core/Services/ContentService.cs`
|
||||
**Lines**: 2436-2479
|
||||
|
||||
```csharp
|
||||
public OperationResult MoveToRecycleBin(IContent content, int userId = Constants.Security.SuperUserId)
|
||||
{
|
||||
// ... setup ...
|
||||
|
||||
var movingToRecycleBinNotification =
|
||||
new ContentMovingToRecycleBinNotification(moveEventInfo, eventMessages);
|
||||
if (scope.Notifications.PublishCancelable(movingToRecycleBinNotification))
|
||||
{
|
||||
scope.Complete();
|
||||
return OperationResult.Cancel(eventMessages);
|
||||
}
|
||||
|
||||
// if it's published we may want to force-unpublish it - that would be backward-compatible... but...
|
||||
// making a radical decision here: trashing is equivalent to moving under an unpublished node so
|
||||
// it's NOT unpublishing, only the content is now masked - allowing us to restore it if wanted
|
||||
// if (content.HasPublishedVersion)
|
||||
// { }
|
||||
|
||||
PerformMoveLocked(content, Constants.System.RecycleBinContent, null, userId, moves, true);
|
||||
|
||||
scope.Notifications.Publish(
|
||||
new ContentMovedToRecycleBinNotification(moveInfo, eventMessages).WithStateFrom(
|
||||
movingToRecycleBinNotification));
|
||||
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
**Conclusion**: The commented-out `if (content.HasPublishedVersion)` block confirms the deliberate design decision to NOT unpublish content when moving to recycle bin.
|
||||
@@ -0,0 +1,419 @@
|
||||
# Critical Implementation Review: ContentService Refactoring Phase 0 (Review 2)
|
||||
|
||||
**Document:** `docs/plans/2025-12-20-contentservice-refactor-phase0-implementation.md` (v1.1)
|
||||
**Reviewer:** Claude (Critical Implementation Review)
|
||||
**Date:** 2025-12-20
|
||||
**Status:** Major Revisions Required
|
||||
|
||||
---
|
||||
|
||||
## Executive Summary
|
||||
|
||||
This review identifies a critical benchmark measurement bug and several moderate issues requiring resolution before Phase 0 execution. The warmup logic in non-destructive benchmarks corrupts measurements by operating on mutated state rather than fresh data.
|
||||
|
||||
**Verdict:** Plan requires v1.2 revision before execution.
|
||||
|
||||
---
|
||||
|
||||
## 1. Overall Assessment
|
||||
|
||||
### Strengths
|
||||
|
||||
- Well-structured task breakdown with atomic commits following conventional commit format
|
||||
- Proper use of existing test infrastructure (`UmbracoIntegrationTestWithContent`, `ContentServiceBenchmarkBase`)
|
||||
- Previous review feedback incorporated (`[NonParallelizable]`, null assertions, POSIX-compliant sed)
|
||||
- Good test coverage across notification ordering, sort, delete, permission, and transaction boundary scenarios
|
||||
- Warmup with `skipWarmup` parameter for destructive benchmarks
|
||||
|
||||
### Major Concerns
|
||||
|
||||
- **Critical warmup logic bug** in non-destructive benchmarks invalidates performance measurements
|
||||
- Benchmark `MeasureAndRecord<T>` overload lacks documentation about warmup behavior
|
||||
- Inconsistent benchmark data sizes prevent meaningful cross-benchmark comparisons
|
||||
- Silent failure on missing baseline JSON masks infrastructure problems
|
||||
|
||||
---
|
||||
|
||||
## 2. Critical Issues
|
||||
|
||||
### 2.1 Warmup Logic Corrupts Benchmark Measurements
|
||||
|
||||
| Attribute | Value |
|
||||
|-----------|-------|
|
||||
| **Severity** | CRITICAL |
|
||||
| **Location** | Task 7 - All non-destructive benchmarks using `MeasureAndRecord` |
|
||||
| **Decision** | Warmup must use completely separate data; measured run uses fresh identical data |
|
||||
|
||||
**Description:**
|
||||
|
||||
The warmup executes the same action on the same data, but for benchmarks that mutate state, this means the measured run operates on different data than intended.
|
||||
|
||||
**Example - `Benchmark_Save_SingleItem` (lines 1116-1126):**
|
||||
|
||||
```csharp
|
||||
var content = ContentBuilder.CreateSimpleContent(ContentType, "BenchmarkSingle", -1);
|
||||
MeasureAndRecord("Save_SingleItem", 1, () =>
|
||||
{
|
||||
ContentService.Save(content); // Warmup: INSERT (assigns ID)
|
||||
// Measured: UPDATE (different operation!)
|
||||
});
|
||||
```
|
||||
|
||||
**Impact:** Benchmarking UPDATE performance when INSERT performance is intended. Affects:
|
||||
- `Benchmark_Save_SingleItem`, `Benchmark_Save_BatchOf100`, `Benchmark_Save_BatchOf1000`
|
||||
- All `Benchmark_Publish_*` variants
|
||||
- Any benchmark where the action mutates setup data
|
||||
|
||||
**Required Fix:**
|
||||
|
||||
All non-destructive benchmarks must create throwaway data for warmup, then fresh identical data for measurement:
|
||||
|
||||
```csharp
|
||||
public void Benchmark_Save_SingleItem()
|
||||
{
|
||||
// Warmup with throwaway content (triggers JIT, warms caches)
|
||||
var warmupContent = ContentBuilder.CreateSimpleContent(ContentType, "Warmup_SingleItem", -1);
|
||||
ContentService.Save(warmupContent);
|
||||
|
||||
// Measured run with fresh, identical setup
|
||||
var content = ContentBuilder.CreateSimpleContent(ContentType, "BenchmarkSingle", -1);
|
||||
var sw = Stopwatch.StartNew();
|
||||
ContentService.Save(content);
|
||||
sw.Stop();
|
||||
RecordBenchmark("Save_SingleItem", sw.ElapsedMilliseconds, 1);
|
||||
|
||||
Assert.That(content.Id, Is.GreaterThan(0));
|
||||
}
|
||||
```
|
||||
|
||||
**Benchmarks Requiring This Pattern:** 1-5, 8-20, 21-27, 29-30 (all non-destructive)
|
||||
|
||||
---
|
||||
|
||||
### 2.2 MeasureAndRecord<T> Overload Missing Documentation
|
||||
|
||||
| Attribute | Value |
|
||||
|-----------|-------|
|
||||
| **Severity** | MEDIUM |
|
||||
| **Location** | `ContentServiceBenchmarkBase.cs` lines 89-96 |
|
||||
| **Decision** | Document that this overload is intended for read-only operations |
|
||||
|
||||
**Description:**
|
||||
|
||||
The `Func<T>` overload of `MeasureAndRecord` has no warmup support:
|
||||
|
||||
```csharp
|
||||
protected T MeasureAndRecord<T>(string name, int itemCount, Func<T> func)
|
||||
{
|
||||
var sw = Stopwatch.StartNew();
|
||||
var result = func();
|
||||
sw.Stop();
|
||||
RecordBenchmark(name, sw.ElapsedMilliseconds, itemCount);
|
||||
return result;
|
||||
}
|
||||
```
|
||||
|
||||
**Required Fix:**
|
||||
|
||||
Add documentation comment:
|
||||
|
||||
```csharp
|
||||
/// <summary>
|
||||
/// Measures and records a benchmark, returning the result of the function.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This overload is intended for READ-ONLY operations that do not need warmup.
|
||||
/// For write operations that modify state, use the Action overload with explicit
|
||||
/// warmup data separation.
|
||||
/// </remarks>
|
||||
protected T MeasureAndRecord<T>(string name, int itemCount, Func<T> func)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 2.3 Benchmark 31 Index Out of Range Risk
|
||||
|
||||
| Attribute | Value |
|
||||
|-----------|-------|
|
||||
| **Severity** | MEDIUM |
|
||||
| **Location** | Task 7, Benchmark 31 - `Benchmark_Rollback_ToVersion` (lines 1897-1915) |
|
||||
| **Decision** | Add defensive assertion and use relative indexing |
|
||||
|
||||
**Description:**
|
||||
|
||||
```csharp
|
||||
var versions = ContentService.GetVersions(content.Id).ToList();
|
||||
var targetVersionId = versions[5].VersionId; // Assumes at least 6 versions exist
|
||||
```
|
||||
|
||||
**Required Fix:**
|
||||
|
||||
```csharp
|
||||
var versions = ContentService.GetVersions(content.Id).ToList();
|
||||
Assert.That(versions.Count, Is.GreaterThanOrEqualTo(6), "Need at least 6 versions for rollback test");
|
||||
var targetVersionId = versions[versions.Count / 2].VersionId; // Middle version
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 2.4 Sort Tests Assume Specific Initial Sort Order
|
||||
|
||||
| Attribute | Value |
|
||||
|-----------|-------|
|
||||
| **Severity** | MEDIUM |
|
||||
| **Location** | Task 3 - Tests 3-5 (lines 385-508) |
|
||||
| **Decision** | Add explicit verification of initial state |
|
||||
|
||||
**Description:**
|
||||
|
||||
Tests assume `Subpage`, `Subpage2`, `Subpage3` have specific sort orders that can be meaningfully reversed. The base class creates them sequentially, but sort orders are not explicitly verified.
|
||||
|
||||
**Required Fix:**
|
||||
|
||||
Add at the start of each sort test:
|
||||
|
||||
```csharp
|
||||
// Verify initial sort order assumption
|
||||
Assert.That(child1.SortOrder, Is.LessThan(child2.SortOrder), "Setup: child1 before child2");
|
||||
Assert.That(child2.SortOrder, Is.LessThan(child3.SortOrder), "Setup: child2 before child3");
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 2.5 Silent Failure on Missing Baseline JSON
|
||||
|
||||
| Attribute | Value |
|
||||
|-----------|-------|
|
||||
| **Severity** | MEDIUM |
|
||||
| **Location** | Task 10, Step 2 |
|
||||
| **Decision** | Fail loudly instead of silent fallback |
|
||||
|
||||
**Description:**
|
||||
|
||||
Current command silently creates empty JSON if no benchmarks found:
|
||||
|
||||
```bash
|
||||
sed -n '...' benchmark-*.txt > docs/plans/baseline-phase0.json || echo "[]" > docs/plans/baseline-phase0.json
|
||||
```
|
||||
|
||||
**Required Fix:**
|
||||
|
||||
```bash
|
||||
# Extract JSON results - fail if no benchmarks found
|
||||
BENCHMARK_OUTPUT=$(sed -n 's/.*\[BENCHMARK_JSON\]\(.*\)\[\/BENCHMARK_JSON\].*/\1/p' benchmark-*.txt)
|
||||
if [ -z "$BENCHMARK_OUTPUT" ]; then
|
||||
echo "ERROR: No benchmark results found in output. Check test execution." >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "$BENCHMARK_OUTPUT" > docs/plans/baseline-phase0.json
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 3. Minor Issues & Improvements
|
||||
|
||||
### 3.1 Inconsistent Benchmark Data Sizes
|
||||
|
||||
| Attribute | Value |
|
||||
|-----------|-------|
|
||||
| **Severity** | LOW |
|
||||
| **Decision** | Standardize to Small (10), Medium (100), Large (1000) |
|
||||
|
||||
**Required Changes:**
|
||||
|
||||
| Benchmark | Current | New | Change |
|
||||
|-----------|---------|-----|--------|
|
||||
| `Benchmark_Delete_WithDescendants` | 50 | 100 | +50 |
|
||||
| `Benchmark_Count_ByContentType` | 500 | 1000 | +500 |
|
||||
| `Benchmark_CountDescendants` | 500 | 1000 | +500 |
|
||||
| `Benchmark_Publish_BatchOf50` | 50 | 100 | +50 |
|
||||
| `Benchmark_PublishBranch_ShallowTree` | 20 | 100 | +80 |
|
||||
| `Benchmark_PerformScheduledPublish` | 50 | 100 | +50 |
|
||||
| `Benchmark_Move_WithDescendants` | 50 | 100 | +50 |
|
||||
| `Benchmark_MoveToRecycleBin_LargeTree` | 100 | 1000 | +900 |
|
||||
| `Benchmark_Copy_Recursive` | 50 | 100 | +50 |
|
||||
| `Benchmark_GetVersions` | 50 | 100 | +50 |
|
||||
| `Benchmark_GetVersionsSlim` | 50 | 100 | +50 |
|
||||
| `Benchmark_DeleteVersions` | 50 | 100 | +50 |
|
||||
|
||||
**Note:** Rename `Benchmark_Publish_BatchOf50` to `Benchmark_Publish_BatchOf100` after resize.
|
||||
|
||||
---
|
||||
|
||||
### 3.2 Document Permission Accumulation Behavior
|
||||
|
||||
| Attribute | Value |
|
||||
|-----------|-------|
|
||||
| **Severity** | LOW |
|
||||
| **Location** | Task 5, Test 10 |
|
||||
| **Decision** | Add explicit documentation of expected behavior |
|
||||
|
||||
**Required Fix:**
|
||||
|
||||
```csharp
|
||||
/// <summary>
|
||||
/// Test 10: Verifies multiple SetPermission calls accumulate permissions for a user group.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Expected behavior: SetPermission assigns permissions per-permission-type, not per-entity.
|
||||
/// Calling SetPermission("F", ...) then SetPermission("U", ...) results in both F and U
|
||||
/// permissions being assigned. Each call only replaces permissions of the same type.
|
||||
/// </remarks>
|
||||
[Test]
|
||||
public void SetPermission_MultiplePermissionsForSameGroup()
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 3.3 Test 13 Unused Variables
|
||||
|
||||
| Attribute | Value |
|
||||
|-----------|-------|
|
||||
| **Severity** | LOW |
|
||||
| **Location** | Task 6, Test 13 (lines 914-944) |
|
||||
|
||||
**Description:**
|
||||
|
||||
Variables `id1` and `id2` are captured but never used after the scope ends.
|
||||
|
||||
**Suggested Fix:**
|
||||
|
||||
Either remove the variables or add a clarifying comment:
|
||||
|
||||
```csharp
|
||||
// Note: IDs are captured for debugging but cannot be used after rollback
|
||||
// since they were assigned within the rolled-back transaction
|
||||
var id1 = content1.Id;
|
||||
var id2 = content2.Id;
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 3.4 Missing Category for Integration Tests
|
||||
|
||||
| Attribute | Value |
|
||||
|-----------|-------|
|
||||
| **Severity** | LOW |
|
||||
| **Location** | `ContentServiceRefactoringTests.cs` |
|
||||
|
||||
**Suggested Fix:**
|
||||
|
||||
Add category for easier filtering:
|
||||
|
||||
```csharp
|
||||
[TestFixture]
|
||||
[NonParallelizable]
|
||||
[Category("Refactoring")] // Add this
|
||||
[UmbracoTest(...)]
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 3.5 Benchmark 33 Documentation
|
||||
|
||||
| Attribute | Value |
|
||||
|-----------|-------|
|
||||
| **Severity** | LOW |
|
||||
| **Location** | Lines 1952-1991 |
|
||||
|
||||
**Observation:**
|
||||
|
||||
`Benchmark_BaselineComparison` manually times and calls `RecordBenchmark` instead of using `MeasureAndRecord`. This is intentional (multi-step composite), but a comment explaining why would improve clarity.
|
||||
|
||||
---
|
||||
|
||||
## 4. Clarification Questions (Resolved)
|
||||
|
||||
| Question | Resolution |
|
||||
|----------|------------|
|
||||
| Benchmark warmup strategy | Warmup should use completely separate data |
|
||||
| Permission accumulation | Test should explicitly document this as expected behavior |
|
||||
| Baseline JSON extraction | Should fail loudly on missing data |
|
||||
| Data consistency | Data should always be the same for consistency |
|
||||
|
||||
---
|
||||
|
||||
## 5. Summary of Required Changes for v1.2
|
||||
|
||||
### Must Fix (Blocking)
|
||||
|
||||
| # | Issue | Change Required |
|
||||
|---|-------|-----------------|
|
||||
| 1 | Warmup logic bug | Restructure all non-destructive benchmarks to create separate warmup data |
|
||||
| 2 | Silent baseline failure | Replace `|| echo "[]"` with explicit error and exit |
|
||||
|
||||
### Should Fix (Before Execution)
|
||||
|
||||
| # | Issue | Change Required |
|
||||
|---|-------|-----------------|
|
||||
| 3 | `MeasureAndRecord<T>` docs | Add remarks about read-only usage |
|
||||
| 4 | Benchmark 31 index | Add defensive assertion, use relative indexing |
|
||||
| 5 | Sort test assumptions | Add initial state verification |
|
||||
| 6 | Data size standardization | Normalize to 10/100/1000 pattern |
|
||||
| 7 | Permission test docs | Add behavior documentation |
|
||||
|
||||
### Consider (Polish)
|
||||
|
||||
| # | Issue | Change Required |
|
||||
|---|-------|-----------------|
|
||||
| 8 | Test 13 unused vars | Add comment or remove |
|
||||
| 9 | Refactoring category | Add `[Category("Refactoring")]` |
|
||||
| 10 | Benchmark 33 comment | Explain manual timing |
|
||||
|
||||
---
|
||||
|
||||
## 6. Final Recommendation
|
||||
|
||||
**Status: Major Revisions Required**
|
||||
|
||||
The warmup logic bug (Issue 2.1) fundamentally invalidates benchmark measurements and must be fixed before execution. Apply all "Must Fix" and "Should Fix" changes, then re-review the updated plan.
|
||||
|
||||
Once v1.2 is prepared with these changes, the plan will provide a solid foundation for Phase 0 test infrastructure.
|
||||
|
||||
---
|
||||
|
||||
## Appendix: Affected Benchmark List
|
||||
|
||||
### Benchmarks Requiring Warmup Pattern Change
|
||||
|
||||
These benchmarks currently use `MeasureAndRecord` with warmup enabled but operate on mutable data:
|
||||
|
||||
1. `Benchmark_Save_SingleItem`
|
||||
2. `Benchmark_Save_BatchOf100`
|
||||
3. `Benchmark_Save_BatchOf1000`
|
||||
4. `Benchmark_GetById_Single`
|
||||
5. `Benchmark_GetByIds_BatchOf100`
|
||||
6. `Benchmark_GetPagedChildren_100Items`
|
||||
7. `Benchmark_GetPagedDescendants_DeepTree`
|
||||
8. `Benchmark_GetAncestors_DeepHierarchy`
|
||||
9. `Benchmark_Count_ByContentType`
|
||||
10. `Benchmark_CountDescendants_LargeTree`
|
||||
11. `Benchmark_HasChildren_100Nodes`
|
||||
12. `Benchmark_Publish_SingleItem`
|
||||
13. `Benchmark_Publish_BatchOf100` (renamed from BatchOf50)
|
||||
14. `Benchmark_PublishBranch_ShallowTree`
|
||||
15. `Benchmark_PublishBranch_DeepTree`
|
||||
16. `Benchmark_Unpublish_SingleItem`
|
||||
17. `Benchmark_PerformScheduledPublish`
|
||||
18. `Benchmark_GetContentSchedulesByIds_100Items`
|
||||
19. `Benchmark_Move_SingleItem`
|
||||
20. `Benchmark_Move_WithDescendants`
|
||||
21. `Benchmark_MoveToRecycleBin_Published`
|
||||
22. `Benchmark_MoveToRecycleBin_LargeTree`
|
||||
23. `Benchmark_Copy_SingleItem`
|
||||
24. `Benchmark_Copy_Recursive_100Items` (renamed from 50Items)
|
||||
25. `Benchmark_Sort_100Children`
|
||||
26. `Benchmark_GetVersions_ItemWith100Versions` (renamed from 50)
|
||||
27. `Benchmark_GetVersionsSlim_Paged`
|
||||
|
||||
### Benchmarks Already Using `skipWarmup: true` (No Change Needed)
|
||||
|
||||
1. `Benchmark_Delete_SingleItem`
|
||||
2. `Benchmark_Delete_WithDescendants`
|
||||
3. `Benchmark_EmptyRecycleBin_100Items`
|
||||
4. `Benchmark_Rollback_ToVersion`
|
||||
5. `Benchmark_DeleteVersions_ByDate`
|
||||
|
||||
### Special Case (Manual Timing)
|
||||
|
||||
1. `Benchmark_BaselineComparison` - Uses manual `Stopwatch` (correct as-is)
|
||||
@@ -0,0 +1,348 @@
|
||||
# Critical Implementation Review #3: ContentService Refactoring Phase 0
|
||||
|
||||
**Document:** `docs/plans/2025-12-20-contentservice-refactor-phase0-implementation.md`
|
||||
**Review Date:** 2025-12-20
|
||||
**Reviewer:** Claude (Critical Implementation Review Skill)
|
||||
**Plan Version Reviewed:** v1.2
|
||||
|
||||
---
|
||||
|
||||
## 1. Overall Assessment
|
||||
|
||||
**Verdict: Approve with Minor Changes**
|
||||
|
||||
The plan is well-structured and comprehensive, establishing solid test infrastructure for the ContentService refactoring. Two prior critical reviews (v1.1 and v1.2) have already addressed significant issues including warmup patterns, data standardization, and POSIX compatibility.
|
||||
|
||||
### Strengths
|
||||
|
||||
- **Comprehensive coverage:** 15 integration tests + 33 benchmarks + 1 unit test placeholder
|
||||
- **Well-organized tasks:** 11 tasks with clear steps and verification commands
|
||||
- **Good commit hygiene:** Atomic commits per task with conventional commit messages
|
||||
- **Proper warmup patterns:** Documented for destructive vs non-destructive benchmarks
|
||||
- **Revision history:** Transparent tracking of changes from prior reviews
|
||||
- **API validation:** All referenced APIs verified to exist:
|
||||
- `ContentService.Sort(IEnumerable<IContent>)` ✓
|
||||
- `ContentService.RecycleBinSmells()` ✓
|
||||
- `ContentScheduleCollection.CreateWithEntry(DateTime?, DateTime?)` ✓
|
||||
- `PublishBranchFilter.Default` ✓
|
||||
|
||||
### Concerns Addressed in This Review
|
||||
|
||||
| Priority | Issue | Status |
|
||||
|----------|-------|--------|
|
||||
| MUST FIX | Variable shadowing in Test 4 | New finding |
|
||||
| MUST FIX | `ContentServiceBenchmarkBase.cs` not committed | New finding |
|
||||
| SHOULD FIX | `MeasureAndRecord<T>` missing warmup | Escalated from v1.2 |
|
||||
| SHOULD FIX | Missing tracking mechanism for ContentServiceBaseTests | New finding |
|
||||
|
||||
---
|
||||
|
||||
## 2. Critical Issues
|
||||
|
||||
### Issue #1: Variable Shadowing Causes Compilation Error
|
||||
|
||||
**Location:** Task 3, Test 4 (lines 508-515)
|
||||
|
||||
**Problem:** Variables `child1`, `child2`, `child3` are redeclared with `var`, causing `CS0128: A local variable named 'child1' is already defined in this scope`.
|
||||
|
||||
```csharp
|
||||
// Lines 486-489: First declaration
|
||||
var child1 = ContentService.GetById(Subpage.Id)!;
|
||||
var child2 = ContentService.GetById(Subpage2.Id)!;
|
||||
var child3 = ContentService.GetById(Subpage3.Id)!;
|
||||
|
||||
// Lines 509-511: ERROR - redeclares variables
|
||||
var child1 = ContentService.GetById(child1Id)!; // CS0128
|
||||
var child2 = ContentService.GetById(child2Id)!; // CS0128
|
||||
var child3 = ContentService.GetById(child3Id)!; // CS0128
|
||||
```
|
||||
|
||||
**Impact:** Code will not compile.
|
||||
|
||||
**Required Fix:** Remove `var` keyword on lines 509-511:
|
||||
|
||||
```csharp
|
||||
// Re-fetch to verify persisted order
|
||||
child1 = ContentService.GetById(child1Id)!;
|
||||
child2 = ContentService.GetById(child2Id)!;
|
||||
child3 = ContentService.GetById(child3Id)!;
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Issue #2: ContentServiceBenchmarkBase.cs Not Committed
|
||||
|
||||
**Location:** Git status shows `?? tests/Umbraco.Tests.Integration/Testing/ContentServiceBenchmarkBase.cs`
|
||||
|
||||
**Problem:** The benchmark base class exists locally but is untracked in git. Anyone cloning the repository will have compilation failures.
|
||||
|
||||
**Impact:** Benchmark tests will not compile for other developers.
|
||||
|
||||
**Required Fix:** Add a prerequisite step before Task 1:
|
||||
|
||||
```bash
|
||||
# Task 0 (Prerequisite): Commit benchmark infrastructure
|
||||
git add tests/Umbraco.Tests.Integration/Testing/ContentServiceBenchmarkBase.cs
|
||||
git commit -m "$(cat <<'EOF'
|
||||
test: add ContentServiceBenchmarkBase infrastructure class
|
||||
|
||||
Adds base class for ContentService performance benchmarks with:
|
||||
- RecordBenchmark() for timing capture
|
||||
- MeasureAndRecord() with warmup support
|
||||
- JSON output wrapped in [BENCHMARK_JSON] markers for extraction
|
||||
|
||||
🤖 Generated with [Claude Code](https://claude.com/claude-code)
|
||||
|
||||
Co-Authored-By: Claude <noreply@anthropic.com>
|
||||
EOF
|
||||
)"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Issue #3: MeasureAndRecord<T> Missing Warmup
|
||||
|
||||
**Location:** `ContentServiceBenchmarkBase.cs` lines 89-96
|
||||
|
||||
**Problem:** The generic `MeasureAndRecord<T>` overload does not perform warmup, unlike the `Action` overload:
|
||||
|
||||
```csharp
|
||||
// Current implementation - NO WARMUP
|
||||
protected T MeasureAndRecord<T>(string name, int itemCount, Func<T> func)
|
||||
{
|
||||
var sw = Stopwatch.StartNew();
|
||||
var result = func(); // First call includes JIT overhead
|
||||
sw.Stop();
|
||||
RecordBenchmark(name, sw.ElapsedMilliseconds, itemCount);
|
||||
return result;
|
||||
}
|
||||
```
|
||||
|
||||
**Impact:** Read-only benchmarks (Benchmarks 4, 5, 8-13, 20, 29, 30) will include JIT compilation overhead in measurements.
|
||||
|
||||
**Required Fix:** Add warmup to `MeasureAndRecord<T>`:
|
||||
|
||||
```csharp
|
||||
/// <summary>
|
||||
/// Measures and records a benchmark, returning the result of the function.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Performs a warmup call before measurement to trigger JIT compilation.
|
||||
/// Safe for read-only operations that can be repeated without side effects.
|
||||
/// </remarks>
|
||||
protected T MeasureAndRecord<T>(string name, int itemCount, Func<T> func)
|
||||
{
|
||||
// Warmup: triggers JIT compilation, warms caches
|
||||
try { func(); } catch { /* ignore warmup errors */ }
|
||||
|
||||
var sw = Stopwatch.StartNew();
|
||||
var result = func();
|
||||
sw.Stop();
|
||||
RecordBenchmark(name, sw.ElapsedMilliseconds, itemCount);
|
||||
return result;
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Issue #4: Missing Tracking for ContentServiceBaseTests
|
||||
|
||||
**Location:** Task 8, `ContentServiceBaseTests.cs`
|
||||
|
||||
**Problem:** The unit tests are commented out pending Phase 1 creation of `ContentServiceBase`. There's no mechanism to ensure they get uncommented when the class is created.
|
||||
|
||||
**Impact:** Tests could remain dormant indefinitely, providing no value.
|
||||
|
||||
**Required Fix:** Add a tracking mechanism. Options:
|
||||
|
||||
**Option A: Add a failing placeholder test (Recommended)**
|
||||
|
||||
Replace the current placeholder with a test that will fail when `ContentServiceBase` exists:
|
||||
|
||||
```csharp
|
||||
/// <summary>
|
||||
/// Tracking test: Fails when ContentServiceBase is created, reminding developers
|
||||
/// to uncomment the actual tests.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void ContentServiceBase_WhenCreated_UncommentTests()
|
||||
{
|
||||
// This test exists to track when ContentServiceBase is created.
|
||||
// When you see this test fail, uncomment all tests in this file
|
||||
// and delete this placeholder.
|
||||
|
||||
var type = Type.GetType("Umbraco.Cms.Infrastructure.Services.ContentServiceBase, Umbraco.Infrastructure");
|
||||
|
||||
Assert.That(type, Is.Null,
|
||||
"ContentServiceBase now exists! Uncomment the tests in this file and delete this placeholder.");
|
||||
}
|
||||
```
|
||||
|
||||
**Option B: Add TODO comment with issue reference**
|
||||
|
||||
Create a GitHub issue and reference it:
|
||||
|
||||
```csharp
|
||||
// TODO: Issue #XXXXX - Uncomment tests when ContentServiceBase is created in Phase 1
|
||||
// Tests are commented out because ContentServiceBase doesn't exist yet.
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 3. Minor Issues & Improvements
|
||||
|
||||
### 3.1 Permission Test Magic Strings
|
||||
|
||||
**Location:** Task 5, Tests 9-12
|
||||
|
||||
**Current:** Uses magic strings for permission codes:
|
||||
```csharp
|
||||
ContentService.SetPermission(content, "F", new[] { adminGroup!.Id }); // Browse
|
||||
ContentService.SetPermission(content, "U", new[] { adminGroup.Id }); // Update
|
||||
```
|
||||
|
||||
**Suggestion:** Document the permission codes inline or use constants:
|
||||
```csharp
|
||||
// Permission codes: F=Browse, U=Update, P=Publish
|
||||
// See Umbraco.Cms.Core.Actions for full list
|
||||
ContentService.SetPermission(content, "F", new[] { adminGroup!.Id });
|
||||
```
|
||||
|
||||
**Priority:** Consider (low impact, improves readability)
|
||||
|
||||
---
|
||||
|
||||
### 3.2 Benchmark Expected Ranges
|
||||
|
||||
**Location:** Task 7 (all benchmarks)
|
||||
|
||||
**Current:** Benchmarks capture timing but don't document expected ranges.
|
||||
|
||||
**Suggestion:** After initial baseline capture, add comments with rough expectations:
|
||||
```csharp
|
||||
// Baseline expectation: < 50ms (adjust after Phase 0 baseline capture)
|
||||
RecordBenchmark("Save_SingleItem", sw.ElapsedMilliseconds, 1);
|
||||
```
|
||||
|
||||
**Priority:** Consider (helpful for future regression detection)
|
||||
|
||||
**Note:** Per user clarification, benchmarks will NOT fail the build based on thresholds in the current phase. This may change in future phases.
|
||||
|
||||
---
|
||||
|
||||
### 3.3 Task 10 JSON Validation
|
||||
|
||||
**Location:** Task 10, Step 2
|
||||
|
||||
**Current:** Extracts JSON but doesn't validate it.
|
||||
|
||||
**Suggestion:** Add optional validation:
|
||||
```bash
|
||||
# Optional: Validate JSON format
|
||||
if command -v jq &> /dev/null; then
|
||||
if ! jq empty docs/plans/baseline-phase0.json 2>/dev/null; then
|
||||
echo "WARNING: baseline-phase0.json may contain invalid JSON"
|
||||
fi
|
||||
fi
|
||||
```
|
||||
|
||||
**Priority:** Consider (defensive, but jq may not be available everywhere)
|
||||
|
||||
---
|
||||
|
||||
## 4. Questions Resolved
|
||||
|
||||
### Q1: Baseline Thresholds
|
||||
|
||||
**Question:** Should any benchmarks fail the build if they exceed a certain threshold?
|
||||
|
||||
**Resolution:** No. Benchmarks currently capture metrics only. Threshold-based failures may be added in future phases.
|
||||
|
||||
---
|
||||
|
||||
### Q2: Async Method Coverage
|
||||
|
||||
**Question:** Are there async versions of ContentService methods that should be benchmarked?
|
||||
|
||||
**Resolution:**
|
||||
|
||||
| Service | Pattern | Async Methods |
|
||||
|---------|---------|---------------|
|
||||
| `IContentService` | Synchronous | Only `EmptyRecycleBinAsync` |
|
||||
| `IContentEditingService` | Fully async | `GetAsync`, `CreateAsync`, `UpdateAsync`, `MoveAsync`, etc. |
|
||||
|
||||
The Phase 0 plan correctly focuses on `IContentService` (the synchronous service being refactored). `IContentEditingService` is a separate API layer and not in scope for this phase.
|
||||
|
||||
---
|
||||
|
||||
### Q3: ContentServiceBaseTests Tracking
|
||||
|
||||
**Question:** Should there be a tracking mechanism for the commented tests?
|
||||
|
||||
**Resolution:** Yes. A tracking mechanism is required (see Issue #4 above).
|
||||
|
||||
---
|
||||
|
||||
### Q4: Base Class Properties
|
||||
|
||||
**Question:** Are `Textpage`, `Subpage`, `Subpage2`, `Subpage3` available from the base class?
|
||||
|
||||
**Resolution:** Yes. Verified in `UmbracoIntegrationTestWithContent.cs`:
|
||||
- `Textpage` - Root content item
|
||||
- `Subpage`, `Subpage2`, `Subpage3` - Children of Textpage, created in sequence
|
||||
- `ContentType` - The "umbTextpage" content type
|
||||
- `FileService`, `ContentTypeService` - Available via properties
|
||||
|
||||
The v1.2 assertions verifying initial sort order are appropriate defensive programming.
|
||||
|
||||
---
|
||||
|
||||
## 5. Summary of Required Changes
|
||||
|
||||
### Must Fix (Blocking)
|
||||
|
||||
| # | Issue | Location | Fix |
|
||||
|---|-------|----------|-----|
|
||||
| 1 | Variable shadowing | Task 3, Test 4, lines 509-511 | Remove `var` keyword |
|
||||
| 2 | Untracked file | `ContentServiceBenchmarkBase.cs` | Add Task 0 to commit |
|
||||
|
||||
### Should Fix (High Priority)
|
||||
|
||||
| # | Issue | Location | Fix |
|
||||
|---|-------|----------|-----|
|
||||
| 3 | Missing warmup | `MeasureAndRecord<T>` in base class | Add warmup call |
|
||||
| 4 | No tracking mechanism | Task 8, `ContentServiceBaseTests.cs` | Add tracking test or TODO |
|
||||
|
||||
### Consider (Optional)
|
||||
|
||||
| # | Issue | Location | Suggestion |
|
||||
|---|-------|----------|------------|
|
||||
| 5 | Magic strings | Task 5 permission tests | Add inline documentation |
|
||||
| 6 | No expected ranges | Task 7 benchmarks | Document after baseline capture |
|
||||
| 7 | No JSON validation | Task 10 | Add optional jq validation |
|
||||
|
||||
---
|
||||
|
||||
## 6. Final Recommendation
|
||||
|
||||
**Approve with Minor Changes**
|
||||
|
||||
The plan is ready for implementation after applying the four required fixes:
|
||||
|
||||
1. **Task 3, Test 4:** Remove `var` from lines 509-511
|
||||
2. **Add Task 0:** Commit `ContentServiceBenchmarkBase.cs` before Task 1
|
||||
3. **Update `ContentServiceBenchmarkBase.cs`:** Add warmup to `MeasureAndRecord<T>`
|
||||
4. **Task 8:** Add tracking mechanism for commented tests
|
||||
|
||||
Once these changes are incorporated (creating v1.3 of the plan), implementation can proceed.
|
||||
|
||||
---
|
||||
|
||||
## Appendix: Version History
|
||||
|
||||
| Version | Date | Reviewer | Summary |
|
||||
|---------|------|----------|---------|
|
||||
| 1.0 | 2025-12-20 | - | Initial implementation plan |
|
||||
| 1.1 | 2025-12-20 | Critical Review #1 | `[NonParallelizable]`, template null checks, POSIX sed, warmup |
|
||||
| 1.2 | 2025-12-20 | Critical Review #2 | Warmup data separation, data size standardization |
|
||||
| 1.3 | TBD | Critical Review #3 | Variable shadowing fix, commit base class, `MeasureAndRecord<T>` warmup, tracking mechanism |
|
||||
@@ -0,0 +1,78 @@
|
||||
# ContentService Refactoring Phase 0 Implementation Plan - Completion Summary
|
||||
|
||||
## 1. Overview
|
||||
|
||||
**Original Scope and Goals:**
|
||||
Phase 0 aimed to create test and benchmark infrastructure to establish baseline metrics and safety nets before the ContentService refactoring begins. The plan specified 12 tasks (Task 0-11), delivering 15 integration tests, 33 benchmarks, and 1 tracking unit test across 4 test files.
|
||||
|
||||
**Overall Completion Status:** Fully Completed (with post-completion fixes applied)
|
||||
|
||||
All planned tasks were executed, all test files were created, and baseline benchmarks were captured. A post-completion review identified and resolved 5 benchmark test implementation issues that were causing test failures.
|
||||
|
||||
---
|
||||
|
||||
## 2. Completed Items
|
||||
|
||||
- **Task 0:** Committed `ContentServiceBenchmarkBase.cs` with warmup support for `MeasureAndRecord` methods
|
||||
- **Task 1:** Created `ContentServiceRefactoringTests.cs` skeleton with notification handler infrastructure
|
||||
- **Task 2:** Added 2 notification ordering tests for MoveToRecycleBin behavior
|
||||
- **Task 3:** Added 3 sort operation tests (IContent, IDs, notifications)
|
||||
- **Task 4:** Added 3 DeleteOfType tests (descendants, mixed types, multiple types)
|
||||
- **Task 5:** Added 4 permission tests (SetPermission, multiple permissions, permission set, multiple groups)
|
||||
- **Task 6:** Added 3 transaction boundary tests (rollback, commit, MoveToRecycleBin rollback)
|
||||
- **Task 7:** Created `ContentServiceRefactoringBenchmarks.cs` with 33 benchmarks across 5 categories
|
||||
- **Task 8:** Created `ContentServiceBaseTests.cs` with tracking test for Phase 1 detection
|
||||
- **Task 9:** Verified all 15 integration tests pass
|
||||
- **Task 10:** Captured baseline benchmarks to `docs/plans/baseline-phase0.json`
|
||||
- **Task 11:** Created git tag `phase-0-baseline` and verified all artifacts
|
||||
|
||||
---
|
||||
|
||||
## 3. Partially Completed or Modified Items
|
||||
|
||||
- **Version-related benchmarks (GetVersions, GetVersionsSlim, Rollback, DeleteVersions):** Required post-completion modification. The original implementation used `Save()` to create versions, but Umbraco's versioning system requires `Publish()` to create new versions. Tests were corrected to call `Publish()` after each `Save()`.
|
||||
|
||||
- **HasChildren benchmark:** Required post-completion modification. The counter variable was accumulating across warmup and measurement runs due to the `MeasureAndRecord` warmup pattern. Fixed by resetting the counter inside the measurement action.
|
||||
|
||||
- **Baseline JSON:** Updated post-completion to reflect corrected benchmark values (33 entries now includes `Rollback_ToVersion` which was previously failing).
|
||||
|
||||
---
|
||||
|
||||
## 4. Omitted or Deferred Items
|
||||
|
||||
None. All items from the original plan were implemented.
|
||||
|
||||
---
|
||||
|
||||
## 5. Discrepancy Explanations
|
||||
|
||||
| Item | Discrepancy | Explanation |
|
||||
|------|-------------|-------------|
|
||||
| **Version benchmarks (4 tests)** | Tests failed initially | Technical misunderstanding of Umbraco's versioning model. `Save()` updates the existing draft version; only `Publish()` creates a new version entry. The plan's comment "Create 100 versions by saving repeatedly" was incorrect. |
|
||||
| **HasChildren benchmark** | Test failed with double-count | The `MeasureAndRecord` warmup pattern executes the action twice (warmup + measurement). Variables captured in closures retain their values across both runs, causing the counter to accumulate. |
|
||||
| **Baseline JSON values** | 5 entries differ from original capture | Original baseline captured incorrect values because the version tests were measuring single-version queries instead of 100-version queries. Corrected values reflect actual versioning behavior. |
|
||||
| **Rollback_ToVersion in baseline** | Missing from original baseline | The test was failing during original baseline capture, so no JSON was emitted. Now included after fix. |
|
||||
|
||||
---
|
||||
|
||||
## 6. Key Achievements
|
||||
|
||||
- **Comprehensive test coverage:** 15 integration tests covering notification ordering, sort operations, DeleteOfType, permissions, and transaction boundaries provide robust safety nets for refactoring.
|
||||
|
||||
- **Benchmark infrastructure:** 33 benchmarks with JSON output enable automated regression detection across refactoring phases.
|
||||
|
||||
- **Warmup pattern implementation:** Benchmarks correctly handle JIT warmup for accurate measurements, with `skipWarmup: true` for destructive operations.
|
||||
|
||||
- **Tracking test for Phase 1:** The `ContentServiceBase_WhenCreated_UncommentTests` test will automatically detect when Phase 1 creates the `ContentServiceBase` class, prompting developers to activate the unit tests.
|
||||
|
||||
- **Versioning behavior documentation:** The fix process documented an important Umbraco behavior: `Save()` updates drafts, `Publish()` creates versions. This knowledge is now captured in code comments (v1.3 remarks).
|
||||
|
||||
- **Git tag for baseline:** The `phase-0-baseline` tag provides a clear rollback point and reference for future comparisons.
|
||||
|
||||
---
|
||||
|
||||
## 7. Final Assessment
|
||||
|
||||
Phase 0 of the ContentService refactoring has been successfully completed. All planned test infrastructure is in place, with 15 integration tests validating behavioral contracts and 33 benchmarks establishing performance baselines. The post-completion fixes addressed implementation issues in 5 benchmark tests that stemmed from a misunderstanding of Umbraco's versioning model rather than issues with the ContentService itself.
|
||||
|
||||
The baseline JSON now contains accurate measurements for all 33 benchmarks, providing a reliable foundation for regression detection in subsequent refactoring phases. The tracking test ensures that unit tests for `ContentServiceBase` will be activated automatically when Phase 1 begins. The infrastructure is ready for Phase 1 implementation.
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,480 @@
|
||||
# Critical Implementation Review: Phase 1 ContentService CRUD Extraction
|
||||
|
||||
**Reviewed:** 2025-12-20
|
||||
**Plan:** `docs/plans/2025-12-20-contentservice-refactor-phase1-implementation.md`
|
||||
**Reviewer:** Claude (Senior Staff Engineer perspective)
|
||||
**Status:** ⚠️ Approve with Changes
|
||||
|
||||
---
|
||||
|
||||
## 1. Overall Assessment
|
||||
|
||||
### Strengths
|
||||
|
||||
- Clear task-by-task structure with TDD approach (write failing tests first)
|
||||
- Correct identification of methods to extract (Create, GetById, Save, Delete)
|
||||
- Follows existing Umbraco patterns (RepositoryService base, scoping, notifications)
|
||||
- Preserves notification system behavior (ContentSavingNotification, ContentDeletedNotification, etc.)
|
||||
- Maintains behavioral parity with existing ContentService for core operations
|
||||
- Proper use of dependency injection and interface-first design
|
||||
|
||||
### Major Concerns
|
||||
|
||||
- Nested scope issues in delete cascade operations
|
||||
- Potential DI circular dependency when ContentService depends on IContentCrudService
|
||||
- Missing behavioral parity in several edge cases
|
||||
- Bug in batch Save audit message (copies existing bug but perpetuates it)
|
||||
- Interface missing key read operations (GetAncestors, GetPagedChildren, GetPagedDescendants)
|
||||
|
||||
---
|
||||
|
||||
## 2. Critical Issues
|
||||
|
||||
### 2.1 Nested Scope Anti-Pattern in Delete Cascade
|
||||
|
||||
**Location:** `ContentCrudService.cs` lines 784-831
|
||||
|
||||
**Description:** `DeleteLocked` (line 784-805) calls `GetPagedDescendants` (line 810-831), which creates a NEW scope inside the already-open scope from `Delete` (line 754).
|
||||
|
||||
```csharp
|
||||
// Delete creates scope at line 754
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope())
|
||||
{
|
||||
// ...
|
||||
DeleteLocked(scope, content, eventMessages); // line 772
|
||||
}
|
||||
|
||||
// DeleteLocked calls GetPagedDescendants at line 797
|
||||
IEnumerable<IContent> descendants = GetPagedDescendants(content.Id, 0, pageSize, out total);
|
||||
|
||||
// GetPagedDescendants creates ANOTHER scope at line 812
|
||||
private IEnumerable<IContent> GetPagedDescendants(...)
|
||||
{
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) // NESTED!
|
||||
{
|
||||
scope.ReadLock(Constants.Locks.ContentTree);
|
||||
// ...
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Why it matters:**
|
||||
- Redundant read locks on the same resource (`Constants.Locks.ContentTree`)
|
||||
- Potential deadlock scenarios under high concurrency
|
||||
- Performance overhead from scope creation/disposal
|
||||
- Violates single responsibility - helper method shouldn't manage its own transaction
|
||||
|
||||
**Required Fix:** The private `GetPagedDescendants` should NOT create its own scope. It's only called from `DeleteLocked`, which already holds a scope. Refactor to:
|
||||
|
||||
```csharp
|
||||
/// <summary>
|
||||
/// Gets paged descendants for internal use. MUST be called within an existing scope.
|
||||
/// </summary>
|
||||
private IEnumerable<IContent> GetPagedDescendantsLocked(int id, long pageIndex, int pageSize, out long totalRecords)
|
||||
{
|
||||
// No scope creation - assumes caller holds scope with proper locks
|
||||
if (id != Constants.System.Root)
|
||||
{
|
||||
var contentPath = _entityRepository.GetAllPaths(Constants.ObjectTypes.Document, id).FirstOrDefault();
|
||||
if (contentPath == null)
|
||||
{
|
||||
totalRecords = 0;
|
||||
return Enumerable.Empty<IContent>();
|
||||
}
|
||||
|
||||
IQuery<IContent>? query = Query<IContent>();
|
||||
query?.Where(x => x.Path.SqlStartsWith($"{contentPath.Path},", TextColumnType.NVarchar));
|
||||
return DocumentRepository.GetPage(query, pageIndex, pageSize, out totalRecords, null, Ordering.By("Path", Direction.Descending));
|
||||
}
|
||||
|
||||
return DocumentRepository.GetPage(null, pageIndex, pageSize, out totalRecords, null, Ordering.By("Path", Direction.Descending));
|
||||
}
|
||||
```
|
||||
|
||||
Update `DeleteLocked` to call `GetPagedDescendantsLocked` instead.
|
||||
|
||||
---
|
||||
|
||||
### 2.2 Circular Dependency Risk in DI
|
||||
|
||||
**Location:** Task 5, lines 1073-1074 of the plan
|
||||
|
||||
**Description:** Task 5 injects `IContentCrudService` into `ContentService`. But the obsolete constructors chain via `StaticServiceProvider.Instance.GetRequiredService<IContentCrudService>()`.
|
||||
|
||||
```csharp
|
||||
// Proposed in plan:
|
||||
StaticServiceProvider.Instance.GetRequiredService<IContentCrudService>()
|
||||
```
|
||||
|
||||
**Why it matters:**
|
||||
- `StaticServiceProvider.Instance` may not be initialized when obsolete constructors are called during application startup
|
||||
- Creates tight coupling to service locator pattern (anti-pattern)
|
||||
- Risk of stack overflow if resolution order is wrong
|
||||
- Hard to debug initialization failures
|
||||
|
||||
**Required Fix:** Use `Lazy<T>` to defer resolution:
|
||||
|
||||
```csharp
|
||||
// In ContentService field declarations:
|
||||
private readonly Lazy<IContentCrudService> _crudServiceLazy;
|
||||
|
||||
// In obsolete constructor chain, pass a lazy resolver:
|
||||
_crudServiceLazy = new Lazy<IContentCrudService>(() =>
|
||||
StaticServiceProvider.Instance.GetRequiredService<IContentCrudService>());
|
||||
|
||||
// Usage in delegating methods:
|
||||
private IContentCrudService CrudService => _crudServiceLazy.Value;
|
||||
|
||||
public IContent? GetById(int id) => CrudService.GetById(id);
|
||||
```
|
||||
|
||||
Alternatively, for the primary constructor:
|
||||
|
||||
```csharp
|
||||
// Primary constructor receives the service directly:
|
||||
public ContentService(
|
||||
// ... other params ...
|
||||
IContentCrudService crudService) // Direct injection
|
||||
{
|
||||
_crudService = crudService ?? throw new ArgumentNullException(nameof(crudService));
|
||||
}
|
||||
|
||||
// Obsolete constructors use Lazy pattern for backward compatibility
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 2.3 Bug in Batch Save Audit Message
|
||||
|
||||
**Location:** `ContentCrudService.cs` line 737
|
||||
|
||||
**Description:**
|
||||
```csharp
|
||||
string contentIds = string.Join(", ", contentsA.Select(x => x.Id));
|
||||
Audit(AuditType.Save, userId, Constants.System.Root, $"Saved multiple content items (#{contentIds.Length})");
|
||||
```
|
||||
|
||||
`contentIds` is a string, so `contentIds.Length` returns the **character count of the joined string**, not the **number of items**.
|
||||
|
||||
**Example:** Saving items with IDs 1, 2, 100 produces `contentIds = "1, 2, 100"` (length 10), resulting in audit message "Saved multiple content items (#10)" instead of "#3".
|
||||
|
||||
**Why it matters:** Audit trail will show incorrect counts, making debugging and compliance auditing unreliable.
|
||||
|
||||
**Required Fix:**
|
||||
```csharp
|
||||
string contentIds = string.Join(", ", contentsA.Select(x => x.Id));
|
||||
Audit(AuditType.Save, userId, Constants.System.Root, $"Saved multiple content items ({contentsA.Length})");
|
||||
```
|
||||
|
||||
Note: This bug exists in the original `ContentService.cs` at line 1202. The refactoring should fix it rather than propagate it.
|
||||
|
||||
---
|
||||
|
||||
### 2.4 Create Method Null Parent Error Propagation
|
||||
|
||||
**Location:** `ContentCrudService.cs` lines 433-437 and 464-477
|
||||
|
||||
**Description:** `Create(name, Guid parentId, ...)` calls `GetById(parentId)` which may return null, then passes null to `Create(name, IContent? parent, ...)` which throws `ArgumentNullException(nameof(parent))`.
|
||||
|
||||
```csharp
|
||||
public IContent Create(string name, Guid parentId, string contentTypeAlias, int userId = ...)
|
||||
{
|
||||
IContent? parent = GetById(parentId); // May return null
|
||||
return Create(name, parent, contentTypeAlias, userId); // Throws ArgumentNullException("parent")
|
||||
}
|
||||
|
||||
public IContent Create(string name, IContent? parent, string contentTypeAlias, int userId = ...)
|
||||
{
|
||||
if (parent == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(parent)); // Misleading error message
|
||||
}
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
**Why it matters:** Error message is misleading - user gets "parent cannot be null" instead of "No content with that key exists." This makes debugging harder for API consumers.
|
||||
|
||||
**Required Fix:**
|
||||
```csharp
|
||||
public IContent Create(string name, Guid parentId, string contentTypeAlias, int userId = Constants.Security.SuperUserId)
|
||||
{
|
||||
IContent? parent = GetById(parentId);
|
||||
if (parent == null)
|
||||
{
|
||||
throw new ArgumentException($"No content with key '{parentId}' exists.", nameof(parentId));
|
||||
}
|
||||
return Create(name, parent, contentTypeAlias, userId);
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 2.5 Missing Validation in CreateAndSave with Parent Object
|
||||
|
||||
**Location:** `ContentCrudService.cs` lines 507-529
|
||||
|
||||
**Description:** `CreateAndSave(string name, IContent parent, ...)` calls `GetContentType(contentTypeAlias)` inside the scope, but doesn't verify the parent is not trashed before creating child content.
|
||||
|
||||
```csharp
|
||||
public IContent CreateAndSave(string name, IContent parent, string contentTypeAlias, int userId = ...)
|
||||
{
|
||||
if (parent == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(parent));
|
||||
}
|
||||
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope())
|
||||
{
|
||||
scope.WriteLock(Constants.Locks.ContentTree);
|
||||
// Missing: parent.Trashed check
|
||||
|
||||
IContentType contentType = GetContentType(contentTypeAlias) ?? throw ...;
|
||||
var content = new Content(name, parent, contentType, userId);
|
||||
Save(content, userId);
|
||||
// ...
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Why it matters:** Users can inadvertently create content under trashed parents, which violates business rules and creates orphaned content in the recycle bin.
|
||||
|
||||
**Required Fix:** Add validation after the write lock:
|
||||
```csharp
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope())
|
||||
{
|
||||
scope.WriteLock(Constants.Locks.ContentTree);
|
||||
|
||||
if (parent.Trashed)
|
||||
{
|
||||
throw new InvalidOperationException($"Cannot create content under trashed parent '{parent.Name}' (id={parent.Id}).");
|
||||
}
|
||||
|
||||
IContentType contentType = GetContentType(contentTypeAlias)
|
||||
?? throw new ArgumentException("No content type with that alias.", nameof(contentTypeAlias));
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 2.6 Interface Missing Key Read Operations
|
||||
|
||||
**Location:** `IContentCrudService.cs` - Read region
|
||||
|
||||
**Description:** `IContentCrudService` is missing several "Get" methods that are commonly grouped with CRUD:
|
||||
- `GetAncestors(int id)` / `GetAncestors(IContent content)`
|
||||
- `GetPagedChildren(int id, long pageIndex, int pageSize, out long totalChildren, ...)`
|
||||
- `GetPagedDescendants(int id, long pageIndex, int pageSize, out long totalChildren, ...)`
|
||||
|
||||
**Why it matters:**
|
||||
- Consumers expecting a complete CRUD service will find incomplete functionality
|
||||
- Future phases will need to extend the interface, causing breaking changes
|
||||
- Tree traversal operations are fundamental to content CRUD
|
||||
|
||||
**Required Fix:** Add these methods to `IContentCrudService`:
|
||||
|
||||
```csharp
|
||||
#region Read (Additional)
|
||||
|
||||
/// <summary>
|
||||
/// Gets ancestors of a document.
|
||||
/// </summary>
|
||||
/// <param name="id">Id of the document.</param>
|
||||
/// <returns>The ancestor documents, from parent to root.</returns>
|
||||
IEnumerable<IContent> GetAncestors(int id);
|
||||
|
||||
/// <summary>
|
||||
/// Gets ancestors of a document.
|
||||
/// </summary>
|
||||
/// <param name="content">The document.</param>
|
||||
/// <returns>The ancestor documents, from parent to root.</returns>
|
||||
IEnumerable<IContent> GetAncestors(IContent content);
|
||||
|
||||
/// <summary>
|
||||
/// Gets paged children of a document.
|
||||
/// </summary>
|
||||
/// <param name="id">Id of the parent document.</param>
|
||||
/// <param name="pageIndex">Zero-based page index.</param>
|
||||
/// <param name="pageSize">Page size.</param>
|
||||
/// <param name="totalChildren">Total number of children.</param>
|
||||
/// <param name="filter">Optional filter query.</param>
|
||||
/// <param name="ordering">Optional ordering.</param>
|
||||
/// <returns>The child documents.</returns>
|
||||
IEnumerable<IContent> GetPagedChildren(int id, long pageIndex, int pageSize, out long totalChildren, IQuery<IContent>? filter = null, Ordering? ordering = null);
|
||||
|
||||
/// <summary>
|
||||
/// Gets paged descendants of a document.
|
||||
/// </summary>
|
||||
/// <param name="id">Id of the ancestor document.</param>
|
||||
/// <param name="pageIndex">Zero-based page index.</param>
|
||||
/// <param name="pageSize">Page size.</param>
|
||||
/// <param name="totalChildren">Total number of descendants.</param>
|
||||
/// <param name="filter">Optional filter query.</param>
|
||||
/// <param name="ordering">Optional ordering.</param>
|
||||
/// <returns>The descendant documents.</returns>
|
||||
IEnumerable<IContent> GetPagedDescendants(int id, long pageIndex, int pageSize, out long totalChildren, IQuery<IContent>? filter = null, Ordering? ordering = null);
|
||||
|
||||
#endregion
|
||||
```
|
||||
|
||||
And implement them in `ContentCrudService` by moving the existing implementations from `ContentService`.
|
||||
|
||||
---
|
||||
|
||||
## 3. Minor Issues & Improvements
|
||||
|
||||
### 3.1 Inconsistent Null Check Style
|
||||
|
||||
**Location:** Throughout `ContentCrudService.cs`
|
||||
|
||||
**Issue:** Mix of `is null` and `== null` patterns:
|
||||
```csharp
|
||||
if (contentType is null) // Line 449
|
||||
if (parent == null) // Line 454
|
||||
```
|
||||
|
||||
**Recommendation:** Standardize on `is null` (C# 9+ pattern matching) for consistency with modern C# idioms.
|
||||
|
||||
---
|
||||
|
||||
### 3.2 Magic Number for Page Size
|
||||
|
||||
**Location:** `ContentCrudService.cs` line 792
|
||||
|
||||
```csharp
|
||||
const int pageSize = 500; // In DeleteLocked
|
||||
```
|
||||
|
||||
**Recommendation:** Extract to a constant in a shared location:
|
||||
```csharp
|
||||
// In Constants.cs or a new ContentServiceConstants class
|
||||
public static class ContentServiceConstants
|
||||
{
|
||||
public const int DefaultBatchPageSize = 500;
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 3.3 Memory Allocation in GetByIds
|
||||
|
||||
**Location:** `ContentCrudService.cs` lines 557, 576
|
||||
|
||||
```csharp
|
||||
var idsA = ids.ToArray();
|
||||
```
|
||||
|
||||
**Issue:** This allocates an array even if the input is already an array.
|
||||
|
||||
**Recommendation:** Use pattern matching to avoid unnecessary allocation:
|
||||
```csharp
|
||||
var idsA = ids as int[] ?? ids.ToArray();
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 3.4 GetLanguageDetailsForAuditEntry Efficiency
|
||||
|
||||
**Location:** `ContentCrudService.cs` lines 847-856
|
||||
|
||||
```csharp
|
||||
private string GetLanguageDetailsForAuditEntry(IEnumerable<string> affectedCultures)
|
||||
{
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true))
|
||||
{
|
||||
var languages = _languageRepository.GetMany(); // Gets ALL languages
|
||||
// ...
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Issue:** Retrieves ALL languages to filter for just the affected cultures. For sites with many languages, this is inefficient.
|
||||
|
||||
**Recommendation:** Consider caching the language list at service level or filtering in the repository query.
|
||||
|
||||
---
|
||||
|
||||
### 3.5 Unit Test Coverage Too Minimal
|
||||
|
||||
**Location:** `ContentCrudServiceTests.cs` in the plan
|
||||
|
||||
**Issue:** The unit test only verifies constructor injection:
|
||||
```csharp
|
||||
[Test]
|
||||
public void Constructor_WithValidDependencies_CreatesInstance()
|
||||
{
|
||||
// Only tests that service can be constructed
|
||||
}
|
||||
```
|
||||
|
||||
**Recommendation:** Add at minimum:
|
||||
- Test for each `Create` overload returning non-null
|
||||
- Test for `GetById` with non-existent ID returning null
|
||||
- Test for `Save` triggering notifications (mock verification)
|
||||
- Test for `Delete` triggering cascade deletion notifications
|
||||
|
||||
---
|
||||
|
||||
### 3.6 Missing Using Statements
|
||||
|
||||
**Location:** `ContentCrudService.cs` implementation
|
||||
|
||||
**Issue:** The implementation references types without showing all required using statements:
|
||||
- `TreeChangeTypes` requires `using Umbraco.Cms.Core.Services.Changes;`
|
||||
- `Ordering` requires `using Umbraco.Cms.Core.Persistence.Querying;`
|
||||
- `TextColumnType` requires appropriate using
|
||||
|
||||
**Recommendation:** Ensure the implementation file includes all necessary using statements.
|
||||
|
||||
---
|
||||
|
||||
## 4. Questions for Clarification
|
||||
|
||||
1. **Scope Nesting Intentionality:** Is the nested scope pattern in `Delete` → `GetPagedDescendants` intentional for re-entrance support, or should the private helper assume an existing scope?
|
||||
|
||||
2. **Interface Versioning Strategy:** Will `IContentCrudService` follow semantic versioning? Adding methods later is a breaking change for implementers.
|
||||
|
||||
3. **Obsolete Constructor Support Duration:** The plan chains obsolete constructors to resolve IContentCrudService. How long will these be supported? Should they instead throw immediately?
|
||||
|
||||
4. **Integration Test Selection:** The plan runs all `ContentService` tests, but doesn't specify if there are specific tests for the methods being extracted. Are there isolated tests for Create/GetById/Save/Delete that should pass first?
|
||||
|
||||
---
|
||||
|
||||
## 5. Summary of Required Changes
|
||||
|
||||
| Priority | Issue | Fix |
|
||||
|----------|-------|-----|
|
||||
| **High** | 2.1 Nested scope in DeleteLocked | Refactor `GetPagedDescendants` to `GetPagedDescendantsLocked` without scope |
|
||||
| **High** | 2.2 Circular DI dependency | Use `Lazy<IContentCrudService>` for obsolete constructors |
|
||||
| **High** | 2.3 Batch Save audit bug | Change `contentIds.Length` to `contentsA.Length` |
|
||||
| **Medium** | 2.4 Misleading null parent error | Add explicit check in `Create(Guid parentId, ...)` |
|
||||
| **Medium** | 2.5 Missing trashed parent check | Add `parent.Trashed` validation in `CreateAndSave` |
|
||||
| **Medium** | 2.6 Incomplete interface | Add `GetAncestors`, `GetPagedChildren`, `GetPagedDescendants` |
|
||||
| **Low** | 3.1 Inconsistent null checks | Standardize on `is null` pattern |
|
||||
| **Low** | 3.2 Magic number | Extract `pageSize = 500` to constant |
|
||||
| **Low** | 3.3 Array allocation | Use pattern matching in `GetByIds` |
|
||||
|
||||
---
|
||||
|
||||
## 6. Final Recommendation
|
||||
|
||||
### ⚠️ **Approve with Changes**
|
||||
|
||||
The plan demonstrates sound architectural thinking and follows established Umbraco patterns. The core design of extracting CRUD operations into a focused service is correct and aligns with the refactoring goals.
|
||||
|
||||
However, **implementation cannot proceed** until the High priority issues are addressed:
|
||||
|
||||
1. The nested scope issue (2.1) can cause deadlocks in production
|
||||
2. The DI circular dependency (2.2) can cause startup failures
|
||||
3. The audit bug (2.3) corrupts audit trail data
|
||||
|
||||
Once these issues are fixed in the plan, implementation can proceed with confidence that the extracted service will maintain behavioral parity with the existing ContentService while improving code organization.
|
||||
|
||||
---
|
||||
|
||||
**Next Steps:**
|
||||
1. Update the plan to address all High priority issues
|
||||
2. Add the missing interface methods (2.6)
|
||||
3. Re-review the updated plan
|
||||
4. Proceed with implementation using `superpowers:executing-plans`
|
||||
@@ -0,0 +1,530 @@
|
||||
# Critical Implementation Review: Phase 1 ContentService CRUD Extraction
|
||||
|
||||
**Plan Version:** 1.2
|
||||
**Plan File:** `docs/plans/2025-12-20-contentservice-refactor-phase1-implementation.md`
|
||||
**Reviewer:** Critical Implementation Review
|
||||
**Date:** 2025-12-20
|
||||
|
||||
---
|
||||
|
||||
## 1. Overall Assessment
|
||||
|
||||
**Summary:** The plan is well-structured with clear task sequencing, versioning strategy, and already incorporates fixes from a previous review (v1.1). The architecture follows established Umbraco patterns. However, several critical issues remain that must be addressed before implementation to prevent production bugs, performance degradation, and maintenance challenges.
|
||||
|
||||
**Strengths:**
|
||||
- Clear versioning strategy with deprecation policy
|
||||
- TDD approach with failing tests first
|
||||
- Incremental commits for easy rollback
|
||||
- Good separation of concerns via delegation pattern
|
||||
- Previous review feedback already incorporated (nested scope fix, Lazy<T> pattern, batch audit fix)
|
||||
|
||||
**Major Concerns:**
|
||||
1. **GetAncestors has O(n) database round trips** for deeply nested content
|
||||
2. **Incomplete interface vs. IContentService parity** - missing methods will break delegation
|
||||
3. **Constructor bloat risk** - 17+ parameters creates maintenance burden
|
||||
4. **Filter parameter ignored** in GetPagedChildren/GetPagedDescendants
|
||||
5. **Race condition** in delete loop with concurrent operations
|
||||
|
||||
---
|
||||
|
||||
## 2. Critical Issues
|
||||
|
||||
### 2.1 GetAncestors N+1 Query Pattern (Performance)
|
||||
|
||||
**Location:** Lines 795-807 in ContentCrudService implementation
|
||||
|
||||
**Description:** The `GetAncestors` implementation walks up the tree one node at a time:
|
||||
|
||||
```csharp
|
||||
while (current is not null)
|
||||
{
|
||||
ancestors.Add(current);
|
||||
current = GetParent(current); // Each call = 1 database round trip
|
||||
}
|
||||
```
|
||||
|
||||
**Impact:** For content at level 10, this triggers 10 separate database queries. Large sites with deep hierarchies will suffer severe performance degradation.
|
||||
|
||||
**Fix:**
|
||||
```csharp
|
||||
public IEnumerable<IContent> GetAncestors(IContent content)
|
||||
{
|
||||
if (content?.Path == null || content.Level <= 1)
|
||||
{
|
||||
return Enumerable.Empty<IContent>();
|
||||
}
|
||||
|
||||
// Parse path to get ancestor IDs: "-1,123,456,789" -> [123, 456]
|
||||
var ancestorIds = content.Path
|
||||
.Split(',')
|
||||
.Skip(1) // Skip root (-1)
|
||||
.Select(int.Parse)
|
||||
.Where(id => id != content.Id) // Exclude self
|
||||
.ToArray();
|
||||
|
||||
return GetByIds(ancestorIds); // Single batch query
|
||||
}
|
||||
```
|
||||
|
||||
**Severity:** HIGH - Performance critical for tree operations
|
||||
|
||||
---
|
||||
|
||||
### 2.2 Incomplete Interface Parity with IContentService
|
||||
|
||||
**Location:** Lines 210-431 in IContentCrudService interface definition
|
||||
|
||||
**Description:** The plan delegates these methods to `CrudService`, but `IContentCrudService` doesn't define them all. Specifically:
|
||||
- `GetPagedChildren` signature mismatch - existing ContentService has multiple overloads
|
||||
- Missing `HasChildren(int id)` which may be called internally
|
||||
- Missing `Exists(int id)` and `Exists(Guid key)` read operations
|
||||
|
||||
**Impact:** When `ContentService` delegates to `CrudService`, it will get compilation errors if the interface lacks these methods.
|
||||
|
||||
**Fix:** Audit all methods being delegated in Task 5 (lines 1249-1312) and ensure every signature exists in `IContentCrudService`. Add:
|
||||
```csharp
|
||||
bool HasChildren(int id);
|
||||
bool Exists(int id);
|
||||
bool Exists(Guid key);
|
||||
```
|
||||
|
||||
**Severity:** HIGH - Build failure during implementation
|
||||
|
||||
---
|
||||
|
||||
### 2.3 Filter Parameter Silently Ignored in GetPagedChildren
|
||||
|
||||
**Location:** Lines 818-825 in ContentCrudService implementation
|
||||
|
||||
**Description:**
|
||||
```csharp
|
||||
if (filter is not null)
|
||||
{
|
||||
// Note: Query combination logic would need to be implemented
|
||||
// For now, the filter is applied after the parent filter
|
||||
}
|
||||
```
|
||||
|
||||
The comment says "would need to be implemented" but the code doesn't implement it. The filter is passed to `DocumentRepository.GetPage` but the parent query is separate, meaning **the filter may not work correctly**.
|
||||
|
||||
**Impact:** Callers relying on filter behavior will get unexpected results.
|
||||
|
||||
**Fix:** Properly combine queries using the repository's query capabilities. The `DocumentRepository.GetPage` method accepts both a base query and a filter parameter, which it combines internally:
|
||||
|
||||
```csharp
|
||||
/// <inheritdoc />
|
||||
public IEnumerable<IContent> GetPagedChildren(int id, long pageIndex, int pageSize, out long totalChildren, IQuery<IContent>? filter = null, Ordering? ordering = null)
|
||||
{
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true))
|
||||
{
|
||||
scope.ReadLock(Constants.Locks.ContentTree);
|
||||
|
||||
// Create base query for parent constraint
|
||||
IQuery<IContent> query = Query<IContent>().Where(x => x.ParentId == id);
|
||||
|
||||
// Pass both query and filter to repository - repository handles combination
|
||||
// The filter parameter is applied as an additional WHERE clause by the repository
|
||||
return DocumentRepository.GetPage(query, pageIndex, pageSize, out totalChildren, filter, ordering);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Remove the misleading comment block entirely. The repository's `GetPage` signature is:
|
||||
```csharp
|
||||
IEnumerable<IContent> GetPage(IQuery<IContent>? query, long pageIndex, int pageSize,
|
||||
out long totalRecords, IQuery<IContent>? filter, Ordering? ordering);
|
||||
```
|
||||
|
||||
The `query` parameter provides the base constraint (parentId), and `filter` provides additional caller-specified filtering. Both are combined by the repository layer.
|
||||
|
||||
**Severity:** HIGH - Behavioral parity violation
|
||||
|
||||
---
|
||||
|
||||
### 2.4 Race Condition in Delete Loop
|
||||
|
||||
**Location:** Lines 1020-1034 in DeleteLocked
|
||||
|
||||
**Description:**
|
||||
```csharp
|
||||
while (total > 0)
|
||||
{
|
||||
IEnumerable<IContent> descendants = GetPagedDescendantsLocked(content.Id, 0, pageSize, out total);
|
||||
foreach (IContent c in descendants)
|
||||
{
|
||||
DoDelete(c);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
If another process adds content while this loop runs, `total` might never reach 0 (content added between deletion batches). Though unlikely in practice due to write locks, the loop condition is fragile.
|
||||
|
||||
**Impact:** Potential infinite loop in rare concurrent scenarios.
|
||||
|
||||
**Fix:** Use a bounded iteration count or break when no results returned:
|
||||
```csharp
|
||||
const int maxIterations = 10000; // Safety limit
|
||||
int iterations = 0;
|
||||
while (total > 0 && iterations++ < maxIterations)
|
||||
{
|
||||
IEnumerable<IContent> descendants = GetPagedDescendantsLocked(content.Id, 0, pageSize, out total);
|
||||
var batch = descendants.ToList(); // Materialize once
|
||||
if (batch.Count == 0) break; // No more results, exit even if total > 0
|
||||
|
||||
foreach (IContent c in batch)
|
||||
{
|
||||
DoDelete(c);
|
||||
}
|
||||
}
|
||||
|
||||
if (iterations >= maxIterations)
|
||||
{
|
||||
_logger.LogWarning("Delete operation for content {ContentId} reached max iterations ({MaxIterations})",
|
||||
content.Id, maxIterations);
|
||||
}
|
||||
```
|
||||
|
||||
**Severity:** MEDIUM - Edge case but could cause production issues
|
||||
|
||||
---
|
||||
|
||||
### 2.5 Missing Logging for Operation Failures
|
||||
|
||||
**Location:** Throughout ContentCrudService implementation
|
||||
|
||||
**Description:** The `Save` and `Delete` methods don't log when operations are cancelled or fail. The original `ContentService` has `_logger` usage in critical paths.
|
||||
|
||||
**Impact:** Production debugging becomes difficult without visibility into cancelled operations.
|
||||
|
||||
**Fix:** Add logging for cancellation and validation failures:
|
||||
```csharp
|
||||
if (scope.Notifications.PublishCancelable(savingNotification))
|
||||
{
|
||||
_logger.LogInformation("Save operation cancelled for content {ContentId} by notification handler", content.Id);
|
||||
scope.Complete();
|
||||
return OperationResult.Cancel(eventMessages);
|
||||
}
|
||||
```
|
||||
|
||||
**Severity:** MEDIUM - Operational visibility
|
||||
|
||||
---
|
||||
|
||||
### 2.6 ContentServiceBase Audit Method Blocks Async
|
||||
|
||||
**Location:** Lines 133-135 in ContentServiceBase
|
||||
|
||||
**Description:**
|
||||
```csharp
|
||||
protected void Audit(AuditType type, int userId, int objectId, string? message = null, string? parameters = null) =>
|
||||
AuditAsync(type, userId, objectId, message, parameters).GetAwaiter().GetResult();
|
||||
```
|
||||
|
||||
Using `.GetAwaiter().GetResult()` blocks the thread and can cause deadlocks in certain synchronization contexts.
|
||||
|
||||
**Impact:** Potential deadlocks on ASP.NET Core when called from async context.
|
||||
|
||||
**Note:** This matches the existing `ContentService` pattern (line 3122-3123), so maintaining parity is acceptable for Phase 1. However, consider marking this for future refactoring to async-first approach.
|
||||
|
||||
**Severity:** LOW (maintains existing behavior) - Flag for future phases
|
||||
|
||||
---
|
||||
|
||||
## 3. Minor Issues & Improvements
|
||||
|
||||
### 3.1 Inconsistent Null-Forgiving Operator Usage
|
||||
|
||||
**Location:** Line 643 - `new Content(name, parent!, contentType, userId)`
|
||||
|
||||
**Issue:** Uses `!` on parent despite checking `parentId > 0 && parent is null` throws. This is correct but looks suspicious.
|
||||
|
||||
**Suggestion:** Add comment or restructure:
|
||||
```csharp
|
||||
// Parent is guaranteed non-null here because parentId > 0 and we throw if parent not found
|
||||
Content content = new Content(name, parent!, contentType, userId);
|
||||
```
|
||||
|
||||
### 3.2 Code Duplication in CreateAndSave Overloads
|
||||
|
||||
**Location:** Lines 620-683 (both CreateAndSave methods)
|
||||
|
||||
**Issue:** Both methods have nearly identical validation and setup logic.
|
||||
|
||||
**Suggestion:** Extract common logic to private helper:
|
||||
```csharp
|
||||
private Content CreateContentInternal(string name, IContent? parent, int parentId, IContentType contentType, int userId)
|
||||
{
|
||||
// Shared validation and construction
|
||||
}
|
||||
```
|
||||
|
||||
### 3.3 Missing XML Documentation for Internal Methods
|
||||
|
||||
**Location:** `GetPagedDescendantsLocked`, `DeleteLocked`
|
||||
|
||||
**Issue:** Internal methods lack documentation about preconditions (must be called within scope with write lock).
|
||||
|
||||
**Suggestion:** Add `<remarks>` documenting the scope/lock requirements.
|
||||
|
||||
### 3.4 Test Coverage Gap
|
||||
|
||||
**Location:** Task 3, Step 1 - Only one unit test
|
||||
|
||||
**Issue:** The single constructor test (`Constructor_WithValidDependencies_CreatesInstance`) doesn't test any actual behavior.
|
||||
|
||||
**Suggestion:** Add unit tests for:
|
||||
- `Create` with invalid parent ID throws
|
||||
- `Create` with null content type throws
|
||||
- `GetById` returns null for non-existent ID
|
||||
- Batch save with empty collection
|
||||
|
||||
### 3.5 Potential Memory Pressure in GetByIds Dictionary
|
||||
|
||||
**Location:** Lines 723-724
|
||||
|
||||
```csharp
|
||||
var index = items.ToDictionary(x => x.Id, x => x);
|
||||
return idsA.Select(x => index.GetValueOrDefault(x)).WhereNotNull();
|
||||
```
|
||||
|
||||
**Issue:** For large ID arrays, creating a dictionary doubles memory.
|
||||
|
||||
**Suggestion:** Only optimize if profiling shows issues. Current approach is correct for most use cases.
|
||||
|
||||
---
|
||||
|
||||
## 4. Questions for Clarification
|
||||
|
||||
1. **Circular Dependency Verification:** Has the `Lazy<IContentCrudService>` pattern in obsolete constructors been verified to work at runtime? The plan mentions the risk but doesn't confirm testing.
|
||||
|
||||
2. **ContentSchedule Handling:** The `Save` method accepts `ContentScheduleCollection` but the batch save doesn't. Is this intentional parity with existing behavior?
|
||||
|
||||
3. **Tree Traversal Methods:** The plan adds `GetAncestors`, `GetPagedChildren`, `GetPagedDescendants` to the CRUD service. Are these truly CRUD operations, or should they remain in a separate "navigation" service in future phases?
|
||||
|
||||
4. **Notification State Passing:** The `ContentSavedNotification` uses `.WithStateFrom(savingNotification)`. Is the state transfer pattern tested for the delegated implementation?
|
||||
|
||||
---
|
||||
|
||||
## 5. Benchmark Regression Threshold Enforcement
|
||||
|
||||
**Question from Plan:** The plan mentions "no >20% regression" in benchmarks. Where is this threshold defined and enforced?
|
||||
|
||||
**Recommendation:** Implement in-test assertions with specific gating for Phase 1 CRUD benchmarks.
|
||||
|
||||
### 5.1 Implementation: Update ContentServiceBenchmarkBase
|
||||
|
||||
Add the following to `tests/Umbraco.Tests.Integration/Testing/ContentServiceBenchmarkBase.cs`:
|
||||
|
||||
```csharp
|
||||
// Add to class fields
|
||||
private static readonly string BaselinePath = Path.Combine(
|
||||
TestContext.CurrentContext.TestDirectory,
|
||||
"..", "..", "..", "..", "..",
|
||||
"docs", "plans", "baseline-phase0.json");
|
||||
|
||||
private Dictionary<string, BenchmarkResult>? _baseline;
|
||||
private const double DefaultRegressionThreshold = 20.0;
|
||||
|
||||
/// <summary>
|
||||
/// Records a benchmark and asserts no regression beyond the threshold.
|
||||
/// </summary>
|
||||
/// <param name="name">Benchmark name (must match baseline JSON key).</param>
|
||||
/// <param name="elapsedMs">Measured elapsed time in milliseconds.</param>
|
||||
/// <param name="itemCount">Number of items processed.</param>
|
||||
/// <param name="thresholdPercent">Maximum allowed regression percentage (default: 20%).</param>
|
||||
protected void AssertNoRegression(string name, long elapsedMs, int itemCount, double thresholdPercent = DefaultRegressionThreshold)
|
||||
{
|
||||
RecordBenchmark(name, elapsedMs, itemCount);
|
||||
|
||||
_baseline ??= LoadBaseline();
|
||||
|
||||
if (_baseline.TryGetValue(name, out var baselineResult))
|
||||
{
|
||||
var maxAllowed = baselineResult.ElapsedMs * (1 + thresholdPercent / 100);
|
||||
|
||||
if (elapsedMs > maxAllowed)
|
||||
{
|
||||
var regressionPct = ((double)(elapsedMs - baselineResult.ElapsedMs) / baselineResult.ElapsedMs) * 100;
|
||||
Assert.Fail(
|
||||
$"Performance regression detected for '{name}': " +
|
||||
$"{elapsedMs}ms exceeds threshold of {maxAllowed:F0}ms " +
|
||||
$"(baseline: {baselineResult.ElapsedMs}ms, regression: +{regressionPct:F1}%, threshold: {thresholdPercent}%)");
|
||||
}
|
||||
|
||||
TestContext.WriteLine($"[REGRESSION_CHECK] {name}: PASS ({elapsedMs}ms <= {maxAllowed:F0}ms, baseline: {baselineResult.ElapsedMs}ms)");
|
||||
}
|
||||
else
|
||||
{
|
||||
TestContext.WriteLine($"[REGRESSION_CHECK] {name}: SKIPPED (no baseline entry)");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Measures, records, and asserts no regression for the given action.
|
||||
/// </summary>
|
||||
protected long MeasureAndAssertNoRegression(string name, int itemCount, Action action, bool skipWarmup = false, double thresholdPercent = DefaultRegressionThreshold)
|
||||
{
|
||||
// Warmup iteration (skip for destructive operations)
|
||||
if (!skipWarmup)
|
||||
{
|
||||
try { action(); }
|
||||
catch { /* Warmup failure acceptable */ }
|
||||
}
|
||||
|
||||
var sw = Stopwatch.StartNew();
|
||||
action();
|
||||
sw.Stop();
|
||||
|
||||
AssertNoRegression(name, sw.ElapsedMilliseconds, itemCount, thresholdPercent);
|
||||
return sw.ElapsedMilliseconds;
|
||||
}
|
||||
|
||||
private Dictionary<string, BenchmarkResult> LoadBaseline()
|
||||
{
|
||||
if (!File.Exists(BaselinePath))
|
||||
{
|
||||
TestContext.WriteLine($"[BASELINE] File not found: {BaselinePath}");
|
||||
return new Dictionary<string, BenchmarkResult>();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var json = File.ReadAllText(BaselinePath);
|
||||
var results = JsonSerializer.Deserialize<List<BenchmarkResult>>(json) ?? new List<BenchmarkResult>();
|
||||
TestContext.WriteLine($"[BASELINE] Loaded {results.Count} baseline entries from {BaselinePath}");
|
||||
return results.ToDictionary(r => r.Name, r => r);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
TestContext.WriteLine($"[BASELINE] Failed to load baseline: {ex.Message}");
|
||||
return new Dictionary<string, BenchmarkResult>();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 5.2 Phase 1 CRUD Benchmarks to Gate
|
||||
|
||||
Update `ContentServiceRefactoringBenchmarks.cs` to use `AssertNoRegression` for these Phase 1 CRUD operations:
|
||||
|
||||
| Benchmark | Gate? | Baseline (ms) | Max Allowed (ms) |
|
||||
|-----------|-------|---------------|------------------|
|
||||
| `Save_SingleItem` | ✅ Yes | 7 | 8.4 |
|
||||
| `Save_BatchOf100` | ✅ Yes | 676 | 811.2 |
|
||||
| `Save_BatchOf1000` | ✅ Yes | 7649 | 9178.8 |
|
||||
| `GetById_Single` | ✅ Yes | 8 | 9.6 |
|
||||
| `GetByIds_BatchOf100` | ✅ Yes | 14 | 16.8 |
|
||||
| `Delete_SingleItem` | ✅ Yes | 35 | 42 |
|
||||
| `Delete_WithDescendants` | ✅ Yes | 243 | 291.6 |
|
||||
| `GetAncestors_DeepHierarchy` | ✅ Yes | 31 | 37.2 |
|
||||
| `GetPagedChildren_100Items` | ✅ Yes | 16 | 19.2 |
|
||||
| `GetPagedDescendants_DeepTree` | ✅ Yes | 25 | 30 |
|
||||
|
||||
**Non-gated (Phase 2+):** `Publish_*`, `Move_*`, `Copy_*`, `Sort_*`, `EmptyRecycleBin_*`, `Rollback_*`, `*Versions*`
|
||||
|
||||
### 5.3 Example Updated Benchmark Test
|
||||
|
||||
```csharp
|
||||
/// <summary>
|
||||
/// Benchmark 1: Single content save latency.
|
||||
/// </summary>
|
||||
[Test]
|
||||
[LongRunning]
|
||||
public void Benchmark_Save_SingleItem()
|
||||
{
|
||||
// Warmup with throwaway content
|
||||
var warmupContent = ContentBuilder.CreateSimpleContent(ContentType, "Warmup_SingleItem", -1);
|
||||
ContentService.Save(warmupContent);
|
||||
|
||||
// Measured run with fresh content
|
||||
var content = ContentBuilder.CreateSimpleContent(ContentType, "BenchmarkSingle", -1);
|
||||
var sw = Stopwatch.StartNew();
|
||||
ContentService.Save(content);
|
||||
sw.Stop();
|
||||
|
||||
// Gate: Fail if >20% regression from baseline
|
||||
AssertNoRegression("Save_SingleItem", sw.ElapsedMilliseconds, 1);
|
||||
|
||||
Assert.That(content.Id, Is.GreaterThan(0));
|
||||
}
|
||||
```
|
||||
|
||||
### 5.4 Baseline Update Process
|
||||
|
||||
When a phase completes and performance characteristics change intentionally:
|
||||
|
||||
```bash
|
||||
# 1. Run benchmarks and capture new results
|
||||
dotnet test tests/Umbraco.Tests.Integration \
|
||||
--filter "Category=Benchmark&FullyQualifiedName~ContentServiceRefactoringBenchmarks" \
|
||||
--logger "console;verbosity=detailed" \
|
||||
| tee benchmark-output.txt
|
||||
|
||||
# 2. Extract JSON from output
|
||||
grep -oP '\[BENCHMARK_JSON\]\K.*(?=\[/BENCHMARK_JSON\])' benchmark-output.txt \
|
||||
| python3 -m json.tool > docs/plans/baseline-phase1.json
|
||||
|
||||
# 3. Commit with phase tag
|
||||
git add docs/plans/baseline-phase1.json
|
||||
git commit -m "chore: update benchmark baseline for Phase 1"
|
||||
git tag phase-1-baseline
|
||||
```
|
||||
|
||||
### 5.5 Environment Variability Considerations
|
||||
|
||||
Benchmark thresholds account for environment variability:
|
||||
- **20% threshold** provides buffer for CI vs. local differences
|
||||
- **Warmup runs** reduce JIT compilation variance
|
||||
- **Database per test** ensures isolation
|
||||
- **Non-parallelizable** attribute prevents resource contention
|
||||
|
||||
If false positives occur in CI, consider:
|
||||
1. Increasing threshold to 30% for CI-only runs
|
||||
2. Using environment variable: `BENCHMARK_THRESHOLD=30`
|
||||
3. Running benchmarks on dedicated hardware
|
||||
|
||||
---
|
||||
|
||||
## 6. Final Recommendation
|
||||
|
||||
**Recommendation:** :warning: **Approve with Changes**
|
||||
|
||||
The plan is sound architecturally but has critical issues that must be fixed before implementation:
|
||||
|
||||
### Required Changes (Must Fix)
|
||||
|
||||
| Priority | Issue | Fix |
|
||||
|----------|-------|-----|
|
||||
| P0 | GetAncestors N+1 | Use batch query via Path parsing |
|
||||
| P0 | Incomplete interface parity | Audit and add missing methods (`HasChildren`, `Exists`) |
|
||||
| P0 | Filter ignored silently | Use repository query combination (pass base query + filter to `GetPage`) |
|
||||
| P0 | Benchmark regression enforcement | Implement `AssertNoRegression` in `ContentServiceBenchmarkBase` |
|
||||
| P1 | Delete loop race condition | Add iteration bound and empty-batch break |
|
||||
| P1 | Missing operation logging | Add cancellation/failure logging |
|
||||
|
||||
### Recommended Changes (Should Fix)
|
||||
|
||||
| Priority | Issue | Fix |
|
||||
|----------|-------|-----|
|
||||
| P2 | Code duplication in CreateAndSave | Extract to helper method |
|
||||
| P2 | Thin test coverage | Add behavioral unit tests |
|
||||
| P2 | Internal method documentation | Add precondition remarks |
|
||||
| P2 | Update CRUD benchmarks | Replace `RecordBenchmark` with `AssertNoRegression` for Phase 1 ops |
|
||||
|
||||
### Implementation Checklist
|
||||
|
||||
Before proceeding to implementation, ensure:
|
||||
|
||||
- [ ] `GetAncestors` uses `Path` parsing with batch `GetByIds`
|
||||
- [ ] `IContentCrudService` includes `HasChildren(int)`, `Exists(int)`, `Exists(Guid)`
|
||||
- [ ] `GetPagedChildren`/`GetPagedDescendants` pass both `query` and `filter` to repository
|
||||
- [ ] `ContentServiceBenchmarkBase` has `AssertNoRegression` method
|
||||
- [ ] 10 Phase 1 CRUD benchmarks use `AssertNoRegression` instead of `RecordBenchmark`
|
||||
- [ ] `DeleteLocked` has iteration bound and empty-batch exit
|
||||
- [ ] Save/Delete operations log cancellations
|
||||
|
||||
Once the P0 and P1 issues are addressed, the plan can proceed to implementation.
|
||||
|
||||
---
|
||||
|
||||
**Reviewed by:** Critical Implementation Review Skill
|
||||
**Review Date:** 2025-12-20
|
||||
@@ -0,0 +1,626 @@
|
||||
# Critical Implementation Review #3: Phase 1 ContentService CRUD Extraction
|
||||
|
||||
**Plan Version Reviewed:** 1.3 (2025-12-20)
|
||||
**Review Date:** 2025-12-20
|
||||
**Reviewer:** Claude (Senior Staff Engineer)
|
||||
**Plan File:** `docs/plans/2025-12-20-contentservice-refactor-phase1-implementation.md`
|
||||
|
||||
---
|
||||
|
||||
## 1. Overall Assessment
|
||||
|
||||
**Strengths:**
|
||||
- Well-structured TDD approach with clear task breakdown
|
||||
- Versioning strategy is thoughtfully documented
|
||||
- Previous critical review feedback (reviews 1 & 2) has been systematically addressed
|
||||
- N+1 query in `GetAncestors` correctly fixed with batch `Path` parsing
|
||||
- Benchmark regression enforcement adds meaningful quality gate (20% threshold)
|
||||
- Safety bounds on `DeleteLocked` iteration (10,000 max) prevent infinite loops
|
||||
- Comprehensive XML documentation with preconditions for internal methods
|
||||
|
||||
**Major Concerns:**
|
||||
- Synchronous wrapper over async code in `ContentServiceBase.Audit` can cause deadlocks
|
||||
- Multiple nested scope creations will degrade performance
|
||||
- Versioning policy describes default interface methods but implementation uses abstract base class
|
||||
- Thread-safety issue in benchmark baseline loading
|
||||
- Lock acquisition timing allows race conditions in `Save()` validation
|
||||
|
||||
**Verdict:** Plan is well-structured but requires targeted fixes before implementation.
|
||||
|
||||
---
|
||||
|
||||
## 2. Critical Issues (P0 — Must Fix Before Implementation)
|
||||
|
||||
### 2.1 Synchronous Async Wrapper — Potential Deadlock
|
||||
|
||||
**Location:** `ContentServiceBase.cs` lines 134-136
|
||||
|
||||
```csharp
|
||||
protected void Audit(...) =>
|
||||
AuditAsync(...).GetAwaiter().GetResult();
|
||||
```
|
||||
|
||||
**Why it matters:** `.GetAwaiter().GetResult()` blocks the calling thread waiting for an async operation. While ASP.NET Core doesn't use `SynchronizationContext` by default, this pattern:
|
||||
1. Blocks a thread pool thread unnecessarily, reducing throughput under load
|
||||
2. Breaks if someone configures a `SynchronizationContext`
|
||||
3. Sets a bad precedent in a base class that will be inherited by multiple services
|
||||
4. Can cause deadlocks in certain hosting scenarios (IIS in-process, custom middleware)
|
||||
|
||||
**Impact:** Application hangs under load; difficult to diagnose in production.
|
||||
|
||||
**Recommended Fix:** Provide synchronous audit path that doesn't require async:
|
||||
|
||||
```csharp
|
||||
/// <summary>
|
||||
/// Records an audit entry for a content operation (synchronous).
|
||||
/// </summary>
|
||||
protected void Audit(AuditType type, int userId, int objectId, string? message = null, string? parameters = null)
|
||||
{
|
||||
// Resolve user key synchronously - IUserIdKeyResolver should have sync overload
|
||||
// For now, use the async pattern with ConfigureAwait(false) to avoid context capture
|
||||
Guid userKey = UserIdKeyResolver.GetAsync(userId).ConfigureAwait(false).GetAwaiter().GetResult();
|
||||
|
||||
AuditService.Add(
|
||||
type,
|
||||
userKey,
|
||||
objectId,
|
||||
UmbracoObjectTypes.Document.GetName(),
|
||||
message,
|
||||
parameters);
|
||||
}
|
||||
```
|
||||
|
||||
**Alternative (Preferred Long-Term):** Add `IAuditService.Add()` synchronous overload and `IUserIdKeyResolver.Get(int userId)` synchronous overload. This avoids the async-over-sync anti-pattern entirely.
|
||||
|
||||
**Action Required:**
|
||||
- [ ] Check if `IAuditService` has synchronous `Add` method
|
||||
- [ ] Check if `IUserIdKeyResolver` has synchronous `Get` method
|
||||
- [ ] If not, use `ConfigureAwait(false)` pattern as shown above
|
||||
- [ ] Add `// TODO: Replace with sync overloads when available` comment
|
||||
|
||||
---
|
||||
|
||||
### 2.2 Nested Scope Creation — Performance Degradation
|
||||
|
||||
**Locations:**
|
||||
- `GetContentType()` creates its own scope (lines 1338-1345)
|
||||
- `GetLanguageDetailsForAuditEntry()` creates its own scope (lines 1347-1356)
|
||||
- `Create(int parentId, ...)` calls `GetById(parentId)` which creates scope, then continues without scope
|
||||
- `GetParent(int id)` calls `GetById(id)` then `GetById(content.ParentId)` — 2 scopes
|
||||
|
||||
**Why it matters:** Each `CreateCoreScope()` call:
|
||||
- Acquires a database connection from the pool
|
||||
- Creates a new transaction context
|
||||
- Has overhead for read/write lock acquisition
|
||||
- Adds latency (~0.5-2ms per scope depending on connection pool state)
|
||||
|
||||
**Impact:** A single `Save()` operation calling `GetLanguageDetailsForAuditEntry()` creates 2+ scopes. At baseline ~7ms per save, this overhead compounds:
|
||||
- 100 saves: +50-200ms overhead
|
||||
- 1000 saves: +500-2000ms overhead
|
||||
|
||||
**Recommended Fix:** Create `*Locked` or `*Internal` variants that assume caller holds scope:
|
||||
|
||||
```csharp
|
||||
// Public API - creates scope
|
||||
public IContentType GetContentType(string alias)
|
||||
{
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true))
|
||||
{
|
||||
scope.ReadLock(Constants.Locks.ContentTypes);
|
||||
return GetContentTypeLocked(alias);
|
||||
}
|
||||
}
|
||||
|
||||
// Internal - assumes caller holds scope with appropriate lock
|
||||
private IContentType GetContentTypeLocked(string alias)
|
||||
{
|
||||
return _contentTypeRepository.Get(alias)
|
||||
?? throw new ArgumentException($"No content type with alias '{alias}' exists.", nameof(alias));
|
||||
}
|
||||
|
||||
// In Save() - reuse the scope
|
||||
public OperationResult Save(IContent content, ...)
|
||||
{
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope())
|
||||
{
|
||||
scope.WriteLock(Constants.Locks.ContentTree);
|
||||
// ...
|
||||
if (culturesChanging != null)
|
||||
{
|
||||
// Use locked variant - no nested scope
|
||||
var langs = GetLanguageDetailsForAuditEntryLocked(culturesChanging);
|
||||
Audit(AuditType.SaveVariant, userId.Value, content.Id, $"Saved languages: {langs}", langs);
|
||||
}
|
||||
// ...
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Files to Update:**
|
||||
- [ ] `ContentCrudService.cs`: Add `GetContentTypeLocked()`, `GetLanguageDetailsForAuditEntryLocked()`
|
||||
- [ ] Update `Save()`, `CreateAndSaveInternal()` to use locked variants
|
||||
- [ ] Document preconditions in XML comments for locked methods
|
||||
|
||||
---
|
||||
|
||||
### 2.3 Interface Versioning Policy — Clarify Inheritance Requirement
|
||||
|
||||
**Location:** Versioning Strategy section (lines 28-70)
|
||||
|
||||
**Issue:** The plan states:
|
||||
> "When adding new methods to `IContentCrudService`, provide a default implementation in `ContentServiceBase`"
|
||||
|
||||
This conflates C# 8+ default interface methods with abstract base class implementations. The current design requires `ContentServiceBase` inheritance, which is the correct approach but needs explicit documentation.
|
||||
|
||||
**Resolution (Agreed):** Use Option B — Document that `ContentServiceBase` inheritance is required.
|
||||
|
||||
**Recommended Changes:**
|
||||
|
||||
1. **Update Versioning Strategy section** — Replace lines 46-55 with:
|
||||
|
||||
```markdown
|
||||
### Interface Extensibility Model
|
||||
|
||||
`IContentCrudService` is designed for **composition, not direct implementation**.
|
||||
|
||||
**Supported usage:**
|
||||
- Inject `IContentCrudService` as a dependency ✅
|
||||
- Extend `ContentCrudService` via inheritance ✅
|
||||
- Replace registration in DI with custom implementation inheriting `ContentServiceBase` ✅
|
||||
|
||||
**Unsupported usage:**
|
||||
- Implement `IContentCrudService` directly without inheriting `ContentServiceBase` ❌
|
||||
|
||||
**Rationale:** All CRUD operations require shared infrastructure (scoping, repositories,
|
||||
auditing). `ContentServiceBase` provides this infrastructure. Direct interface implementation
|
||||
would require re-implementing this infrastructure correctly, which is error-prone and
|
||||
creates maintenance burden.
|
||||
|
||||
**Adding New Methods (Umbraco internal process):**
|
||||
1. Add method signature to `IContentCrudService` interface
|
||||
2. Add virtual implementation to `ContentServiceBase` (if shareable) or `ContentCrudService`
|
||||
3. Existing subclasses automatically inherit the new implementation
|
||||
4. Mark with `[Since("X.Y")]` attribute if adding after initial release
|
||||
```
|
||||
|
||||
2. **Update IContentCrudService XML documentation** — Add implementation warning:
|
||||
|
||||
```csharp
|
||||
/// <summary>
|
||||
/// Service for content CRUD (Create, Read, Update, Delete) operations.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// <strong>Implementation Note:</strong> Do not implement this interface directly.
|
||||
/// Instead, inherit from <see cref="ContentServiceBase"/> which provides required
|
||||
/// infrastructure (scoping, repository access, auditing). Direct implementation
|
||||
/// without this base class will result in missing functionality.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// This interface is part of the ContentService refactoring initiative.
|
||||
/// It extracts core CRUD operations into a focused, testable service.
|
||||
/// </para>
|
||||
/// ...
|
||||
/// </remarks>
|
||||
public interface IContentCrudService : IService
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 2.4 Validation Before Lock — Race Condition Window
|
||||
|
||||
**Location:** `Save()` method lines 1077-1091
|
||||
|
||||
```csharp
|
||||
public OperationResult Save(IContent content, ...)
|
||||
{
|
||||
PublishedState publishedState = content.PublishedState;
|
||||
// Validation happens BEFORE lock acquisition
|
||||
if (publishedState != PublishedState.Published && publishedState != PublishedState.Unpublished)
|
||||
throw new InvalidOperationException(...);
|
||||
|
||||
if (content.Name != null && content.Name.Length > 255)
|
||||
throw new InvalidOperationException(...);
|
||||
|
||||
EventMessages eventMessages = EventMessagesFactory.Get();
|
||||
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope())
|
||||
{
|
||||
// Lock acquired AFTER validation
|
||||
scope.WriteLock(Constants.Locks.ContentTree);
|
||||
```
|
||||
|
||||
**Why it matters:** The content object's state could theoretically change between validation and lock acquisition if:
|
||||
- Another thread modifies the same `IContent` instance
|
||||
- The object is shared across async contexts
|
||||
|
||||
While unlikely in typical usage, this violates transactional consistency principles.
|
||||
|
||||
**Recommended Fix:** Move validation inside the locked section:
|
||||
|
||||
```csharp
|
||||
public OperationResult Save(IContent content, ...)
|
||||
{
|
||||
EventMessages eventMessages = EventMessagesFactory.Get();
|
||||
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope())
|
||||
{
|
||||
scope.WriteLock(Constants.Locks.ContentTree);
|
||||
|
||||
// Validate AFTER acquiring lock — content state is now stable
|
||||
PublishedState publishedState = content.PublishedState;
|
||||
if (publishedState != PublishedState.Published && publishedState != PublishedState.Unpublished)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"Cannot save (un)publishing content with name: {content.Name} - and state: {content.PublishedState}");
|
||||
}
|
||||
|
||||
if (content.Name != null && content.Name.Length > 255)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"Content with the name {content.Name} cannot be more than 255 characters in length.");
|
||||
}
|
||||
|
||||
// Continue with save...
|
||||
```
|
||||
|
||||
**Trade-off:** Lock is held slightly longer during validation. However, validation is O(1) string length check, so impact is negligible (~microseconds).
|
||||
|
||||
---
|
||||
|
||||
## 3. High Priority Issues (P1 — Should Fix)
|
||||
|
||||
### 3.1 Thread-Unsafe Baseline Loading in Benchmarks
|
||||
|
||||
**Location:** `ContentServiceBenchmarkBase.cs` lines 1688-1689
|
||||
|
||||
```csharp
|
||||
private Dictionary<string, BenchmarkResult>? _baseline;
|
||||
|
||||
protected void AssertNoRegression(...)
|
||||
{
|
||||
_baseline ??= LoadBaseline(); // Race condition if tests run in parallel
|
||||
```
|
||||
|
||||
**Why it matters:** NUnit can run tests in parallel (default behavior). Multiple threads checking `_baseline == null` simultaneously could:
|
||||
- Both see `null` and both call `LoadBaseline()`
|
||||
- Cause file I/O contention
|
||||
- Result in `JsonSerializer` errors if file is read concurrently
|
||||
- Produce inconsistent baseline state
|
||||
|
||||
**Recommended Fix:** Use `Lazy<T>` for thread-safe initialization:
|
||||
|
||||
```csharp
|
||||
private static readonly Lazy<Dictionary<string, BenchmarkResult>> _baselineLoader =
|
||||
new(() => LoadBaselineInternal(), LazyThreadSafetyMode.ExecutionAndPublication);
|
||||
|
||||
private static Dictionary<string, BenchmarkResult> Baseline => _baselineLoader.Value;
|
||||
|
||||
protected void AssertNoRegression(string name, long elapsedMs, int itemCount, double thresholdPercent = DefaultRegressionThreshold)
|
||||
{
|
||||
RecordBenchmark(name, elapsedMs, itemCount);
|
||||
|
||||
if (Baseline.TryGetValue(name, out var baselineResult))
|
||||
{
|
||||
// ... regression check logic
|
||||
}
|
||||
}
|
||||
|
||||
private static Dictionary<string, BenchmarkResult> LoadBaselineInternal()
|
||||
{
|
||||
// ... existing LoadBaseline logic, but static
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 3.2 Baseline Path Uses Relative Navigation — Brittle
|
||||
|
||||
**Location:** `ContentServiceBenchmarkBase.cs` lines 1670-1673
|
||||
|
||||
```csharp
|
||||
private static readonly string BaselinePath = Path.Combine(
|
||||
TestContext.CurrentContext.TestDirectory,
|
||||
"..", "..", "..", "..", "..",
|
||||
"docs", "plans", "baseline-phase0.json");
|
||||
```
|
||||
|
||||
**Why it matters:** `TestContext.CurrentContext.TestDirectory` varies by:
|
||||
- Test runner (Visual Studio, Rider, dotnet CLI, NCrunch)
|
||||
- Build configuration (Debug/Release)
|
||||
- CI/CD environment (GitHub Actions, Azure DevOps)
|
||||
|
||||
Five `..` navigations are fragile and will break when project structure changes.
|
||||
|
||||
**Recommended Fix:** Use repository root detection:
|
||||
|
||||
```csharp
|
||||
private static string FindRepositoryRoot()
|
||||
{
|
||||
var dir = new DirectoryInfo(TestContext.CurrentContext.TestDirectory);
|
||||
while (dir != null)
|
||||
{
|
||||
if (File.Exists(Path.Combine(dir.FullName, "umbraco.sln")))
|
||||
{
|
||||
return dir.FullName;
|
||||
}
|
||||
dir = dir.Parent;
|
||||
}
|
||||
throw new InvalidOperationException(
|
||||
$"Cannot find repository root (umbraco.sln) starting from {TestContext.CurrentContext.TestDirectory}");
|
||||
}
|
||||
|
||||
private static readonly Lazy<string> _repositoryRoot = new(FindRepositoryRoot);
|
||||
|
||||
private static string BaselinePath => Path.Combine(_repositoryRoot.Value, "docs", "plans", "baseline-phase0.json");
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 3.3 GetByIds Dictionary Key Collision Risk
|
||||
|
||||
**Location:** `ContentCrudService.cs` lines 909-910
|
||||
|
||||
```csharp
|
||||
var index = items.ToDictionary(x => x.Id, x => x);
|
||||
```
|
||||
|
||||
**Why it matters:** If `DocumentRepository.GetMany()` returns duplicates (due to repository bug, database inconsistency, or future ORM change), `.ToDictionary()` throws `ArgumentException: An item with the same key has already been added`.
|
||||
|
||||
**Impact:** Service method crashes with unhelpful exception instead of gracefully handling data inconsistency.
|
||||
|
||||
**Recommended Fix:** Use safe dictionary construction:
|
||||
|
||||
```csharp
|
||||
// Option 1: Take first occurrence (matches current behavior intent)
|
||||
var index = items.GroupBy(x => x.Id).ToDictionary(g => g.Key, g => g.First());
|
||||
|
||||
// Option 2: Use TryAdd pattern (more explicit)
|
||||
var index = new Dictionary<int, IContent>();
|
||||
foreach (var item in items)
|
||||
{
|
||||
index.TryAdd(item.Id, item); // Silently ignores duplicates
|
||||
}
|
||||
```
|
||||
|
||||
Apply same fix to `GetByIds(IEnumerable<Guid>)` (line 931).
|
||||
|
||||
---
|
||||
|
||||
### 3.4 Missing ContentSchedule Support in Batch Save
|
||||
|
||||
**Location:** `IContentCrudService.cs` lines 436-438
|
||||
|
||||
```csharp
|
||||
OperationResult Save(IEnumerable<IContent> contents, int userId = Constants.Security.SuperUserId);
|
||||
```
|
||||
|
||||
The batch `Save` doesn't accept `ContentScheduleCollection`, but the single-item `Save` does:
|
||||
|
||||
```csharp
|
||||
OperationResult Save(IContent content, int? userId = null, ContentScheduleCollection? contentSchedule = null);
|
||||
```
|
||||
|
||||
**Why it matters:** Users needing to save multiple items with individual schedules must:
|
||||
1. Make N individual `Save()` calls (defeats batching purpose)
|
||||
2. Or call batch `Save()` then separately persist schedules (inconsistent transaction)
|
||||
|
||||
**Recommended Fix (Documentation):** Add XML doc noting the limitation:
|
||||
|
||||
```csharp
|
||||
/// <summary>
|
||||
/// Saves multiple documents.
|
||||
/// </summary>
|
||||
/// <param name="contents">The documents to save.</param>
|
||||
/// <param name="userId">Optional id of the user saving the content.</param>
|
||||
/// <returns>The operation result.</returns>
|
||||
/// <remarks>
|
||||
/// This method does not support content schedules. To save content with schedules,
|
||||
/// use the single-item <see cref="Save(IContent, int?, ContentScheduleCollection?)"/> overload.
|
||||
/// </remarks>
|
||||
OperationResult Save(IEnumerable<IContent> contents, int userId = Constants.Security.SuperUserId);
|
||||
```
|
||||
|
||||
**Future Enhancement (Optional):** Consider adding:
|
||||
```csharp
|
||||
OperationResult Save(IEnumerable<(IContent Content, ContentScheduleCollection? Schedule)> items, int userId = ...);
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 4. Medium Priority Issues (P2 — Recommended)
|
||||
|
||||
### 4.1 Unit Test Mock Setup Repetition
|
||||
|
||||
**Location:** `ContentCrudServiceTests.cs` lines 570-579 (repeated 6+ times)
|
||||
|
||||
Each test repeats the same ~10-line `CreateCoreScope` mock setup.
|
||||
|
||||
**Recommendation:** Extract to helper:
|
||||
|
||||
```csharp
|
||||
private ICoreScope CreateMockScopeWithReadLock()
|
||||
{
|
||||
var scope = new Mock<ICoreScope>();
|
||||
scope.Setup(x => x.ReadLock(It.IsAny<int[]>()));
|
||||
_scopeProvider.Setup(x => x.CreateCoreScope(
|
||||
It.IsAny<IsolationLevel>(),
|
||||
It.IsAny<RepositoryCacheMode>(),
|
||||
It.IsAny<IEventDispatcher?>(),
|
||||
It.IsAny<IScopedNotificationPublisher?>(),
|
||||
It.IsAny<bool?>(),
|
||||
It.IsAny<bool>(),
|
||||
It.IsAny<bool>()))
|
||||
.Returns(scope.Object);
|
||||
return scope.Object;
|
||||
}
|
||||
|
||||
private ICoreScope CreateMockScopeWithWriteLock()
|
||||
{
|
||||
var scope = CreateMockScopeWithReadLock();
|
||||
Mock.Get(scope).Setup(x => x.WriteLock(It.IsAny<int[]>()));
|
||||
Mock.Get(scope).Setup(x => x.Notifications).Returns(Mock.Of<IScopedNotificationPublisher>());
|
||||
return scope;
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 4.2 Benchmark Threshold Should Be Configurable
|
||||
|
||||
**Location:** `ContentServiceBenchmarkBase.cs` line 1683
|
||||
|
||||
```csharp
|
||||
private const double DefaultRegressionThreshold = 20.0;
|
||||
```
|
||||
|
||||
**Recommendation:** Allow CI override via environment variable:
|
||||
|
||||
```csharp
|
||||
private static readonly double RegressionThreshold =
|
||||
double.TryParse(Environment.GetEnvironmentVariable("BENCHMARK_REGRESSION_THRESHOLD"), out var t)
|
||||
? t
|
||||
: 20.0;
|
||||
```
|
||||
|
||||
This allows tightening thresholds in CI while keeping development lenient.
|
||||
|
||||
---
|
||||
|
||||
### 4.3 Missing Test Category Attributes
|
||||
|
||||
**Location:** `ContentCrudServiceTests.cs`
|
||||
|
||||
The unit tests lack `[Category("UnitTest")]` attribute, making it harder to filter:
|
||||
|
||||
```bash
|
||||
# Can't easily run only unit tests
|
||||
dotnet test --filter "Category=UnitTest"
|
||||
```
|
||||
|
||||
**Recommendation:** Add category:
|
||||
|
||||
```csharp
|
||||
[TestFixture]
|
||||
[Category("UnitTest")]
|
||||
public class ContentCrudServiceTests
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 4.4 Summary Table File Count Mismatch
|
||||
|
||||
**Location:** Task 7 Summary (line 1916)
|
||||
|
||||
The table states "4 new files" but Task 2 creates `IContentCrudService.cs` as a 5th file.
|
||||
|
||||
**Files created:**
|
||||
1. `ContentServiceBase.cs`
|
||||
2. `ContentServiceConstants.cs`
|
||||
3. `IContentCrudService.cs`
|
||||
4. `ContentCrudService.cs`
|
||||
5. `ContentCrudServiceTests.cs`
|
||||
|
||||
**Fix:** Update summary to "5 new files".
|
||||
|
||||
---
|
||||
|
||||
### 4.5 GetAncestors Return Order Inconsistency
|
||||
|
||||
**Location:** `ContentCrudService.cs` lines 988-998
|
||||
|
||||
**Documentation says:**
|
||||
> Returns: The ancestor documents, from parent to root.
|
||||
|
||||
**Implementation does:**
|
||||
```csharp
|
||||
var ancestorIds = content.Path
|
||||
.Split(',')
|
||||
.Skip(1) // Skip root (-1)
|
||||
.Select(int.Parse)
|
||||
.Where(id => id != content.Id)
|
||||
.ToArray();
|
||||
|
||||
return GetByIds(ancestorIds); // Returns in path order: root -> parent
|
||||
```
|
||||
|
||||
Path format is `-1,123,456,789` where 123 is closest to root, 789 is the item.
|
||||
After `Skip(1)` and excluding self: `[123, 456]` — this is root-to-parent order.
|
||||
|
||||
**Recommendation:** Either:
|
||||
1. Fix documentation: "from root to parent"
|
||||
2. Or reverse the array: `ancestorIds.Reverse().ToArray()`
|
||||
|
||||
Check existing `ContentService.GetAncestors` behavior for consistency.
|
||||
|
||||
---
|
||||
|
||||
## 5. Questions for Clarification
|
||||
|
||||
| # | Question | Impact |
|
||||
|---|----------|--------|
|
||||
| 1 | Is there an async version of this interface planned? Many services in codebase have `*Async` variants. | Affects whether to add async methods now or later |
|
||||
| 2 | What should happen if `baseline-phase0.json` is missing in CI? Current: skip silently. Alternative: fail hard. | Affects CI reliability |
|
||||
| 3 | `GetPagedDescendantsLocked` is private but mentioned in interface method count (24 total). Should it be internal/protected? | Documentation accuracy |
|
||||
| 4 | Does `IUserIdKeyResolver` have a synchronous `Get` method, or only `GetAsync`? | Affects 2.1 fix approach |
|
||||
|
||||
---
|
||||
|
||||
## 6. Implementation Checklist Update
|
||||
|
||||
Add these items to the existing checklist in the plan:
|
||||
|
||||
```markdown
|
||||
### Critical Review 3 Changes Required
|
||||
|
||||
**P0 - Must Fix:**
|
||||
- [ ] Fix `Audit()` async wrapper (use `ConfigureAwait(false)` or sync overloads)
|
||||
- [ ] Add `*Locked` variants for `GetContentType`, `GetLanguageDetailsForAuditEntry`
|
||||
- [ ] Update Versioning Strategy to document `ContentServiceBase` inheritance requirement
|
||||
- [ ] Add implementation warning to `IContentCrudService` XML docs
|
||||
- [ ] Move `Save()` validation inside locked section
|
||||
|
||||
**P1 - Should Fix:**
|
||||
- [ ] Make baseline loading thread-safe with `Lazy<T>`
|
||||
- [ ] Use repository root detection for baseline path
|
||||
- [ ] Handle duplicate keys in `GetByIds` dictionary construction
|
||||
- [ ] Add XML doc to batch `Save` noting schedule limitation
|
||||
|
||||
**P2 - Recommended:**
|
||||
- [ ] Extract mock setup helpers in unit tests
|
||||
- [ ] Add `[Category("UnitTest")]` to test fixture
|
||||
- [ ] Update summary table to "5 new files"
|
||||
- [ ] Verify/fix `GetAncestors` return order documentation
|
||||
- [ ] Make regression threshold configurable via environment variable
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 7. Final Recommendation
|
||||
|
||||
**Approve with Changes**
|
||||
|
||||
The plan is well-structured and has comprehensively addressed feedback from reviews 1 and 2. The identified issues are targeted and fixable without architectural changes.
|
||||
|
||||
### Priority Summary
|
||||
|
||||
| Priority | Count | Effort Estimate |
|
||||
|----------|-------|-----------------|
|
||||
| P0 (Must Fix) | 4 | ~2-3 hours |
|
||||
| P1 (Should Fix) | 4 | ~1-2 hours |
|
||||
| P2 (Recommended) | 5 | ~30 min |
|
||||
|
||||
### Before Implementation:
|
||||
1. Apply all P0 fixes to the plan
|
||||
2. Apply P1 fixes (strongly recommended)
|
||||
3. P2 can be addressed during implementation
|
||||
|
||||
### Sign-off Criteria:
|
||||
- [ ] All P0 items resolved in plan v1.4
|
||||
- [ ] P1 items either resolved or documented as known limitations
|
||||
- [ ] Plan version incremented with "Critical Review 3 Changes Applied" section
|
||||
|
||||
---
|
||||
|
||||
**Review Complete:** 2025-12-20
|
||||
**Next Action:** Update plan to v1.4 with fixes, then proceed to implementation
|
||||
@@ -0,0 +1,558 @@
|
||||
# Critical Implementation Review: Phase 1 ContentService CRUD Extraction
|
||||
|
||||
**Plan Document:** `docs/plans/2025-12-20-contentservice-refactor-phase1-implementation.md`
|
||||
**Plan Version:** 1.4
|
||||
**Reviewer:** Claude (Senior Staff Engineer)
|
||||
**Review Date:** 2025-12-20
|
||||
**Review Type:** Detailed Implementation Review (Pre-Implementation Gate)
|
||||
|
||||
---
|
||||
|
||||
## 1. Overall Assessment
|
||||
|
||||
This is a well-structured plan that has incorporated feedback from three prior critical reviews. The versioning strategy, interface design, and test coverage are thorough. The TDD approach with explicit test-first steps is commendable.
|
||||
|
||||
### Strengths
|
||||
|
||||
- **Comprehensive versioning policy** with clear 2-major-version deprecation timeline
|
||||
- **N+1 query fix** for `GetAncestors` using batch fetch with path parsing
|
||||
- **Safety limits** on delete loop (10,000 iterations + empty-batch exit)
|
||||
- **Thread-safe baseline loading** with `Lazy<T>` and `LazyThreadSafetyMode.ExecutionAndPublication`
|
||||
- **Good precondition documentation** for internal `*Locked` methods
|
||||
- **Configurable regression threshold** via environment variable
|
||||
- **Correct lock ordering patterns** established in most methods
|
||||
|
||||
### Major Concerns
|
||||
|
||||
| Severity | Issue | Impact |
|
||||
|----------|-------|--------|
|
||||
| P0 | Nested scope creation in `CreateAndSaveInternal` → `Save()` | Transaction overhead, pattern violation |
|
||||
| P0 | Nested scope in `CreateAndSaveInternal` → `GetContentType()` | Conflicting locks possible |
|
||||
| P0 | `GetAncestors` path parsing with unhandled `FormatException` | Runtime crash on malformed data |
|
||||
| P1 | Lock acquisition timing inconsistency (single vs batch Save) | TOCTOU race in batch Save |
|
||||
|
||||
---
|
||||
|
||||
## 2. Critical Issues (P0 - Must Fix Before Implementation)
|
||||
|
||||
### 2.1 CreateAndSaveInternal Creates Nested Scopes via Save()
|
||||
|
||||
**Location:** Task 3, lines 849-875 (`CreateAndSaveInternal`) and lines 1085-1158 (`Save`)
|
||||
|
||||
**Problem:** `CreateAndSaveInternal` creates a scope at line 851, then calls `Save(content, userId)` at line 871. But `Save()` creates its **own scope** at line 1089. This results in nested scopes with double lock acquisition.
|
||||
|
||||
```csharp
|
||||
// CreateAndSaveInternal (line 851)
|
||||
private IContent CreateAndSaveInternal(...)
|
||||
{
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope()) // SCOPE 1
|
||||
{
|
||||
scope.WriteLock(Constants.Locks.ContentTree); // LOCK 1
|
||||
// ...
|
||||
Save(content, userId); // Calls Save() below
|
||||
scope.Complete();
|
||||
}
|
||||
}
|
||||
|
||||
// Save() (line 1089)
|
||||
public OperationResult Save(IContent content, int? userId = null, ...)
|
||||
{
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope()) // SCOPE 2 (nested!)
|
||||
{
|
||||
scope.WriteLock(Constants.Locks.ContentTree); // LOCK 2 (redundant!)
|
||||
// ...
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Why It Matters:**
|
||||
- Creates unnecessary nested transaction overhead
|
||||
- Double-locking `ContentTree` is wasteful (nested scopes inherit parent lock, but still incur overhead)
|
||||
- Violates the pattern established by `DeleteLocked` and `GetPagedDescendantsLocked` which specifically avoid nested scopes
|
||||
- Inconsistent with the plan's stated goal of fixing nested scope issues
|
||||
|
||||
**Recommended Fix:** Extract `SaveLocked()` private method that assumes caller holds scope:
|
||||
|
||||
```csharp
|
||||
/// <summary>
|
||||
/// Internal save implementation. Caller MUST hold scope with ContentTree write lock.
|
||||
/// </summary>
|
||||
private OperationResult SaveLocked(ICoreScope scope, IContent content, int userId,
|
||||
ContentScheduleCollection? contentSchedule, EventMessages eventMessages)
|
||||
{
|
||||
// Validation (already under lock)
|
||||
PublishedState publishedState = content.PublishedState;
|
||||
if (publishedState != PublishedState.Published && publishedState != PublishedState.Unpublished)
|
||||
{
|
||||
throw new InvalidOperationException(...);
|
||||
}
|
||||
// ... rest of save logic without scope creation ...
|
||||
}
|
||||
|
||||
public OperationResult Save(IContent content, int? userId = null, ...)
|
||||
{
|
||||
EventMessages eventMessages = EventMessagesFactory.Get();
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope())
|
||||
{
|
||||
scope.WriteLock(Constants.Locks.ContentTree);
|
||||
var result = SaveLocked(scope, content, userId ?? Constants.Security.SuperUserId,
|
||||
contentSchedule, eventMessages);
|
||||
scope.Complete();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
private IContent CreateAndSaveInternal(...)
|
||||
{
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope())
|
||||
{
|
||||
scope.WriteLock(Constants.Locks.ContentTree, Constants.Locks.ContentTypes);
|
||||
// ...
|
||||
SaveLocked(scope, content, userId, null, EventMessagesFactory.Get());
|
||||
scope.Complete();
|
||||
return content;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 2.2 GetContentType Creates Nested Scope When Called From CreateAndSaveInternal
|
||||
|
||||
**Location:** Task 3, line 862 (`CreateAndSaveInternal`) and lines 1355-1361 (`GetContentType`)
|
||||
|
||||
**Problem:** `CreateAndSaveInternal` already holds a scope (line 851), but calls `GetContentType()` at line 862, which creates **another scope** at line 1357 with a different lock.
|
||||
|
||||
```csharp
|
||||
// CreateAndSaveInternal (has scope with ContentTree write lock)
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope())
|
||||
{
|
||||
scope.WriteLock(Constants.Locks.ContentTree);
|
||||
// ...
|
||||
IContentType contentType = GetContentType(contentTypeAlias); // NESTED SCOPE!
|
||||
}
|
||||
|
||||
// GetContentType (line 1357)
|
||||
private IContentType GetContentType(string alias)
|
||||
{
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) // NESTED!
|
||||
{
|
||||
scope.ReadLock(Constants.Locks.ContentTypes); // Different lock!
|
||||
return GetContentTypeLocked(alias);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Why It Matters:**
|
||||
- Creates nested scopes which the plan explicitly set out to fix
|
||||
- Acquires `ContentTypes` read lock inside `ContentTree` write lock scope (potential lock ordering issues)
|
||||
- Inconsistent with `GetContentTypeLocked()` which exists but isn't used here
|
||||
|
||||
**Recommended Fix:** Acquire both locks upfront in `CreateAndSaveInternal` and use the `*Locked` variant:
|
||||
|
||||
```csharp
|
||||
private IContent CreateAndSaveInternal(...)
|
||||
{
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope())
|
||||
{
|
||||
// Acquire both locks at scope start
|
||||
scope.WriteLock(Constants.Locks.ContentTree);
|
||||
scope.ReadLock(Constants.Locks.ContentTypes);
|
||||
|
||||
if (parent?.Trashed == true)
|
||||
{
|
||||
throw new InvalidOperationException(...);
|
||||
}
|
||||
|
||||
// Use locked variant - no nested scope
|
||||
IContentType contentType = GetContentTypeLocked(contentTypeAlias);
|
||||
|
||||
Content content = parent is not null
|
||||
? new Content(name, parent, contentType, userId)
|
||||
: new Content(name, parentId, contentType, userId);
|
||||
|
||||
SaveLocked(scope, content, userId, null, EventMessagesFactory.Get());
|
||||
|
||||
scope.Complete();
|
||||
return content;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 2.3 GetAncestors Path Parsing Can Throw Unhandled FormatException
|
||||
|
||||
**Location:** Task 3, lines 996-1005
|
||||
|
||||
**Problem:** Path segments are parsed with `int.Parse()` without exception handling:
|
||||
|
||||
```csharp
|
||||
var ancestorIds = content.Path
|
||||
.Split(',')
|
||||
.Skip(1) // Skip root (-1)
|
||||
.Select(int.Parse) // CAN THROW FormatException!
|
||||
.Where(id => id != content.Id)
|
||||
.ToArray();
|
||||
```
|
||||
|
||||
**Why It Matters:**
|
||||
- If `Path` contains malformed data (e.g., `-1,abc,456` from data corruption or import), this throws an unhandled `FormatException`
|
||||
- Crashes the entire request with an opaque error
|
||||
- No logging to help diagnose the root cause
|
||||
- The existing ContentService doesn't have this code path (it uses iterative `GetParent`), so this is a new failure mode
|
||||
|
||||
**Recommended Fix - Option A (Defensive with TryParse):**
|
||||
|
||||
```csharp
|
||||
var ancestorIds = content.Path
|
||||
.Split(',')
|
||||
.Skip(1)
|
||||
.Select(s => int.TryParse(s, out var id) ? id : (int?)null)
|
||||
.Where(id => id.HasValue && id.Value != content.Id)
|
||||
.Select(id => id!.Value)
|
||||
.ToArray();
|
||||
|
||||
if (ancestorIds.Length == 0 && content.Level > 1)
|
||||
{
|
||||
_logger.LogWarning("Malformed path '{Path}' for content {ContentId} at level {Level}",
|
||||
content.Path, content.Id, content.Level);
|
||||
}
|
||||
```
|
||||
|
||||
**Recommended Fix - Option B (Fail-safe with logging):**
|
||||
|
||||
```csharp
|
||||
int[] ancestorIds;
|
||||
try
|
||||
{
|
||||
ancestorIds = content.Path
|
||||
.Split(',')
|
||||
.Skip(1)
|
||||
.Select(int.Parse)
|
||||
.Where(id => id != content.Id)
|
||||
.ToArray();
|
||||
}
|
||||
catch (FormatException ex)
|
||||
{
|
||||
_logger.LogError(ex, "Malformed path '{Path}' for content {ContentId}, returning empty ancestors",
|
||||
content.Path, content.Id);
|
||||
return Enumerable.Empty<IContent>();
|
||||
}
|
||||
```
|
||||
|
||||
Option A is preferred as it's more resilient and handles partial corruption gracefully.
|
||||
|
||||
---
|
||||
|
||||
## 3. High Priority Issues (P1 - Should Fix)
|
||||
|
||||
### 3.1 Lock Acquisition Timing Inconsistency Between Single and Batch Save
|
||||
|
||||
**Location:** Task 3, lines 1089-1114 (single Save) vs. lines 1166-1177 (batch Save)
|
||||
|
||||
**Problem:** The two Save overloads have inconsistent lock/notification ordering:
|
||||
|
||||
| Operation | Order |
|
||||
|-----------|-------|
|
||||
| Single Save | Scope → WriteLock → Validate → Notification → Repository |
|
||||
| Batch Save | Scope → Notification → WriteLock → Repository |
|
||||
|
||||
```csharp
|
||||
// Single Save (lines 1089-1114) - Lock BEFORE notification
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope())
|
||||
{
|
||||
scope.WriteLock(Constants.Locks.ContentTree); // LOCK FIRST
|
||||
|
||||
// Validate AFTER lock (content state is stable)
|
||||
PublishedState publishedState = content.PublishedState;
|
||||
if (publishedState != PublishedState.Published && ...)
|
||||
|
||||
var savingNotification = new ContentSavingNotification(...);
|
||||
if (scope.Notifications.PublishCancelable(savingNotification))
|
||||
// ...
|
||||
}
|
||||
|
||||
// Batch Save (lines 1166-1177) - Notification BEFORE lock
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope())
|
||||
{
|
||||
var savingNotification = new ContentSavingNotification(contentsA, eventMessages);
|
||||
if (scope.Notifications.PublishCancelable(savingNotification)) // NOTIFICATION FIRST
|
||||
{
|
||||
scope.Complete();
|
||||
return OperationResult.Cancel(eventMessages);
|
||||
}
|
||||
|
||||
scope.WriteLock(Constants.Locks.ContentTree); // LOCK SECOND
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
**Why It Matters:**
|
||||
- The plan explicitly states "Validate AFTER acquiring lock — content state is now stable" for single Save
|
||||
- But batch Save sends notification before lock, so handlers see potentially stale state
|
||||
- Creates TOCTOU race (content could change between notification and lock)
|
||||
- Inconsistent behavior is confusing for notification handlers
|
||||
|
||||
**Note:** Looking at the original ContentService, single Save also publishes notification before acquiring lock (lines 1107-1114 in original). The plan CHANGES single Save to lock-first. This is a behavioral change that should be documented.
|
||||
|
||||
**Recommended Fix:**
|
||||
1. If the plan intends to change lock timing for safety, apply consistently to both overloads
|
||||
2. Document this as a behavioral change in the summary section
|
||||
3. Or revert single Save to match original (notification before lock) for consistency
|
||||
|
||||
---
|
||||
|
||||
### 3.2 Unit Test Missing IsolationLevel Import
|
||||
|
||||
**Location:** Task 3, lines 601-609 (`CreateMockScopeWithReadLock` helper)
|
||||
|
||||
**Problem:** The helper method references `IsolationLevel` without a visible using statement:
|
||||
|
||||
```csharp
|
||||
_scopeProvider.Setup(x => x.CreateCoreScope(
|
||||
It.IsAny<IsolationLevel>(), // IsolationLevel needs import
|
||||
It.IsAny<RepositoryCacheMode>(),
|
||||
// ...
|
||||
```
|
||||
|
||||
**Why It Matters:** Build will fail without the correct import.
|
||||
|
||||
**Recommended Fix:** Add to test file imports:
|
||||
|
||||
```csharp
|
||||
using IsolationLevel = System.Data.IsolationLevel;
|
||||
```
|
||||
|
||||
Or use fully qualified name in the test.
|
||||
|
||||
---
|
||||
|
||||
### 3.3 Batch Save Missing Validation That Exists in Single Save
|
||||
|
||||
**Location:** Task 3, lines 1166-1204 (batch Save)
|
||||
|
||||
**Problem:** Single Save validates `PublishedState` and name length (lines 1094-1104), but batch Save doesn't perform these validations:
|
||||
|
||||
```csharp
|
||||
// Single Save has this validation:
|
||||
PublishedState publishedState = content.PublishedState;
|
||||
if (publishedState != PublishedState.Published && publishedState != PublishedState.Unpublished)
|
||||
{
|
||||
throw new InvalidOperationException(...);
|
||||
}
|
||||
|
||||
if (content.Name != null && content.Name.Length > 255)
|
||||
{
|
||||
throw new InvalidOperationException(...);
|
||||
}
|
||||
|
||||
// Batch Save SKIPS this validation entirely
|
||||
```
|
||||
|
||||
**Why It Matters:**
|
||||
- Allows saving content in invalid states via batch API
|
||||
- Name length constraint only enforced for single saves
|
||||
- Inconsistent validation behavior
|
||||
|
||||
**Note:** This matches the original ContentService behavior (batch Save also lacks validation). If maintaining parity, document this explicitly as a known limitation.
|
||||
|
||||
**Recommended Fix:** Either:
|
||||
1. Add validation loop in batch Save (with option to collect all errors before throwing)
|
||||
2. Document this as intentional parity with original behavior
|
||||
|
||||
---
|
||||
|
||||
## 4. Minor Issues & Improvements (P2)
|
||||
|
||||
### 4.1 GetByIds Nullable Handling Inconsistency
|
||||
|
||||
**Location:** Task 3, lines 902-917 (int overload) vs. lines 922-944 (Guid overload)
|
||||
|
||||
**Problem:** The Guid overload checks `if (items is not null)` at line 940, but the int overload doesn't:
|
||||
|
||||
```csharp
|
||||
// Int overload (no null check)
|
||||
IEnumerable<IContent> items = DocumentRepository.GetMany(idsA);
|
||||
var index = items.GroupBy(x => x.Id).ToDictionary(...);
|
||||
|
||||
// Guid overload (has null check)
|
||||
IEnumerable<IContent>? items = DocumentRepository.GetMany(idsA);
|
||||
if (items is not null)
|
||||
{
|
||||
var index = items.GroupBy(x => x.Key).ToDictionary(...);
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
**Recommended Fix:** Apply consistent null handling to both overloads. The int overload should also handle potential null from repository.
|
||||
|
||||
---
|
||||
|
||||
### 4.2 Interface Method Count Discrepancy in Summary
|
||||
|
||||
**Location:** Summary section, "Interface Methods (24 total)"
|
||||
|
||||
**Problem:** Summary claims 24 methods, but counting the interface definition in Task 2:
|
||||
- Create: 6 methods
|
||||
- Read: 7 methods (GetById×2, GetByIds×2, GetRootContent, GetParent×2)
|
||||
- Read Tree: 5 methods (GetAncestors×2, GetPagedChildren, GetPagedDescendants, HasChildren)
|
||||
- Exists: 2 methods
|
||||
- Save: 2 methods
|
||||
- Delete: 1 method
|
||||
|
||||
Total: **23 public interface methods**, not 24.
|
||||
|
||||
**Recommended Fix:** Update summary to accurate count.
|
||||
|
||||
---
|
||||
|
||||
### 4.3 Warmup Exception Silently Swallowed
|
||||
|
||||
**Location:** Task 6, lines 1806-1809
|
||||
|
||||
**Problem:** Warmup iteration swallows all exceptions with empty catch:
|
||||
|
||||
```csharp
|
||||
if (!skipWarmup)
|
||||
{
|
||||
try { action(); }
|
||||
catch { /* Warmup failure acceptable */ }
|
||||
}
|
||||
```
|
||||
|
||||
**Why It Matters:** Could hide setup issues that cause actual measurement to fail unexpectedly.
|
||||
|
||||
**Recommended Fix:** Log warmup failures at Debug level:
|
||||
|
||||
```csharp
|
||||
if (!skipWarmup)
|
||||
{
|
||||
try { action(); }
|
||||
catch (Exception ex)
|
||||
{
|
||||
TestContext.WriteLine($"[WARMUP] {name} warmup failed: {ex.Message}");
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 4.4 Benchmark Threshold Edge Case
|
||||
|
||||
**Location:** Task 6, threshold table and line 1787
|
||||
|
||||
**Problem:** The threshold comparison uses `>`:
|
||||
|
||||
```csharp
|
||||
if (elapsedMs > maxAllowed)
|
||||
```
|
||||
|
||||
For `Save_SingleItem` with baseline 7ms at 20% threshold, max allowed is exactly 8.4ms. If measurement is exactly 8.4ms, it passes. This is correct, but floating-point representation of 8.4 could cause unexpected boundary behavior.
|
||||
|
||||
**Recommended Fix:** Document that boundary is inclusive (`<=` max), or use integer math:
|
||||
|
||||
```csharp
|
||||
var maxAllowed = (long)Math.Ceiling(baselineResult.ElapsedMs * (1 + effectiveThreshold / 100));
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 4.5 Task 5 Step 3 Lazy Pattern Could Be Simplified
|
||||
|
||||
**Location:** Task 5, Step 3
|
||||
|
||||
**Problem:** The plan describes using `Lazy<IContentCrudService>` for obsolete constructors, but the primary constructor sets `_crudServiceLazy = null!`:
|
||||
|
||||
```csharp
|
||||
_crudService = crudService ?? throw new ArgumentNullException(nameof(crudService));
|
||||
_crudServiceLazy = null!; // Not used when directly injected
|
||||
```
|
||||
|
||||
This means `CrudService` property could throw NullReferenceException if incorrectly accessed:
|
||||
|
||||
```csharp
|
||||
private IContentCrudService CrudService => _crudService ?? _crudServiceLazy.Value;
|
||||
```
|
||||
|
||||
If `_crudService` is null AND `_crudServiceLazy` is null, this throws.
|
||||
|
||||
**Recommended Fix:** Use null-forgiving operator more carefully or use single field with union pattern:
|
||||
|
||||
```csharp
|
||||
private readonly Lazy<IContentCrudService> _crudServiceLazy;
|
||||
|
||||
// In primary constructor:
|
||||
_crudServiceLazy = new Lazy<IContentCrudService>(() => crudService);
|
||||
|
||||
// In obsolete constructors:
|
||||
_crudServiceLazy = new Lazy<IContentCrudService>(() =>
|
||||
StaticServiceProvider.Instance.GetRequiredService<IContentCrudService>());
|
||||
|
||||
// Property:
|
||||
private IContentCrudService CrudService => _crudServiceLazy.Value;
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 5. Questions for Clarification
|
||||
|
||||
1. **Nested Scope Intent:** Is `CreateAndSaveInternal` calling `Save()` (which creates its own scope) intentional, or should it use a `SaveLocked()` variant as recommended?
|
||||
|
||||
2. **Validation Timing Change:** The plan moves single-item Save validation inside the locked section (after `WriteLock`). The original ContentService validates before scope creation. Is this intentional behavioral change, and should it be documented?
|
||||
|
||||
3. **ContentSchedule Parity:** The plan documents that batch Save doesn't support content schedules. Does the original ContentService batch Save support schedules? If so, this needs to be called out as a behavioral difference.
|
||||
|
||||
4. **Lock Ordering Strategy:** When `CreateAndSaveInternal` needs both `ContentTree` (write) and `ContentTypes` (read) locks, should they be acquired in a specific order for deadlock prevention? The codebase should document lock ordering conventions.
|
||||
|
||||
---
|
||||
|
||||
## 6. Final Recommendation
|
||||
|
||||
### Verdict: **Major Revisions Needed**
|
||||
|
||||
The plan requires fixes for the three P0 issues before implementation can proceed safely.
|
||||
|
||||
### Required Changes Before Approval
|
||||
|
||||
| Priority | Issue | Recommended Fix |
|
||||
|----------|-------|-----------------|
|
||||
| **P0** | `CreateAndSaveInternal` → `Save()` nested scope | Extract `SaveLocked()` internal method |
|
||||
| **P0** | `CreateAndSaveInternal` → `GetContentType()` nested scope | Acquire both locks upfront, use `GetContentTypeLocked()` |
|
||||
| **P0** | `GetAncestors` `int.Parse` FormatException | Use `TryParse` with logging |
|
||||
| **P1** | Batch Save notification before lock (inconsistent) | Align with single Save or document difference |
|
||||
| **P1** | Missing `IsolationLevel` import | Add using statement |
|
||||
| **P1** | Batch Save missing validation | Document as intentional or add validation |
|
||||
| **P2** | GetByIds null handling inconsistency | Align both overloads |
|
||||
| **P2** | Method count in summary | Fix to 23 |
|
||||
| **P2** | Warmup exception logging | Add Debug-level logging |
|
||||
|
||||
### Positive Notes
|
||||
|
||||
The plan is fundamentally sound. The three prior reviews have significantly improved robustness:
|
||||
- Thread-safe baseline loading
|
||||
- Delete loop safety bounds
|
||||
- N+1 query elimination in GetAncestors
|
||||
- Comprehensive precondition documentation
|
||||
|
||||
After addressing the P0 issues (primarily around nested scope creation), this plan will be ready for implementation. The issues identified are localized and can be fixed with targeted changes to Tasks 3 and 5.
|
||||
|
||||
---
|
||||
|
||||
## 7. Appendix: Referenced Code Locations
|
||||
|
||||
| File | Lines | Description |
|
||||
|------|-------|-------------|
|
||||
| Plan Task 3 | 849-875 | `CreateAndSaveInternal` implementation |
|
||||
| Plan Task 3 | 1085-1158 | `Save(IContent)` implementation |
|
||||
| Plan Task 3 | 1166-1204 | `Save(IEnumerable<IContent>)` implementation |
|
||||
| Plan Task 3 | 996-1005 | `GetAncestors` path parsing |
|
||||
| Plan Task 3 | 1355-1361 | `GetContentType` with scope |
|
||||
| Plan Task 5 | 1543-1571 | Constructor with `Lazy<T>` pattern |
|
||||
| Plan Task 6 | 1770-1798 | `AssertNoRegression` implementation |
|
||||
| Original ContentService | 1088-1138 | Original `Save` implementation (for comparison) |
|
||||
| Original ContentService | 2322-2345 | Original `DeleteLocked` (for pattern reference) |
|
||||
|
||||
---
|
||||
|
||||
**Review Complete.** Awaiting plan revision for P0 issues before implementation approval.
|
||||
@@ -0,0 +1,445 @@
|
||||
# Critical Implementation Review #5: Phase 1 ContentService CRUD Extraction
|
||||
|
||||
**Plan**: `docs/plans/2025-12-20-contentservice-refactor-phase1-implementation.md` (v1.5)
|
||||
**Reviewer**: Claude (Critical Implementation Review)
|
||||
**Date**: 2025-12-20
|
||||
**Review Type**: Strict Code Review (Pre-Implementation)
|
||||
|
||||
---
|
||||
|
||||
## 1. Overall Assessment
|
||||
|
||||
### Strengths
|
||||
|
||||
- **Thorough iteration**: Plan v1.5 incorporates feedback from 4 prior critical reviews with detailed change tracking
|
||||
- **Well-documented versioning strategy**: Clear interface extensibility model and deprecation policy
|
||||
- **Proper nested scope elimination**: Extracted `SaveLocked`, `GetContentTypeLocked`, `GetPagedDescendantsLocked` to avoid nested scope creation
|
||||
- **Thread-safe patterns**: Lazy initialization with `LazyThreadSafetyMode.ExecutionAndPublication` for baseline loading and service resolution
|
||||
- **Comprehensive implementation checklist**: All 30+ items from prior reviews tracked with checkboxes
|
||||
- **TDD approach**: Unit tests defined before implementation code
|
||||
|
||||
### Major Concerns
|
||||
|
||||
1. **Critical lock ordering gap** when saving variant (multi-language) content
|
||||
2. **Inconsistent cancellation behavior** between single and batch Save operations
|
||||
3. **Underspecified constructor modifications** for obsolete ContentService constructors
|
||||
|
||||
---
|
||||
|
||||
## 2. Critical Issues (P0 - Must Fix Before Implementation)
|
||||
|
||||
### 2.1 Missing Languages Lock When Saving Variant Content
|
||||
|
||||
**Location**: Lines 1110-1124 (`Save(IContent)`) and lines 1142-1204 (`SaveLocked`)
|
||||
|
||||
**Description**:
|
||||
|
||||
The `SaveLocked` method calls `GetLanguageDetailsForAuditEntryLocked(culturesChanging)` at lines 1195-1196. This locked variant has a documented precondition:
|
||||
|
||||
> "Caller MUST hold an active scope with read/write lock on `Constants.Locks.Languages`."
|
||||
|
||||
However, neither `Save()` nor `CreateAndSaveInternal()` acquire this lock:
|
||||
|
||||
```csharp
|
||||
// Save() - line 1117 - only acquires ContentTree:
|
||||
scope.WriteLock(Constants.Locks.ContentTree);
|
||||
// Languages lock is NOT acquired
|
||||
|
||||
var result = SaveLocked(scope, content, ...); // Calls GetLanguageDetailsForAuditEntryLocked
|
||||
```
|
||||
|
||||
```csharp
|
||||
// CreateAndSaveInternal() - lines 861-862:
|
||||
scope.WriteLock(Constants.Locks.ContentTree);
|
||||
scope.ReadLock(Constants.Locks.ContentTypes);
|
||||
// Languages lock is NOT acquired
|
||||
|
||||
SaveLocked(scope, content, ...); // Calls GetLanguageDetailsForAuditEntryLocked
|
||||
```
|
||||
|
||||
**Impact**:
|
||||
|
||||
| Risk | Description |
|
||||
|------|-------------|
|
||||
| Data Consistency | `_languageRepository.GetMany()` called without lock protection in multi-threaded scenarios |
|
||||
| Deadlock Potential | Another operation holding Languages lock and waiting for ContentTree could deadlock |
|
||||
| Lock Hierarchy Violation | Breaks the documented lock ordering strategy |
|
||||
|
||||
**Affected Scenarios**: All saves of variant (multi-language) content where `culturesChanging != null`
|
||||
|
||||
**Actionable Fix**:
|
||||
|
||||
Option A (Recommended): Acquire Languages lock in all Save paths:
|
||||
|
||||
```csharp
|
||||
// In Save():
|
||||
scope.WriteLock(Constants.Locks.ContentTree);
|
||||
scope.ReadLock(Constants.Locks.Languages); // ADD THIS
|
||||
|
||||
// In CreateAndSaveInternal():
|
||||
scope.WriteLock(Constants.Locks.ContentTree);
|
||||
scope.ReadLock(Constants.Locks.ContentTypes);
|
||||
scope.ReadLock(Constants.Locks.Languages); // ADD THIS
|
||||
```
|
||||
|
||||
Option B (Alternative): Conditionally acquire lock only when needed:
|
||||
|
||||
```csharp
|
||||
// In SaveLocked, before accessing languages:
|
||||
if (culturesChanging != null)
|
||||
{
|
||||
scope.ReadLock(Constants.Locks.Languages);
|
||||
var langs = GetLanguageDetailsForAuditEntryLocked(culturesChanging);
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
**Recommendation**: Option A is safer and simpler. The overhead of acquiring an unused read lock is minimal compared to the complexity of conditional locking.
|
||||
|
||||
---
|
||||
|
||||
### 2.2 Batch Save Inconsistent scope.Complete() on Cancellation
|
||||
|
||||
**Location**: Lines 1231-1234 in batch `Save(IEnumerable<IContent>)`
|
||||
|
||||
**Description**:
|
||||
|
||||
When `ContentSavingNotification` is cancelled, batch Save calls `scope.Complete()`:
|
||||
|
||||
```csharp
|
||||
if (scope.Notifications.PublishCancelable(savingNotification))
|
||||
{
|
||||
_logger.LogInformation("Batch save operation cancelled...");
|
||||
scope.Complete(); // <-- INCONSISTENT
|
||||
return OperationResult.Cancel(eventMessages);
|
||||
}
|
||||
```
|
||||
|
||||
Comparison with other operations:
|
||||
|
||||
| Operation | On Cancel | Code Location |
|
||||
|-----------|-----------|---------------|
|
||||
| `Save(IContent)` single | No `scope.Complete()` | Lines 1160-1165 |
|
||||
| `Save(IEnumerable<IContent>)` batch | **Calls `scope.Complete()`** | Lines 1231-1234 |
|
||||
| `Delete(IContent)` | No `scope.Complete()` | Lines 1277-1280 |
|
||||
|
||||
**Impact**:
|
||||
|
||||
- Inconsistent behavior between single and batch operations
|
||||
- Semantically questionable: what transaction is being committed on cancellation?
|
||||
- Could commit partial work if any side effects occurred before notification
|
||||
|
||||
**Actionable Fix**:
|
||||
|
||||
Remove `scope.Complete()` from the cancellation path to match single-item Save behavior:
|
||||
|
||||
```csharp
|
||||
if (scope.Notifications.PublishCancelable(savingNotification))
|
||||
{
|
||||
_logger.LogInformation("Batch save operation cancelled for {ContentCount} content items by notification handler",
|
||||
contentsA.Length);
|
||||
return OperationResult.Cancel(eventMessages); // No scope.Complete()
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 3. High Priority Issues (P1 - Should Fix)
|
||||
|
||||
### 3.1 Task 5 Obsolete Constructor Modification Underspecified
|
||||
|
||||
**Location**: Task 5, Steps 1-3
|
||||
|
||||
**Description**:
|
||||
|
||||
The plan describes using `Lazy<IContentCrudService>` for obsolete constructors but doesn't show complete constructor modifications. The existing ContentService has two obsolete constructors (lines 91-169) that chain to the primary constructor via `: this(...)`.
|
||||
|
||||
**Current pattern (simplified)**:
|
||||
```csharp
|
||||
[Obsolete("...")]
|
||||
public ContentService(/* old params */)
|
||||
: this(/* chain to primary constructor */)
|
||||
{
|
||||
}
|
||||
```
|
||||
|
||||
**Unclear aspects**:
|
||||
1. How does chaining work when primary constructor now requires `IContentCrudService`?
|
||||
2. Do both obsolete constructors need identical treatment?
|
||||
3. What is the complete body of modified obsolete constructors?
|
||||
|
||||
**Actionable Fix**:
|
||||
|
||||
Provide complete obsolete constructor specification. The obsolete constructors should NOT chain to the new primary constructor. Instead, they should have their own full body:
|
||||
|
||||
```csharp
|
||||
[Obsolete("Use the non-obsolete constructor instead. Scheduled removal in v19.")]
|
||||
public ContentService(
|
||||
ICoreScopeProvider provider,
|
||||
ILoggerFactory loggerFactory,
|
||||
IEventMessagesFactory eventMessagesFactory,
|
||||
IDocumentRepository documentRepository,
|
||||
IEntityRepository entityRepository,
|
||||
IAuditRepository auditRepository, // Old parameter
|
||||
IContentTypeRepository contentTypeRepository,
|
||||
IDocumentBlueprintRepository documentBlueprintRepository,
|
||||
ILanguageRepository languageRepository,
|
||||
Lazy<IPropertyValidationService> propertyValidationService,
|
||||
IShortStringHelper shortStringHelper,
|
||||
ICultureImpactFactory cultureImpactFactory,
|
||||
IUserIdKeyResolver userIdKeyResolver,
|
||||
PropertyEditorCollection propertyEditorCollection,
|
||||
IIdKeyMap idKeyMap,
|
||||
IOptionsMonitor<ContentSettings> optionsMonitor,
|
||||
IRelationService relationService)
|
||||
: base(provider, loggerFactory, eventMessagesFactory)
|
||||
{
|
||||
// All existing field assignments...
|
||||
_documentRepository = documentRepository;
|
||||
_entityRepository = entityRepository;
|
||||
// ... etc ...
|
||||
|
||||
// NEW: Lazy resolution of IContentCrudService
|
||||
_crudServiceLazy = new Lazy<IContentCrudService>(() =>
|
||||
StaticServiceProvider.Instance.GetRequiredService<IContentCrudService>(),
|
||||
LazyThreadSafetyMode.ExecutionAndPublication);
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 3.2 Unit Tests Missing Variant Culture Save Path Coverage
|
||||
|
||||
**Location**: Task 3, Step 1 (`ContentCrudServiceTests.cs`)
|
||||
|
||||
**Description**:
|
||||
|
||||
The unit tests cover basic scenarios but don't exercise the variant culture path in `SaveLocked` (lines 1175-1197), which:
|
||||
1. Checks `content.ContentType.VariesByCulture()`
|
||||
2. Accesses `content.CultureInfos`
|
||||
3. Calls `GetLanguageDetailsForAuditEntryLocked()`
|
||||
|
||||
This is the exact code path affected by the critical lock bug (2.1).
|
||||
|
||||
**Actionable Fix**:
|
||||
|
||||
Add a unit test for variant content saving:
|
||||
|
||||
```csharp
|
||||
[Test]
|
||||
public void Save_WithVariantContent_CallsLanguageRepository()
|
||||
{
|
||||
// Arrange
|
||||
var scope = CreateMockScopeWithWriteLock();
|
||||
|
||||
var contentType = new Mock<IContentType>();
|
||||
contentType.Setup(x => x.VariesByCulture()).Returns(true);
|
||||
|
||||
var cultureInfo = new Mock<IContentCultureInfo>();
|
||||
cultureInfo.Setup(x => x.IsDirty()).Returns(true);
|
||||
cultureInfo.Setup(x => x.Culture).Returns("en-US");
|
||||
|
||||
var cultureInfos = new Mock<IDictionary<string, IContentCultureInfo>>();
|
||||
cultureInfos.Setup(x => x.Values).Returns(new[] { cultureInfo.Object });
|
||||
|
||||
var content = new Mock<IContent>();
|
||||
content.Setup(x => x.ContentType).Returns(contentType.Object);
|
||||
content.Setup(x => x.CultureInfos).Returns(cultureInfos.Object);
|
||||
content.Setup(x => x.HasIdentity).Returns(true);
|
||||
content.Setup(x => x.PublishedState).Returns(PublishedState.Unpublished);
|
||||
content.Setup(x => x.Name).Returns("Test");
|
||||
|
||||
_languageRepository.Setup(x => x.GetMany()).Returns(new List<ILanguage>());
|
||||
|
||||
// Act
|
||||
var result = _sut.Save(content.Object);
|
||||
|
||||
// Assert
|
||||
Assert.That(result.Success, Is.True);
|
||||
_languageRepository.Verify(x => x.GetMany(), Times.Once);
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 4. Medium Priority Issues (P2 - Recommended)
|
||||
|
||||
### 4.1 Missing Using Statements in Code Samples
|
||||
|
||||
**Location**: Task 3, ContentCrudService.cs code block
|
||||
|
||||
**Description**:
|
||||
|
||||
The code uses types requiring imports not shown in the using block:
|
||||
- `TextColumnType` requires `Umbraco.Cms.Core.Persistence.Querying`
|
||||
- `Direction` requires `Umbraco.Cms.Core.Persistence.Querying`
|
||||
- `Ordering` requires `Umbraco.Cms.Core.Persistence.Querying`
|
||||
|
||||
**Actionable Fix**:
|
||||
|
||||
Add to the using statements at the top of ContentCrudService.cs:
|
||||
|
||||
```csharp
|
||||
using Umbraco.Cms.Core.Persistence.Querying;
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 4.2 RecordBenchmark vs AssertNoRegression Clarification
|
||||
|
||||
**Location**: Task 6, Step 2
|
||||
|
||||
**Description**:
|
||||
|
||||
The plan adds `AssertNoRegression` which internally calls `RecordBenchmark`. The example shows calling `AssertNoRegression` only, which is correct. However, the instruction text could be clearer that benchmarks should REPLACE `RecordBenchmark` calls with `AssertNoRegression`, not add both.
|
||||
|
||||
**Actionable Fix**:
|
||||
|
||||
Update Step 2 text to:
|
||||
|
||||
> "**Replace** `RecordBenchmark(...)` calls with `AssertNoRegression(...)` calls in the following 10 Phase 1 CRUD benchmarks. The `AssertNoRegression` method internally records the benchmark AND asserts no regression."
|
||||
|
||||
---
|
||||
|
||||
### 4.3 GetAncestors Warning Log Could Be Noisy
|
||||
|
||||
**Location**: Lines 1024-1029
|
||||
|
||||
**Description**:
|
||||
|
||||
`GetAncestors` logs a warning when `ancestorIds.Length == 0 && content.Level > 1`:
|
||||
|
||||
```csharp
|
||||
_logger.LogWarning(
|
||||
"Malformed path '{Path}' for content {ContentId} at level {Level} - expected ancestors but found none",
|
||||
content.Path, content.Id, content.Level);
|
||||
```
|
||||
|
||||
This warning could be noisy in edge cases or during data migration.
|
||||
|
||||
**Actionable Fix**:
|
||||
|
||||
Consider changing to `LogDebug` or adding expected count for clarity:
|
||||
|
||||
```csharp
|
||||
_logger.LogWarning(
|
||||
"Malformed path '{Path}' for content {ContentId} at level {Level} - expected {ExpectedCount} ancestors but parsed {ActualCount}",
|
||||
content.Path, content.Id, content.Level, content.Level - 1, ancestorIds.Length);
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 4.4 Benchmark CI Failure Mode Consideration
|
||||
|
||||
**Location**: Task 6, `AssertNoRegression` implementation
|
||||
|
||||
**Description**:
|
||||
|
||||
If the baseline file doesn't exist, `AssertNoRegression` logs and skips the regression check. In CI environments, this could mask regressions if the baseline file is missing.
|
||||
|
||||
**Actionable Fix (Optional)**:
|
||||
|
||||
Add optional strict mode via environment variable:
|
||||
|
||||
```csharp
|
||||
private static readonly bool RequireBaseline =
|
||||
bool.TryParse(Environment.GetEnvironmentVariable("BENCHMARK_REQUIRE_BASELINE"), out var b) && b;
|
||||
|
||||
protected void AssertNoRegression(...)
|
||||
{
|
||||
RecordBenchmark(name, elapsedMs, itemCount);
|
||||
|
||||
if (Baseline.TryGetValue(name, out var baselineResult))
|
||||
{
|
||||
// ... existing regression check ...
|
||||
}
|
||||
else if (RequireBaseline)
|
||||
{
|
||||
Assert.Fail($"No baseline entry found for '{name}' and BENCHMARK_REQUIRE_BASELINE=true");
|
||||
}
|
||||
else
|
||||
{
|
||||
TestContext.WriteLine($"[REGRESSION_CHECK] {name}: SKIPPED (no baseline entry)");
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 5. Questions for Clarification
|
||||
|
||||
### Q1: Lock Ordering Strategy for Languages Lock
|
||||
|
||||
When fixing issue 2.1, should the Languages lock be acquired:
|
||||
- **Always** in `Save()` and `CreateAndSaveInternal()` (simpler, minor overhead for invariant content), or
|
||||
- **Conditionally** only when `content.ContentType.VariesByCulture()` returns true (more complex, avoids unnecessary locks)?
|
||||
|
||||
**Recommendation**: Always acquire. The read lock overhead is minimal.
|
||||
|
||||
### Q2: Obsolete Constructor Strategy
|
||||
|
||||
For the obsolete constructors:
|
||||
- Should they stop chaining to the primary constructor and have their own full body?
|
||||
- Or should an intermediate constructor be added that accepts optional `IContentCrudService`?
|
||||
|
||||
**Recommendation**: Full body approach (as shown in fix 3.1) is cleaner and avoids parameter default complexity.
|
||||
|
||||
### Q3: Baseline Required in CI
|
||||
|
||||
Should the CI pipeline require baseline file presence? If so, add the `BENCHMARK_REQUIRE_BASELINE` environment variable check suggested in 4.4.
|
||||
|
||||
---
|
||||
|
||||
## 6. Implementation Checklist Additions
|
||||
|
||||
Add to the existing checklist:
|
||||
|
||||
### From Critical Review 5
|
||||
|
||||
- [ ] `Save()` acquires `Constants.Locks.Languages` read lock
|
||||
- [ ] `CreateAndSaveInternal()` acquires `Constants.Locks.Languages` read lock
|
||||
- [ ] Batch `Save()` does NOT call `scope.Complete()` on cancellation
|
||||
- [ ] Obsolete constructors have complete body specification (not chained)
|
||||
- [ ] Unit test added for variant culture save path
|
||||
- [ ] `using Umbraco.Cms.Core.Persistence.Querying;` added to ContentCrudService.cs
|
||||
- [ ] Task 6 Step 2 clarifies "replace" not "add" AssertNoRegression
|
||||
|
||||
---
|
||||
|
||||
## 7. Final Recommendation
|
||||
|
||||
| Verdict | **Major Revisions Needed** |
|
||||
|---------|----------------------------|
|
||||
|
||||
The plan is comprehensive and well-structured after 4 prior reviews, but the **missing Languages lock** (Issue 2.1) is a correctness bug that will affect all multi-language content saves. This must be fixed before implementation.
|
||||
|
||||
### Required Changes (Blocking)
|
||||
|
||||
| Priority | Issue | Action |
|
||||
|----------|-------|--------|
|
||||
| P0 | 2.1 Missing Languages Lock | Acquire `scope.ReadLock(Constants.Locks.Languages)` in `Save()` and `CreateAndSaveInternal()` |
|
||||
| P0 | 2.2 Inconsistent scope.Complete() | Remove `scope.Complete()` from batch Save cancellation path |
|
||||
| P1 | 3.1 Constructor Underspecified | Add complete obsolete constructor body to Task 5 |
|
||||
|
||||
### Recommended Changes (Non-Blocking)
|
||||
|
||||
| Priority | Issue | Action |
|
||||
|----------|-------|--------|
|
||||
| P1 | 3.2 Missing Test Coverage | Add unit test for variant culture save |
|
||||
| P2 | 4.1 Using Statements | Add missing using to code sample |
|
||||
| P2 | 4.2 Task 6 Clarification | Clarify "replace" RecordBenchmark |
|
||||
|
||||
---
|
||||
|
||||
## 8. Summary
|
||||
|
||||
**Plan Version**: 1.5
|
||||
**Critical Issues Found**: 2
|
||||
**High Priority Issues Found**: 2
|
||||
**Medium Priority Issues Found**: 4
|
||||
|
||||
After addressing the critical lock ordering issue and scope.Complete() inconsistency, the plan will be production-ready. The prior 4 reviews have successfully caught and fixed the majority of implementation concerns—this review identified edge cases in the variant content save path that were not fully covered.
|
||||
|
||||
---
|
||||
|
||||
*Review completed: 2025-12-20*
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,461 @@
|
||||
# Critical Implementation Review #6: Phase 1 ContentService CRUD Extraction
|
||||
|
||||
**Document:** `docs/plans/2025-12-20-contentservice-refactor-phase1-implementation.md` (v1.6)
|
||||
**Reviewer:** Claude (Opus 4.5)
|
||||
**Date:** 2025-12-21
|
||||
**Review Type:** Strict Tactical Implementation Review
|
||||
|
||||
---
|
||||
|
||||
## 1. Overall Assessment
|
||||
|
||||
### Strengths
|
||||
|
||||
- **Well-structured plan** with clear task decomposition, version history, and 5-iteration review cycle
|
||||
- **Comprehensive issue resolution** - previous reviews addressed N+1 queries, lock ordering, scope management, and thread safety
|
||||
- **Strong documentation** of preconditions for internal methods (`SaveLocked`, `DeleteLocked`, `GetPagedDescendantsLocked`)
|
||||
- **Baseline-enforced regression testing** with configurable thresholds and CI-friendly environment variables
|
||||
- **Production-ready versioning policy** with 2-major-version deprecation periods and additive-only interface changes
|
||||
- **Consistent lock acquisition patterns** for most operations (ContentTree, ContentTypes, Languages)
|
||||
|
||||
### Major Concerns
|
||||
|
||||
1. **Delete operation has inconsistent `scope.Complete()` behavior** on cancellation compared to batch Save
|
||||
2. **Sync-over-async pattern in `Audit()`** still poses deadlock/thread exhaustion risk despite `ConfigureAwait(false)`
|
||||
3. **`StaticServiceProvider` usage** for obsolete constructors introduces untestable code paths (explicitly discouraged in codebase)
|
||||
4. **Delete acquires lock AFTER notification** - creates race window (differs from Save's lock-first pattern)
|
||||
|
||||
---
|
||||
|
||||
## 2. Critical Issues (P0)
|
||||
|
||||
### 2.1 Delete Cancellation Calls `scope.Complete()` - Inconsistent with Save
|
||||
|
||||
**Location:** Task 3, Delete method (lines 1308-1342 in plan)
|
||||
|
||||
**Code in question:**
|
||||
```csharp
|
||||
// Delete method (lines 1313-1319):
|
||||
if (scope.Notifications.PublishCancelable(new ContentDeletingNotification(content, eventMessages)))
|
||||
{
|
||||
scope.Complete(); // <-- Calls Complete on cancel
|
||||
return OperationResult.Cancel(eventMessages);
|
||||
}
|
||||
```
|
||||
|
||||
**Contrast with batch Save (lines 1268-1273):**
|
||||
```csharp
|
||||
if (scope.Notifications.PublishCancelable(savingNotification))
|
||||
{
|
||||
return OperationResult.Cancel(eventMessages); // No scope.Complete() - fixed in review 5
|
||||
}
|
||||
```
|
||||
|
||||
**Verification:** The original `ContentService.Delete` at line 2296-2297 does call `scope.Complete()` on cancel, so this maintains behavioral parity. However, this creates internal inconsistency within `ContentCrudService`.
|
||||
|
||||
**Impact:**
|
||||
- Inconsistent transaction behavior between operations
|
||||
- Potential confusion for developers maintaining the code
|
||||
- Scope.Complete() on cancel could theoretically commit partial state (though unlikely in cancel path)
|
||||
|
||||
**Recommendation:**
|
||||
```csharp
|
||||
// Option A: Document the inconsistency (preserves parity)
|
||||
if (scope.Notifications.PublishCancelable(new ContentDeletingNotification(content, eventMessages)))
|
||||
{
|
||||
// NOTE: scope.Complete() called on cancel for behavioral parity with original ContentService.Delete.
|
||||
// This differs from Save operations which do NOT complete scope on cancel.
|
||||
// See: src/Umbraco.Core/Services/ContentService.cs line 2296
|
||||
scope.Complete();
|
||||
return OperationResult.Cancel(eventMessages);
|
||||
}
|
||||
|
||||
// Option B: Align with Save (breaking change from original)
|
||||
if (scope.Notifications.PublishCancelable(new ContentDeletingNotification(content, eventMessages)))
|
||||
{
|
||||
_logger.LogInformation("Delete operation cancelled for content {ContentId} ({ContentName}) by notification handler",
|
||||
content.Id, content.Name);
|
||||
return OperationResult.Cancel(eventMessages); // No scope.Complete()
|
||||
}
|
||||
```
|
||||
|
||||
**Required action:** Choose Option A or B and update plan accordingly.
|
||||
|
||||
---
|
||||
|
||||
### 2.2 Sync-over-Async Deadlock Risk in `Audit()` Method
|
||||
|
||||
**Location:** Task 1, ContentServiceBase.cs (lines 151-163 in plan)
|
||||
|
||||
**Code in question:**
|
||||
```csharp
|
||||
protected void Audit(AuditType type, int userId, int objectId, string? message = null, string? parameters = null)
|
||||
{
|
||||
// Use ConfigureAwait(false) to avoid context capture and potential deadlocks
|
||||
Guid userKey = UserIdKeyResolver.GetAsync(userId).ConfigureAwait(false).GetAwaiter().GetResult();
|
||||
|
||||
AuditService.AddAsync(
|
||||
type,
|
||||
userKey,
|
||||
objectId,
|
||||
UmbracoObjectTypes.Document.GetName(),
|
||||
message,
|
||||
parameters).ConfigureAwait(false).GetAwaiter().GetResult();
|
||||
}
|
||||
```
|
||||
|
||||
**Impact:**
|
||||
- **Thread pool exhaustion:** Each sync call blocks a thread waiting for async completion
|
||||
- **Potential deadlocks:** If underlying async operations have sync dependencies or limited concurrency resources
|
||||
- **Performance degradation:** Under high load, blocked threads accumulate
|
||||
- The TODO comment (line 149-150) acknowledges this but provides no timeline or mitigation
|
||||
|
||||
**Recommendation:**
|
||||
|
||||
1. Add obsolete warning to sync method:
|
||||
```csharp
|
||||
/// <summary>
|
||||
/// Records an audit entry for a content operation (synchronous).
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para><strong>Warning:</strong> This method uses sync-over-async pattern which can cause
|
||||
/// thread pool exhaustion under high load. Prefer <see cref="AuditAsync"/> for new code.</para>
|
||||
/// <para>TODO: Replace with sync overloads when IAuditService.Add and IUserIdKeyResolver.Get are available.</para>
|
||||
/// </remarks>
|
||||
[Obsolete("Prefer AuditAsync for new code. Sync wrapper may cause thread pool exhaustion under high load.")]
|
||||
protected void Audit(AuditType type, int userId, int objectId, string? message = null, string? parameters = null)
|
||||
```
|
||||
|
||||
2. Track sync `Audit()` callers for future migration to `AuditAsync()`
|
||||
|
||||
**Required action:** Add `[Obsolete]` attribute with warning message.
|
||||
|
||||
---
|
||||
|
||||
### 2.3 StaticServiceProvider Makes Obsolete Constructors Untestable
|
||||
|
||||
**Location:** Task 5, obsolete constructor specification (lines 1803-1807 in plan)
|
||||
|
||||
**Code in question:**
|
||||
```csharp
|
||||
// NEW: Lazy resolution of IContentCrudService
|
||||
_crudServiceLazy = new Lazy<IContentCrudService>(() =>
|
||||
StaticServiceProvider.Instance.GetRequiredService<IContentCrudService>(),
|
||||
LazyThreadSafetyMode.ExecutionAndPublication);
|
||||
```
|
||||
|
||||
**StaticServiceProvider documentation (verified in codebase):**
|
||||
```csharp
|
||||
/// <remarks>
|
||||
/// Keep in mind, every time this is used, the code becomes basically untestable.
|
||||
/// </remarks>
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public static class StaticServiceProvider
|
||||
```
|
||||
|
||||
**Impact:**
|
||||
- Unit tests cannot mock `IContentCrudService` when using obsolete constructors
|
||||
- Migration scenarios from old constructor to new constructor are untestable at unit level
|
||||
- Goes against the codebase's own documented guidance
|
||||
|
||||
**Recommendation:**
|
||||
|
||||
1. Add XML documentation warning:
|
||||
```csharp
|
||||
/// <remarks>
|
||||
/// <para><strong>Testing limitation:</strong> This constructor uses StaticServiceProvider for
|
||||
/// IContentCrudService resolution, making it untestable at unit level. Integration tests
|
||||
/// should verify CRUD delegation when using this constructor.</para>
|
||||
/// </remarks>
|
||||
[Obsolete("Use the non-obsolete constructor instead. Scheduled removal in v19.")]
|
||||
public ContentService(...)
|
||||
```
|
||||
|
||||
2. Add integration test verifying obsolete constructor behavior:
|
||||
```csharp
|
||||
/// <summary>
|
||||
/// Verifies obsolete constructor correctly delegates to IContentCrudService via StaticServiceProvider.
|
||||
/// Required because obsolete constructor is not unit-testable due to StaticServiceProvider usage.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void ObsoleteConstructor_DelegatesToContentCrudService()
|
||||
{
|
||||
// Integration test using actual DI container
|
||||
var contentService = GetRequiredService<IContentService>();
|
||||
var content = contentService.Create("Test", -1, ContentType.Alias);
|
||||
|
||||
Assert.That(content, Is.Not.Null);
|
||||
Assert.That(content.Name, Is.EqualTo("Test"));
|
||||
}
|
||||
```
|
||||
|
||||
**Required action:** Add documentation warning and integration test.
|
||||
|
||||
---
|
||||
|
||||
### 2.4 Delete Acquires Lock AFTER Notification - Race Window
|
||||
|
||||
**Location:** Task 3, Delete method (lines 1308-1322 in plan)
|
||||
|
||||
**Code in question:**
|
||||
```csharp
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope())
|
||||
{
|
||||
// Notification sent BEFORE lock acquired
|
||||
if (scope.Notifications.PublishCancelable(new ContentDeletingNotification(content, eventMessages)))
|
||||
{
|
||||
scope.Complete();
|
||||
return OperationResult.Cancel(eventMessages);
|
||||
}
|
||||
|
||||
// Lock acquired AFTER notification
|
||||
scope.WriteLock(Constants.Locks.ContentTree);
|
||||
|
||||
// ... deletion proceeds
|
||||
}
|
||||
```
|
||||
|
||||
**Contrast with Save (post-review 4):**
|
||||
```csharp
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope())
|
||||
{
|
||||
// Lock acquired BEFORE notification
|
||||
scope.WriteLock(Constants.Locks.ContentTree);
|
||||
scope.ReadLock(Constants.Locks.Languages);
|
||||
|
||||
// Notification sent AFTER lock acquired
|
||||
if (scope.Notifications.PublishCancelable(savingNotification))
|
||||
{
|
||||
return OperationResult.Cancel(eventMessages);
|
||||
}
|
||||
```
|
||||
|
||||
**Verification:** Original `ContentService.Delete` (line 2294-2300) follows the same pattern - notification before lock. This maintains behavioral parity.
|
||||
|
||||
**Impact:**
|
||||
- Race window between notification and lock: content could be modified/deleted by another thread
|
||||
- Notification handlers see potentially stale content state
|
||||
- Inconsistent pattern with Save operations (though matches original Delete)
|
||||
|
||||
**Recommendation:** Document this as intentional for parity:
|
||||
```csharp
|
||||
public OperationResult Delete(IContent content, int userId = Constants.Security.SuperUserId)
|
||||
{
|
||||
EventMessages eventMessages = EventMessagesFactory.Get();
|
||||
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope())
|
||||
{
|
||||
// NOTE: Notification sent BEFORE lock for behavioral parity with original ContentService.Delete.
|
||||
// This differs from Save operations which acquire lock first.
|
||||
// Race window exists between notification and lock - accepted for backward compatibility.
|
||||
// See: src/Umbraco.Core/Services/ContentService.cs line 2294
|
||||
if (scope.Notifications.PublishCancelable(new ContentDeletingNotification(content, eventMessages)))
|
||||
```
|
||||
|
||||
**Required action:** Add comment documenting intentional parity.
|
||||
|
||||
---
|
||||
|
||||
## 3. High Priority Issues (P1)
|
||||
|
||||
### 3.1 Missing `RequireBaseline` CI Documentation
|
||||
|
||||
**Location:** Task 6, benchmark enforcement
|
||||
|
||||
**Problem:** `BENCHMARK_REQUIRE_BASELINE` environment variable is implemented (line 1893) but not documented in CI setup instructions. Benchmarks will silently skip regression checks if baseline file is missing.
|
||||
|
||||
**Recommendation:** Add to Task 6 Step 5 commit message:
|
||||
```
|
||||
CI Configuration:
|
||||
- Set BENCHMARK_REQUIRE_BASELINE=true in CI to fail on missing baselines
|
||||
- Set BENCHMARK_REGRESSION_THRESHOLD=20 (default) or custom percentage
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 3.2 GetAncestors Warning Log False Positive Edge Case
|
||||
|
||||
**Location:** Task 3, GetAncestors (lines 1062-1067 in plan)
|
||||
|
||||
**Code in question:**
|
||||
```csharp
|
||||
// Log warning if path appears malformed (expected ancestors but found none)
|
||||
if (ancestorIds.Length == 0 && content.Level > 1)
|
||||
{
|
||||
_logger.LogWarning(
|
||||
"Malformed path '{Path}' for content {ContentId} at level {Level} - expected {ExpectedCount} ancestors but parsed {ActualCount}",
|
||||
content.Path, content.Id, content.Level, content.Level - 1, ancestorIds.Length);
|
||||
}
|
||||
```
|
||||
|
||||
**Problem:** Edge case at Level 2 with path "-1,{selfId}" - content directly under root has 0 ancestors (root is skipped), but Level 2 implies 1 expected ancestor. Warning would incorrectly fire.
|
||||
|
||||
**Recommendation:** Adjust expected count calculation:
|
||||
```csharp
|
||||
// Expected ancestors = Level - 1 (levels above) - 1 (root is skipped in parsing)
|
||||
var expectedAncestorCount = content.Level - 2; // Level 2 expects 0, Level 3 expects 1, etc.
|
||||
if (ancestorIds.Length < expectedAncestorCount && expectedAncestorCount > 0)
|
||||
{
|
||||
_logger.LogWarning(
|
||||
"Malformed path '{Path}' for content {ContentId} at level {Level} - expected {ExpectedCount} ancestors but parsed {ActualCount}",
|
||||
content.Path, content.Id, content.Level, expectedAncestorCount, ancestorIds.Length);
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 3.3 Unit Test Mock May Not Exercise Intended Code Path
|
||||
|
||||
**Location:** Task 3, unit test `Save_WithVariantContent_CallsLanguageRepository` (lines 718-751)
|
||||
|
||||
**Concern:** The test mocks `_languageRepository.GetMany()` to return empty list, but the verification asserts it's called `Times.Once`. Need to verify the test data setup actually triggers the variant save path.
|
||||
|
||||
**Recommendation:** Add explicit assertion that variant path was taken:
|
||||
```csharp
|
||||
// Verify we actually entered the variant code path
|
||||
Assert.That(content.Object.ContentType.VariesByCulture(), Is.True,
|
||||
"Test setup error: ContentType should vary by culture");
|
||||
Assert.That(cultureInfoDict.Object.Values.Any(x => x.IsDirty()), Is.True,
|
||||
"Test setup error: Should have dirty culture infos");
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 4. Medium Priority Issues (P2)
|
||||
|
||||
### 4.1 Benchmark Threshold Too Tight for Low-Millisecond Operations
|
||||
|
||||
**Location:** Task 6, threshold table
|
||||
|
||||
**Problem:** 20% threshold on 7ms baseline allows only 1.4ms variance (8.4ms max). System timing jitter can easily exceed this.
|
||||
|
||||
**Current thresholds:**
|
||||
| Benchmark | Baseline | 20% Max | Variance Allowed |
|
||||
|-----------|----------|---------|------------------|
|
||||
| `Save_SingleItem` | 7ms | 8.4ms | 1.4ms |
|
||||
| `GetById_Single` | 8ms | 9.6ms | 1.6ms |
|
||||
|
||||
**Recommendation:** Consider two-tier threshold or absolute floor:
|
||||
```csharp
|
||||
protected void AssertNoRegression(string name, long elapsedMs, int itemCount, double thresholdPercent = -1)
|
||||
{
|
||||
var effectiveThreshold = thresholdPercent < 0 ? RegressionThreshold : thresholdPercent;
|
||||
|
||||
if (Baseline.TryGetValue(name, out var baselineResult))
|
||||
{
|
||||
// Two-tier: For fast operations, allow at least 5ms absolute variance
|
||||
var absoluteFloor = 5.0;
|
||||
var percentageAllowance = baselineResult.ElapsedMs * (effectiveThreshold / 100);
|
||||
var maxAllowed = baselineResult.ElapsedMs + Math.Max(absoluteFloor, percentageAllowance);
|
||||
// ...
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 4.2 Missing `[Category("Benchmark")]` Attribute in Plan
|
||||
|
||||
**Location:** Task 6, benchmark test examples
|
||||
|
||||
**Problem:** Plan shows `[LongRunning]` attribute but filter commands use `Category=Benchmark`. Need to ensure consistency.
|
||||
|
||||
**Recommendation:** Verify benchmark tests have both attributes:
|
||||
```csharp
|
||||
[Test]
|
||||
[Category("Benchmark")]
|
||||
[LongRunning]
|
||||
public void Benchmark_Save_SingleItem()
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 4.3 Plan Summary Method Count Minor Discrepancy
|
||||
|
||||
**Location:** Summary section (line 2166-2171)
|
||||
|
||||
**Current:** Lists "23 public" methods with breakdown totaling 23.
|
||||
|
||||
**Actual count from interface (lines 286-491):**
|
||||
- Create: 6 methods
|
||||
- Read: 7 methods (GetById x2, GetByIds x2, GetRootContent, GetParent x2)
|
||||
- Read Tree: 7 methods (GetAncestors x2, GetPagedChildren, GetPagedDescendants, HasChildren, Exists x2)
|
||||
- Save: 2 methods
|
||||
- Delete: 1 method
|
||||
- **Total: 23 methods**
|
||||
|
||||
**Status:** Count is correct. No action needed.
|
||||
|
||||
---
|
||||
|
||||
## 5. Questions for Clarification
|
||||
|
||||
| # | Question | Impact | Context |
|
||||
|---|----------|--------|---------|
|
||||
| 1 | Should Delete's `scope.Complete()` on cancellation be preserved (parity) or removed (consistency with Save)? | P0 | Issue 2.1 |
|
||||
| 2 | What's the timeline for sync `IAuditService.Add` / `IUserIdKeyResolver.Get` to eliminate sync-over-async? | P0 | Issue 2.2 |
|
||||
| 3 | Are existing `ContentService` integration tests sufficient to cover `ContentCrudService` via delegation? | P1 | Test coverage |
|
||||
| 4 | Should Delete lock timing be changed to lock-first (like Save) or kept for parity? | P0 | Issue 2.4 |
|
||||
|
||||
---
|
||||
|
||||
## 6. Implementation Checklist Additions
|
||||
|
||||
Add to existing checklist in plan:
|
||||
|
||||
### From Critical Review 6 (Required)
|
||||
|
||||
- [ ] Issue 2.1: Document or fix Delete's `scope.Complete()` on cancellation
|
||||
- [ ] Issue 2.2: Add `[Obsolete]` to sync `Audit()` method with deadlock warning
|
||||
- [ ] Issue 2.3: Add XML docs warning about obsolete constructor untestability
|
||||
- [ ] Issue 2.3: Add integration test for obsolete constructor CRUD delegation
|
||||
- [ ] Issue 2.4: Add comment documenting Delete lock timing is intentional for parity
|
||||
|
||||
### From Critical Review 6 (Recommended)
|
||||
|
||||
- [ ] Issue 3.1: Document `BENCHMARK_REQUIRE_BASELINE` in CI setup
|
||||
- [ ] Issue 3.2: Fix GetAncestors expected ancestor count calculation
|
||||
- [ ] Issue 3.3: Add setup validation assertions to variant content unit test
|
||||
- [ ] Issue 4.1: Consider absolute threshold floor for fast benchmarks
|
||||
- [ ] Issue 4.2: Verify `[Category("Benchmark")]` on all benchmark tests
|
||||
|
||||
---
|
||||
|
||||
## 7. Final Recommendation
|
||||
|
||||
### Approve with Changes
|
||||
|
||||
The plan has undergone thorough review and is well-structured. The remaining issues are addressable:
|
||||
|
||||
**Required before implementation (P0):**
|
||||
1. Document Delete's `scope.Complete()` behavior (issue 2.1) - choose parity or consistency
|
||||
2. Add `[Obsolete]` warning to sync `Audit()` method (issue 2.2)
|
||||
3. Document obsolete constructor untestability and add integration test (issue 2.3)
|
||||
4. Document Delete lock timing rationale (issue 2.4)
|
||||
|
||||
**Strongly recommended (P1):**
|
||||
5. Document `BENCHMARK_REQUIRE_BASELINE` for CI (issue 3.1)
|
||||
6. Fix GetAncestors warning log edge case (issue 3.2)
|
||||
|
||||
**Optional improvements (P2):**
|
||||
7. Consider absolute threshold floor for fast benchmarks (issue 4.1)
|
||||
|
||||
---
|
||||
|
||||
## Appendix: Verification Commands Used
|
||||
|
||||
```bash
|
||||
# Verified StaticServiceProvider exists and is documented as untestable
|
||||
grep -r "StaticServiceProvider" src/Umbraco.Core/
|
||||
|
||||
# Verified original ContentService.Delete behavior
|
||||
grep -A 30 "OperationResult Delete" src/Umbraco.Core/Services/ContentService.cs
|
||||
|
||||
# Verified baseline file exists and has expected structure
|
||||
cat docs/plans/baseline-phase0.json
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
**Review Status:** Complete
|
||||
**Next Step:** Address P0 issues and update plan to v1.7, then proceed to implementation
|
||||
200
docs/plans/baseline-phase0.json
Normal file
200
docs/plans/baseline-phase0.json
Normal file
@@ -0,0 +1,200 @@
|
||||
[
|
||||
{
|
||||
"Name": "BaselineComparison",
|
||||
"ElapsedMs": 1357,
|
||||
"ItemCount": 10,
|
||||
"MsPerItem": 135.7
|
||||
},
|
||||
{
|
||||
"Name": "Copy_Recursive_100Items",
|
||||
"ElapsedMs": 2809,
|
||||
"ItemCount": 101,
|
||||
"MsPerItem": 27.81188118811881
|
||||
},
|
||||
{
|
||||
"Name": "Copy_SingleItem",
|
||||
"ElapsedMs": 30,
|
||||
"ItemCount": 1,
|
||||
"MsPerItem": 30
|
||||
},
|
||||
{
|
||||
"Name": "Count_ByContentType",
|
||||
"ElapsedMs": 1,
|
||||
"ItemCount": 1000,
|
||||
"MsPerItem": 0.001
|
||||
},
|
||||
{
|
||||
"Name": "CountDescendants_LargeTree",
|
||||
"ElapsedMs": 1,
|
||||
"ItemCount": 1000,
|
||||
"MsPerItem": 0.001
|
||||
},
|
||||
{
|
||||
"Name": "Delete_SingleItem",
|
||||
"ElapsedMs": 35,
|
||||
"ItemCount": 1,
|
||||
"MsPerItem": 35
|
||||
},
|
||||
{
|
||||
"Name": "Delete_WithDescendants",
|
||||
"ElapsedMs": 243,
|
||||
"ItemCount": 101,
|
||||
"MsPerItem": 2.405940594059406
|
||||
},
|
||||
{
|
||||
"Name": "DeleteVersions_ByDate",
|
||||
"ElapsedMs": 178,
|
||||
"ItemCount": 100,
|
||||
"MsPerItem": 1.78
|
||||
},
|
||||
{
|
||||
"Name": "EmptyRecycleBin_100Items",
|
||||
"ElapsedMs": 847,
|
||||
"ItemCount": 100,
|
||||
"MsPerItem": 8.47
|
||||
},
|
||||
{
|
||||
"Name": "GetAncestors_DeepHierarchy",
|
||||
"ElapsedMs": 31,
|
||||
"ItemCount": 10,
|
||||
"MsPerItem": 3.1
|
||||
},
|
||||
{
|
||||
"Name": "GetById_Single",
|
||||
"ElapsedMs": 8,
|
||||
"ItemCount": 1,
|
||||
"MsPerItem": 8
|
||||
},
|
||||
{
|
||||
"Name": "GetByIds_BatchOf100",
|
||||
"ElapsedMs": 14,
|
||||
"ItemCount": 100,
|
||||
"MsPerItem": 0.14
|
||||
},
|
||||
{
|
||||
"Name": "GetContentSchedulesByIds_100Items",
|
||||
"ElapsedMs": 1,
|
||||
"ItemCount": 100,
|
||||
"MsPerItem": 0.01
|
||||
},
|
||||
{
|
||||
"Name": "GetPagedChildren_100Items",
|
||||
"ElapsedMs": 16,
|
||||
"ItemCount": 100,
|
||||
"MsPerItem": 0.16
|
||||
},
|
||||
{
|
||||
"Name": "GetPagedDescendants_DeepTree",
|
||||
"ElapsedMs": 25,
|
||||
"ItemCount": 300,
|
||||
"MsPerItem": 0.08333333333333333
|
||||
},
|
||||
{
|
||||
"Name": "GetVersions_ItemWith100Versions",
|
||||
"ElapsedMs": 19,
|
||||
"ItemCount": 100,
|
||||
"MsPerItem": 0.19
|
||||
},
|
||||
{
|
||||
"Name": "GetVersionsSlim_Paged",
|
||||
"ElapsedMs": 8,
|
||||
"ItemCount": 10,
|
||||
"MsPerItem": 0.8
|
||||
},
|
||||
{
|
||||
"Name": "HasChildren_100Nodes",
|
||||
"ElapsedMs": 65,
|
||||
"ItemCount": 100,
|
||||
"MsPerItem": 0.65
|
||||
},
|
||||
{
|
||||
"Name": "Move_SingleItem",
|
||||
"ElapsedMs": 22,
|
||||
"ItemCount": 1,
|
||||
"MsPerItem": 22
|
||||
},
|
||||
{
|
||||
"Name": "Move_WithDescendants",
|
||||
"ElapsedMs": 592,
|
||||
"ItemCount": 101,
|
||||
"MsPerItem": 5.861386138613861
|
||||
},
|
||||
{
|
||||
"Name": "MoveToRecycleBin_LargeTree",
|
||||
"ElapsedMs": 8955,
|
||||
"ItemCount": 1001,
|
||||
"MsPerItem": 8.946053946053945
|
||||
},
|
||||
{
|
||||
"Name": "MoveToRecycleBin_Published",
|
||||
"ElapsedMs": 34,
|
||||
"ItemCount": 1,
|
||||
"MsPerItem": 34
|
||||
},
|
||||
{
|
||||
"Name": "PerformScheduledPublish",
|
||||
"ElapsedMs": 2526,
|
||||
"ItemCount": 100,
|
||||
"MsPerItem": 25.26
|
||||
},
|
||||
{
|
||||
"Name": "Publish_BatchOf100",
|
||||
"ElapsedMs": 2456,
|
||||
"ItemCount": 100,
|
||||
"MsPerItem": 24.56
|
||||
},
|
||||
{
|
||||
"Name": "Publish_SingleItem",
|
||||
"ElapsedMs": 21,
|
||||
"ItemCount": 1,
|
||||
"MsPerItem": 21
|
||||
},
|
||||
{
|
||||
"Name": "PublishBranch_DeepTree",
|
||||
"ElapsedMs": 51,
|
||||
"ItemCount": 101,
|
||||
"MsPerItem": 0.504950495049505
|
||||
},
|
||||
{
|
||||
"Name": "PublishBranch_ShallowTree",
|
||||
"ElapsedMs": 50,
|
||||
"ItemCount": 101,
|
||||
"MsPerItem": 0.49504950495049505
|
||||
},
|
||||
{
|
||||
"Name": "Rollback_ToVersion",
|
||||
"ElapsedMs": 33,
|
||||
"ItemCount": 1,
|
||||
"MsPerItem": 33
|
||||
},
|
||||
{
|
||||
"Name": "Save_BatchOf100",
|
||||
"ElapsedMs": 676,
|
||||
"ItemCount": 100,
|
||||
"MsPerItem": 6.76
|
||||
},
|
||||
{
|
||||
"Name": "Save_BatchOf1000",
|
||||
"ElapsedMs": 7649,
|
||||
"ItemCount": 1000,
|
||||
"MsPerItem": 7.649
|
||||
},
|
||||
{
|
||||
"Name": "Save_SingleItem",
|
||||
"ElapsedMs": 7,
|
||||
"ItemCount": 1,
|
||||
"MsPerItem": 7
|
||||
},
|
||||
{
|
||||
"Name": "Sort_100Children",
|
||||
"ElapsedMs": 758,
|
||||
"ItemCount": 100,
|
||||
"MsPerItem": 7.58
|
||||
},
|
||||
{
|
||||
"Name": "Unpublish_SingleItem",
|
||||
"ElapsedMs": 23,
|
||||
"ItemCount": 1,
|
||||
"MsPerItem": 23
|
||||
}
|
||||
]
|
||||
@@ -46,6 +46,7 @@ using Umbraco.Cms.Core.Services.ImportExport;
|
||||
using Umbraco.Cms.Core.Services.Navigation;
|
||||
using Umbraco.Cms.Core.Services.Querying;
|
||||
using Umbraco.Cms.Core.Services.Querying.RecycleBin;
|
||||
using Umbraco.Cms.Core.Strings;
|
||||
using Umbraco.Cms.Core.Sync;
|
||||
using Umbraco.Cms.Core.Telemetry;
|
||||
using Umbraco.Cms.Core.Templates;
|
||||
@@ -297,7 +298,29 @@ namespace Umbraco.Cms.Core.DependencyInjection
|
||||
Services.AddUnique<ITagService, TagService>();
|
||||
Services.AddUnique<IContentPermissionService, ContentPermissionService>();
|
||||
Services.AddUnique<IDictionaryPermissionService, DictionaryPermissionService>();
|
||||
Services.AddUnique<IContentService, ContentService>();
|
||||
Services.AddUnique<IContentCrudService, ContentCrudService>();
|
||||
Services.AddUnique<IContentQueryOperationService, ContentQueryOperationService>();
|
||||
Services.AddUnique<IContentService>(sp =>
|
||||
new ContentService(
|
||||
sp.GetRequiredService<ICoreScopeProvider>(),
|
||||
sp.GetRequiredService<ILoggerFactory>(),
|
||||
sp.GetRequiredService<IEventMessagesFactory>(),
|
||||
sp.GetRequiredService<IDocumentRepository>(),
|
||||
sp.GetRequiredService<IEntityRepository>(),
|
||||
sp.GetRequiredService<IAuditService>(),
|
||||
sp.GetRequiredService<IContentTypeRepository>(),
|
||||
sp.GetRequiredService<IDocumentBlueprintRepository>(),
|
||||
sp.GetRequiredService<ILanguageRepository>(),
|
||||
sp.GetRequiredService<Lazy<IPropertyValidationService>>(),
|
||||
sp.GetRequiredService<IShortStringHelper>(),
|
||||
sp.GetRequiredService<ICultureImpactFactory>(),
|
||||
sp.GetRequiredService<IUserIdKeyResolver>(),
|
||||
sp.GetRequiredService<PropertyEditorCollection>(),
|
||||
sp.GetRequiredService<IIdKeyMap>(),
|
||||
sp.GetRequiredService<IOptionsMonitor<ContentSettings>>(),
|
||||
sp.GetRequiredService<IRelationService>(),
|
||||
sp.GetRequiredService<IContentCrudService>(),
|
||||
sp.GetRequiredService<IContentQueryOperationService>()));
|
||||
Services.AddUnique<IContentBlueprintEditingService, ContentBlueprintEditingService>();
|
||||
Services.AddUnique<IContentEditingService, ContentEditingService>();
|
||||
Services.AddUnique<IContentPublishingService, ContentPublishingService>();
|
||||
|
||||
777
src/Umbraco.Core/Services/ContentCrudService.cs
Normal file
777
src/Umbraco.Core/Services/ContentCrudService.cs
Normal file
@@ -0,0 +1,777 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Umbraco.Cms.Core.Events;
|
||||
using Umbraco.Cms.Core.Models;
|
||||
using Umbraco.Cms.Core.Models.Entities;
|
||||
using Umbraco.Cms.Core.Notifications;
|
||||
using Umbraco.Cms.Core.Persistence;
|
||||
using Umbraco.Cms.Core.Persistence.Querying;
|
||||
using Umbraco.Cms.Core.Persistence.Repositories;
|
||||
using Umbraco.Cms.Core.Scoping;
|
||||
using Umbraco.Cms.Core.Services.Changes;
|
||||
using Umbraco.Extensions;
|
||||
|
||||
namespace Umbraco.Cms.Core.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Implements content CRUD (Create, Read, Update, Delete) operations.
|
||||
/// </summary>
|
||||
public class ContentCrudService : ContentServiceBase, IContentCrudService
|
||||
{
|
||||
private readonly IEntityRepository _entityRepository;
|
||||
private readonly IContentTypeRepository _contentTypeRepository;
|
||||
private readonly ILanguageRepository _languageRepository;
|
||||
private readonly ILogger<ContentCrudService> _logger;
|
||||
|
||||
public ContentCrudService(
|
||||
ICoreScopeProvider provider,
|
||||
ILoggerFactory loggerFactory,
|
||||
IEventMessagesFactory eventMessagesFactory,
|
||||
IDocumentRepository documentRepository,
|
||||
IEntityRepository entityRepository,
|
||||
IContentTypeRepository contentTypeRepository,
|
||||
IAuditService auditService,
|
||||
IUserIdKeyResolver userIdKeyResolver,
|
||||
ILanguageRepository languageRepository)
|
||||
: base(provider, loggerFactory, eventMessagesFactory, documentRepository, auditService, userIdKeyResolver)
|
||||
{
|
||||
_entityRepository = entityRepository ?? throw new ArgumentNullException(nameof(entityRepository));
|
||||
_contentTypeRepository = contentTypeRepository ?? throw new ArgumentNullException(nameof(contentTypeRepository));
|
||||
_languageRepository = languageRepository ?? throw new ArgumentNullException(nameof(languageRepository));
|
||||
_logger = loggerFactory.CreateLogger<ContentCrudService>();
|
||||
}
|
||||
|
||||
#region Create
|
||||
|
||||
/// <inheritdoc />
|
||||
public IContent Create(string name, int parentId, string contentTypeAlias, int userId = Constants.Security.SuperUserId)
|
||||
{
|
||||
IContentType? contentType = GetContentType(contentTypeAlias);
|
||||
if (contentType == null)
|
||||
{
|
||||
throw new Exception($"No ContentType matching the passed in Alias: '{contentTypeAlias}' was found");
|
||||
}
|
||||
|
||||
return Create(name, parentId, contentType, userId);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IContent Create(string name, Guid parentId, string contentTypeAlias, int userId = Constants.Security.SuperUserId)
|
||||
{
|
||||
IContent? parent = GetById(parentId);
|
||||
if (parent is null)
|
||||
{
|
||||
throw new ArgumentException($"No content with key '{parentId}' exists.", nameof(parentId));
|
||||
}
|
||||
return Create(name, parent, contentTypeAlias, userId);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IContent Create(string name, int parentId, IContentType contentType, int userId = Constants.Security.SuperUserId)
|
||||
{
|
||||
if (contentType is null)
|
||||
{
|
||||
throw new ArgumentException("Content type must be specified", nameof(contentType));
|
||||
}
|
||||
|
||||
IContent? parent = parentId > 0 ? GetById(parentId) : null;
|
||||
if (parentId > 0 && parent is null)
|
||||
{
|
||||
throw new ArgumentException("No content with that id.", nameof(parentId));
|
||||
}
|
||||
|
||||
var content = new Content(name, parentId, contentType, userId);
|
||||
|
||||
return content;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IContent Create(string name, IContent? parent, string contentTypeAlias, int userId = Constants.Security.SuperUserId)
|
||||
{
|
||||
if (parent == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(parent));
|
||||
}
|
||||
|
||||
IContentType contentType = GetContentType(contentTypeAlias)
|
||||
?? throw new ArgumentException("No content type with that alias.", nameof(contentTypeAlias));
|
||||
|
||||
var content = new Content(name, parent, contentType, userId);
|
||||
|
||||
return content;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IContent CreateAndSave(string name, int parentId, string contentTypeAlias, int userId = Constants.Security.SuperUserId)
|
||||
{
|
||||
EventMessages eventMessages = EventMessagesFactory.Get();
|
||||
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope())
|
||||
{
|
||||
// locking the content tree secures content types too
|
||||
scope.WriteLock(Constants.Locks.ContentTree);
|
||||
scope.ReadLock(Constants.Locks.Languages);
|
||||
|
||||
IContentType contentType = GetContentTypeLocked(contentTypeAlias)
|
||||
?? throw new ArgumentException("No content type with that alias.", nameof(contentTypeAlias));
|
||||
|
||||
IContent? parent = parentId > 0 ? GetById(parentId) : null;
|
||||
if (parentId > 0 && parent == null)
|
||||
{
|
||||
throw new ArgumentException("No content with that id.", nameof(parentId));
|
||||
}
|
||||
|
||||
if (parent?.Trashed == true)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"Cannot create content under trashed parent '{parent.Name}' (id={parent.Id}).");
|
||||
}
|
||||
|
||||
Content content = parentId > 0
|
||||
? new Content(name, parent!, contentType, userId)
|
||||
: new Content(name, parentId, contentType, userId);
|
||||
|
||||
SaveLocked(scope, content, userId);
|
||||
|
||||
scope.Notifications.Publish(
|
||||
new ContentSavedNotification(content, eventMessages));
|
||||
scope.Notifications.Publish(
|
||||
new ContentTreeChangeNotification(content, TreeChangeTypes.RefreshNode, eventMessages));
|
||||
|
||||
scope.Complete();
|
||||
|
||||
return content;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IContent CreateAndSave(string name, IContent parent, string contentTypeAlias, int userId = Constants.Security.SuperUserId)
|
||||
{
|
||||
if (parent == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(parent));
|
||||
}
|
||||
|
||||
EventMessages eventMessages = EventMessagesFactory.Get();
|
||||
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope())
|
||||
{
|
||||
// locking the content tree secures content types too
|
||||
scope.WriteLock(Constants.Locks.ContentTree);
|
||||
scope.ReadLock(Constants.Locks.Languages);
|
||||
|
||||
IContentType contentType = GetContentTypeLocked(contentTypeAlias)
|
||||
?? throw new ArgumentException("No content type with that alias.", nameof(contentTypeAlias));
|
||||
|
||||
if (parent.Trashed == true)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"Cannot create content under trashed parent '{parent.Name}' (id={parent.Id}).");
|
||||
}
|
||||
|
||||
var content = new Content(name, parent, contentType, userId);
|
||||
|
||||
SaveLocked(scope, content, userId);
|
||||
|
||||
scope.Notifications.Publish(
|
||||
new ContentSavedNotification(content, eventMessages));
|
||||
scope.Notifications.Publish(
|
||||
new ContentTreeChangeNotification(content, TreeChangeTypes.RefreshNode, eventMessages));
|
||||
|
||||
scope.Complete();
|
||||
|
||||
return content;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Read
|
||||
|
||||
/// <inheritdoc />
|
||||
public IContent? GetById(int id)
|
||||
{
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true))
|
||||
{
|
||||
scope.ReadLock(Constants.Locks.ContentTree);
|
||||
return DocumentRepository.Get(id);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IContent? GetById(Guid key)
|
||||
{
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true))
|
||||
{
|
||||
scope.ReadLock(Constants.Locks.ContentTree);
|
||||
return DocumentRepository.Get(key);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IEnumerable<IContent> GetByIds(IEnumerable<int> ids)
|
||||
{
|
||||
int[] idsA = ids.ToArray();
|
||||
if (idsA.Length == 0)
|
||||
{
|
||||
return Enumerable.Empty<IContent>();
|
||||
}
|
||||
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true))
|
||||
{
|
||||
scope.ReadLock(Constants.Locks.ContentTree);
|
||||
IEnumerable<IContent>? items = DocumentRepository.GetMany(idsA);
|
||||
|
||||
if (items is not null)
|
||||
{
|
||||
// Use GroupBy to handle potential duplicate keys from repository
|
||||
var index = items.GroupBy(x => x.Id).ToDictionary(g => g.Key, g => g.First());
|
||||
return idsA.Select(x => index.GetValueOrDefault(x)).WhereNotNull();
|
||||
}
|
||||
|
||||
return Enumerable.Empty<IContent>();
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IEnumerable<IContent> GetByIds(IEnumerable<Guid> ids)
|
||||
{
|
||||
Guid[] idsA = ids.ToArray();
|
||||
if (idsA.Length == 0)
|
||||
{
|
||||
return Enumerable.Empty<IContent>();
|
||||
}
|
||||
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true))
|
||||
{
|
||||
scope.ReadLock(Constants.Locks.ContentTree);
|
||||
IEnumerable<IContent>? items = DocumentRepository.GetMany(idsA);
|
||||
|
||||
if (items is not null)
|
||||
{
|
||||
// Use GroupBy to handle potential duplicate keys from repository
|
||||
var index = items.GroupBy(x => x.Key).ToDictionary(g => g.Key, g => g.First());
|
||||
return idsA.Select(x => index.GetValueOrDefault(x)).WhereNotNull();
|
||||
}
|
||||
|
||||
return Enumerable.Empty<IContent>();
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IEnumerable<IContent> GetRootContent()
|
||||
{
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true))
|
||||
{
|
||||
scope.ReadLock(Constants.Locks.ContentTree);
|
||||
IQuery<IContent> query = Query<IContent>().Where(x => x.ParentId == Constants.System.Root);
|
||||
return DocumentRepository.Get(query);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IContent? GetParent(int id)
|
||||
{
|
||||
IContent? content = GetById(id);
|
||||
return GetParent(content);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IContent? GetParent(IContent? content)
|
||||
{
|
||||
if (content?.ParentId == Constants.System.Root ||
|
||||
content?.ParentId == Constants.System.RecycleBinContent ||
|
||||
content is null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return GetById(content.ParentId);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Read (Tree Traversal)
|
||||
|
||||
/// <inheritdoc />
|
||||
public IEnumerable<IContent> GetAncestors(int id)
|
||||
{
|
||||
// intentionally not locking
|
||||
IContent? content = GetById(id);
|
||||
if (content is null)
|
||||
{
|
||||
return Enumerable.Empty<IContent>();
|
||||
}
|
||||
|
||||
return GetAncestors(content);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IEnumerable<IContent> GetAncestors(IContent content)
|
||||
{
|
||||
if (content?.Path == null || content.Level <= 1)
|
||||
{
|
||||
return Enumerable.Empty<IContent>();
|
||||
}
|
||||
|
||||
// Parse path to get ancestor IDs: "-1,123,456,789" -> [123, 456]
|
||||
// Skip root (-1) and exclude self
|
||||
// Use TryParse for resilience against malformed path data
|
||||
var ancestorIds = content.Path
|
||||
.Split(',')
|
||||
.Skip(1) // Skip root (-1)
|
||||
.Select(s => int.TryParse(s, out var id) ? id : (int?)null)
|
||||
.Where(id => id.HasValue && id.Value != content.Id) // Exclude nulls and self
|
||||
.Select(id => id!.Value)
|
||||
.ToArray();
|
||||
|
||||
// Log warning if path appears malformed (expected ancestors but found none)
|
||||
if (ancestorIds.Length == 0 && content.Level > 1)
|
||||
{
|
||||
_logger.LogWarning(
|
||||
"Malformed path '{Path}' for content {ContentId} at level {Level} - expected {ExpectedCount} ancestors but parsed {ActualCount}",
|
||||
content.Path, content.Id, content.Level, content.Level - 1, ancestorIds.Length);
|
||||
}
|
||||
|
||||
return GetByIds(ancestorIds); // Single batch query instead of N+1
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IEnumerable<IContent> GetPagedChildren(int id, long pageIndex, int pageSize, out long totalChildren, IQuery<IContent>? filter = null, Ordering? ordering = null)
|
||||
{
|
||||
if (pageIndex < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(pageIndex));
|
||||
}
|
||||
|
||||
if (pageSize <= 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(pageSize));
|
||||
}
|
||||
|
||||
ordering ??= Ordering.By("sortOrder");
|
||||
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true))
|
||||
{
|
||||
scope.ReadLock(Constants.Locks.ContentTree);
|
||||
|
||||
IQuery<IContent>? query = Query<IContent>()?.Where(x => x.ParentId == id);
|
||||
return DocumentRepository.GetPage(query, pageIndex, pageSize, out totalChildren, filter, ordering);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IEnumerable<IContent> GetPagedDescendants(int id, long pageIndex, int pageSize, out long totalChildren, IQuery<IContent>? filter = null, Ordering? ordering = null)
|
||||
{
|
||||
ordering ??= Ordering.By("Path");
|
||||
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true))
|
||||
{
|
||||
scope.ReadLock(Constants.Locks.ContentTree);
|
||||
|
||||
return GetPagedDescendantsLocked(id, pageIndex, pageSize, out totalChildren, filter, ordering);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool HasChildren(int id)
|
||||
{
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true))
|
||||
{
|
||||
scope.ReadLock(Constants.Locks.ContentTree);
|
||||
IQuery<IContent>? query = Query<IContent>()?.Where(x => x.ParentId == id);
|
||||
var count = DocumentRepository.Count(query);
|
||||
return count > 0;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool Exists(int id)
|
||||
{
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true))
|
||||
{
|
||||
scope.ReadLock(Constants.Locks.ContentTree);
|
||||
return DocumentRepository.Exists(id);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool Exists(Guid key)
|
||||
{
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true))
|
||||
{
|
||||
scope.ReadLock(Constants.Locks.ContentTree);
|
||||
return DocumentRepository.Exists(key);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Save
|
||||
|
||||
/// <inheritdoc />
|
||||
public OperationResult Save(IContent content, int? userId = null, ContentScheduleCollection? contentSchedule = null)
|
||||
{
|
||||
EventMessages eventMessages = EventMessagesFactory.Get();
|
||||
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope())
|
||||
{
|
||||
var savingNotification = new ContentSavingNotification(content, eventMessages);
|
||||
if (scope.Notifications.PublishCancelable(savingNotification))
|
||||
{
|
||||
scope.Complete();
|
||||
return OperationResult.Cancel(eventMessages);
|
||||
}
|
||||
|
||||
scope.WriteLock(Constants.Locks.ContentTree);
|
||||
scope.ReadLock(Constants.Locks.Languages);
|
||||
userId ??= Constants.Security.SuperUserId;
|
||||
|
||||
SaveLocked(scope, content, userId.Value, contentSchedule);
|
||||
|
||||
scope.Notifications.Publish(
|
||||
new ContentSavedNotification(content, eventMessages).WithStateFrom(savingNotification));
|
||||
|
||||
scope.Notifications.Publish(
|
||||
new ContentTreeChangeNotification(content, TreeChangeTypes.RefreshNode, eventMessages));
|
||||
|
||||
scope.Complete();
|
||||
}
|
||||
|
||||
return OperationResult.Succeed(eventMessages);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public OperationResult Save(IEnumerable<IContent> contents, int userId = Constants.Security.SuperUserId)
|
||||
{
|
||||
EventMessages eventMessages = EventMessagesFactory.Get();
|
||||
IContent[] contentsA = contents.ToArray();
|
||||
|
||||
if (contentsA.Length == 0)
|
||||
{
|
||||
return OperationResult.Succeed(eventMessages);
|
||||
}
|
||||
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope())
|
||||
{
|
||||
var savingNotification = new ContentSavingNotification(contentsA, eventMessages);
|
||||
if (scope.Notifications.PublishCancelable(savingNotification))
|
||||
{
|
||||
scope.Complete();
|
||||
return OperationResult.Cancel(eventMessages);
|
||||
}
|
||||
|
||||
scope.WriteLock(Constants.Locks.ContentTree);
|
||||
scope.ReadLock(Constants.Locks.Languages);
|
||||
foreach (IContent content in contentsA)
|
||||
{
|
||||
if (content.HasIdentity == false)
|
||||
{
|
||||
content.CreatorId = userId;
|
||||
}
|
||||
|
||||
content.WriterId = userId;
|
||||
|
||||
DocumentRepository.Save(content);
|
||||
}
|
||||
|
||||
scope.Notifications.Publish(
|
||||
new ContentSavedNotification(contentsA, eventMessages).WithStateFrom(savingNotification));
|
||||
|
||||
scope.Notifications.Publish(
|
||||
new ContentTreeChangeNotification(contentsA, TreeChangeTypes.RefreshNode, eventMessages));
|
||||
|
||||
Audit(AuditType.Save, userId, Constants.System.Root, $"Saved {contentsA.Length} content items");
|
||||
|
||||
scope.Complete();
|
||||
}
|
||||
|
||||
return OperationResult.Succeed(eventMessages);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Delete
|
||||
|
||||
/// <inheritdoc />
|
||||
public OperationResult Delete(IContent content, int userId = Constants.Security.SuperUserId)
|
||||
{
|
||||
EventMessages eventMessages = EventMessagesFactory.Get();
|
||||
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope())
|
||||
{
|
||||
if (scope.Notifications.PublishCancelable(new ContentDeletingNotification(content, eventMessages)))
|
||||
{
|
||||
scope.Complete();
|
||||
return OperationResult.Cancel(eventMessages);
|
||||
}
|
||||
|
||||
scope.WriteLock(Constants.Locks.ContentTree);
|
||||
|
||||
// if it's not trashed yet, and published, we should unpublish
|
||||
// but... Unpublishing event makes no sense (not going to cancel?) and no need to save
|
||||
// just raise the event
|
||||
if (content.Trashed == false && content.Published)
|
||||
{
|
||||
scope.Notifications.Publish(new ContentUnpublishedNotification(content, eventMessages));
|
||||
}
|
||||
|
||||
DeleteLocked(scope, content, eventMessages);
|
||||
|
||||
scope.Notifications.Publish(
|
||||
new ContentTreeChangeNotification(content, TreeChangeTypes.Remove, eventMessages));
|
||||
Audit(AuditType.Delete, userId, content.Id);
|
||||
|
||||
scope.Complete();
|
||||
}
|
||||
|
||||
return OperationResult.Succeed(eventMessages);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Helpers
|
||||
|
||||
/// <summary>
|
||||
/// Gets a content type by alias without creating a scope (must be called within an existing scope).
|
||||
/// </summary>
|
||||
private IContentType? GetContentType(string contentTypeAlias)
|
||||
{
|
||||
if (contentTypeAlias == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(contentTypeAlias));
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(contentTypeAlias))
|
||||
{
|
||||
throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(contentTypeAlias));
|
||||
}
|
||||
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true))
|
||||
{
|
||||
return GetContentTypeLocked(contentTypeAlias);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a content type by alias within an existing scope with proper locking.
|
||||
/// </summary>
|
||||
private IContentType? GetContentTypeLocked(string contentTypeAlias)
|
||||
{
|
||||
if (contentTypeAlias == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(contentTypeAlias));
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(contentTypeAlias))
|
||||
{
|
||||
throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(contentTypeAlias));
|
||||
}
|
||||
|
||||
IQuery<IContentType> query = Query<IContentType>().Where(x => x.Alias == contentTypeAlias);
|
||||
IContentType? contentType = _contentTypeRepository.Get(query).FirstOrDefault();
|
||||
|
||||
return contentType;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves content within an existing scope with proper locking.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Must be called from within a scope that holds ContentTree write lock.
|
||||
/// If content type varies by culture, caller must also hold Languages read lock.
|
||||
/// </remarks>
|
||||
private void SaveLocked(ICoreScope scope, IContent content, int userId, ContentScheduleCollection? contentSchedule = null)
|
||||
{
|
||||
// Validation INSIDE locked section to prevent race conditions
|
||||
PublishedState publishedState = content.PublishedState;
|
||||
if (publishedState != PublishedState.Published && publishedState != PublishedState.Unpublished)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"Cannot save (un)publishing content with name: {content.Name} - and state: {content.PublishedState}, use the dedicated SavePublished method.");
|
||||
}
|
||||
|
||||
if (content.Name != null && content.Name.Length > 255)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"Content with the name {content.Name} cannot be more than 255 characters in length.");
|
||||
}
|
||||
|
||||
if (content.HasIdentity == false)
|
||||
{
|
||||
content.CreatorId = userId;
|
||||
}
|
||||
|
||||
content.WriterId = userId;
|
||||
|
||||
// track the cultures that have changed
|
||||
List<string>? culturesChanging = content.ContentType.VariesByCulture()
|
||||
? content.CultureInfos?.Values.Where(x => x.IsDirty()).Select(x => x.Culture).ToList()
|
||||
: null;
|
||||
|
||||
DocumentRepository.Save(content);
|
||||
|
||||
if (contentSchedule != null)
|
||||
{
|
||||
DocumentRepository.PersistContentSchedule(content, contentSchedule);
|
||||
}
|
||||
|
||||
if (culturesChanging != null && culturesChanging.Any())
|
||||
{
|
||||
var langs = GetLanguageDetailsForAuditEntryLocked(culturesChanging);
|
||||
Audit(AuditType.SaveVariant, userId, content.Id, $"Saved languages: {langs}", langs);
|
||||
}
|
||||
else
|
||||
{
|
||||
Audit(AuditType.Save, userId, content.Id);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes content and all descendants within an existing scope.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Must be called from within a scope that holds ContentTree write lock.
|
||||
/// Uses paging to handle large trees without loading everything into memory.
|
||||
/// Iteration bound prevents infinite loops if database is in inconsistent state.
|
||||
/// </remarks>
|
||||
private void DeleteLocked(ICoreScope scope, IContent content, EventMessages evtMsgs)
|
||||
{
|
||||
void DoDelete(IContent c)
|
||||
{
|
||||
DocumentRepository.Delete(c);
|
||||
scope.Notifications.Publish(new ContentDeletedNotification(c, evtMsgs));
|
||||
}
|
||||
|
||||
const int pageSize = 500;
|
||||
const int maxIterations = 10000; // Safety bound to prevent infinite loops
|
||||
var iteration = 0;
|
||||
var total = long.MaxValue;
|
||||
|
||||
while (total > 0 && iteration < maxIterations)
|
||||
{
|
||||
// get descendants - ordered from deepest to shallowest
|
||||
IEnumerable<IContent> descendants = GetPagedDescendantsLocked(
|
||||
content.Id,
|
||||
0,
|
||||
pageSize,
|
||||
out total,
|
||||
ordering: Ordering.By("Path", Direction.Descending));
|
||||
|
||||
var batch = descendants.ToList();
|
||||
|
||||
// Exit if we got an empty batch (even if total > 0, which indicates inconsistency)
|
||||
if (batch.Count == 0)
|
||||
{
|
||||
if (total > 0)
|
||||
{
|
||||
_logger.LogWarning(
|
||||
"GetPagedDescendants reported {Total} total descendants but returned empty batch for content {ContentId}",
|
||||
total,
|
||||
content.Id);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
foreach (IContent c in batch)
|
||||
{
|
||||
DoDelete(c);
|
||||
}
|
||||
|
||||
iteration++;
|
||||
}
|
||||
|
||||
if (iteration >= maxIterations)
|
||||
{
|
||||
_logger.LogError(
|
||||
"DeleteLocked exceeded maximum iteration limit ({MaxIterations}) for content {ContentId}. Tree may be incompletely deleted.",
|
||||
maxIterations,
|
||||
content.Id);
|
||||
}
|
||||
|
||||
DoDelete(content);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets paged descendants within an existing scope.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Must be called from within a scope that holds ContentTree read lock.
|
||||
/// </remarks>
|
||||
private IEnumerable<IContent> GetPagedDescendantsLocked(int id, long pageIndex, int pageSize, out long totalChildren, IQuery<IContent>? filter = null, Ordering? ordering = null)
|
||||
{
|
||||
if (pageIndex < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(pageIndex));
|
||||
}
|
||||
|
||||
if (pageSize <= 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(pageSize));
|
||||
}
|
||||
|
||||
if (ordering == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(ordering));
|
||||
}
|
||||
|
||||
// if the id is System Root, then just get all
|
||||
if (id != Constants.System.Root)
|
||||
{
|
||||
TreeEntityPath[] contentPath =
|
||||
_entityRepository.GetAllPaths(Constants.ObjectTypes.Document, id).ToArray();
|
||||
if (contentPath.Length == 0)
|
||||
{
|
||||
totalChildren = 0;
|
||||
return Enumerable.Empty<IContent>();
|
||||
}
|
||||
|
||||
IQuery<IContent>? query = GetPagedDescendantQuery(contentPath[0].Path);
|
||||
return DocumentRepository.GetPage(query, pageIndex, pageSize, out totalChildren, filter, ordering);
|
||||
}
|
||||
|
||||
return DocumentRepository.GetPage(null, pageIndex, pageSize, out totalChildren, filter, ordering);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds a query for descendants based on path.
|
||||
/// </summary>
|
||||
private IQuery<IContent>? GetPagedDescendantQuery(string contentPath)
|
||||
{
|
||||
IQuery<IContent>? query = Query<IContent>();
|
||||
if (!contentPath.IsNullOrWhiteSpace())
|
||||
{
|
||||
query?.Where(x => x.Path.SqlStartsWith($"{contentPath},", TextColumnType.NVarchar));
|
||||
}
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets language details for audit entry (creates new scope).
|
||||
/// </summary>
|
||||
private string GetLanguageDetailsForAuditEntry(IEnumerable<string> affectedCultures)
|
||||
{
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true))
|
||||
{
|
||||
scope.ReadLock(Constants.Locks.Languages);
|
||||
return GetLanguageDetailsForAuditEntryLocked(affectedCultures);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets language details for audit entry within an existing scope.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Must be called from within a scope. Caller should hold Languages read lock if concurrent modifications are possible.
|
||||
/// </remarks>
|
||||
private string GetLanguageDetailsForAuditEntryLocked(IEnumerable<string> affectedCultures)
|
||||
{
|
||||
IEnumerable<ILanguage> languages = _languageRepository.GetMany();
|
||||
IEnumerable<string> languageIsoCodes = languages
|
||||
.Where(x => affectedCultures.InvariantContains(x.IsoCode))
|
||||
.Select(x => x.IsoCode);
|
||||
return string.Join(", ", languageIsoCodes);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
169
src/Umbraco.Core/Services/ContentQueryOperationService.cs
Normal file
169
src/Umbraco.Core/Services/ContentQueryOperationService.cs
Normal file
@@ -0,0 +1,169 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Umbraco.Cms.Core.Events;
|
||||
using Umbraco.Cms.Core.Models;
|
||||
using Umbraco.Cms.Core.Persistence.Querying;
|
||||
using Umbraco.Cms.Core.Persistence.Repositories;
|
||||
using Umbraco.Cms.Core.Scoping;
|
||||
|
||||
namespace Umbraco.Cms.Core.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Implements content query operations (counting, filtering by type/level).
|
||||
/// </summary>
|
||||
public class ContentQueryOperationService : ContentServiceBase, IContentQueryOperationService
|
||||
{
|
||||
/// <summary>
|
||||
/// Default ordering for paged queries.
|
||||
/// </summary>
|
||||
private static readonly Ordering DefaultSortOrdering = Ordering.By("sortOrder");
|
||||
|
||||
/// <summary>
|
||||
/// Logger for this service (for debugging, performance monitoring, or error tracking).
|
||||
/// </summary>
|
||||
private readonly ILogger<ContentQueryOperationService> _logger;
|
||||
|
||||
public ContentQueryOperationService(
|
||||
ICoreScopeProvider provider,
|
||||
ILoggerFactory loggerFactory,
|
||||
IEventMessagesFactory eventMessagesFactory,
|
||||
IDocumentRepository documentRepository,
|
||||
IAuditService auditService,
|
||||
IUserIdKeyResolver userIdKeyResolver)
|
||||
: base(provider, loggerFactory, eventMessagesFactory, documentRepository, auditService, userIdKeyResolver)
|
||||
{
|
||||
_logger = loggerFactory.CreateLogger<ContentQueryOperationService>();
|
||||
}
|
||||
|
||||
#region Count Operations
|
||||
|
||||
/// <inheritdoc />
|
||||
public int Count(string? contentTypeAlias = null)
|
||||
{
|
||||
using ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true);
|
||||
scope.ReadLock(Constants.Locks.ContentTree);
|
||||
return DocumentRepository.Count(contentTypeAlias);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public int CountPublished(string? contentTypeAlias = null)
|
||||
{
|
||||
using ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true);
|
||||
scope.ReadLock(Constants.Locks.ContentTree);
|
||||
return DocumentRepository.CountPublished(contentTypeAlias);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public int CountChildren(int parentId, string? contentTypeAlias = null)
|
||||
{
|
||||
using ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true);
|
||||
scope.ReadLock(Constants.Locks.ContentTree);
|
||||
return DocumentRepository.CountChildren(parentId, contentTypeAlias);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public int CountDescendants(int parentId, string? contentTypeAlias = null)
|
||||
{
|
||||
using ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true);
|
||||
scope.ReadLock(Constants.Locks.ContentTree);
|
||||
return DocumentRepository.CountDescendants(parentId, contentTypeAlias);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Hierarchy Queries
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <remarks>
|
||||
/// The returned enumerable may be lazily evaluated. Callers should materialize
|
||||
/// results (e.g., call ToList()) if they need to access them after the scope is disposed.
|
||||
/// This is consistent with the existing ContentService.GetByLevel implementation.
|
||||
/// </remarks>
|
||||
public IEnumerable<IContent> GetByLevel(int level)
|
||||
{
|
||||
using ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true);
|
||||
scope.ReadLock(Constants.Locks.ContentTree);
|
||||
IQuery<IContent>? query = Query<IContent>().Where(x => x.Level == level && x.Trashed == false);
|
||||
return DocumentRepository.Get(query);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Paged Type Queries
|
||||
|
||||
/// <inheritdoc />
|
||||
public IEnumerable<IContent> GetPagedOfType(
|
||||
int contentTypeId,
|
||||
long pageIndex,
|
||||
int pageSize,
|
||||
out long totalRecords,
|
||||
IQuery<IContent>? filter = null,
|
||||
Ordering? ordering = null)
|
||||
{
|
||||
if (pageIndex < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(pageIndex));
|
||||
}
|
||||
|
||||
if (pageSize <= 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(pageSize));
|
||||
}
|
||||
|
||||
ordering ??= DefaultSortOrdering;
|
||||
|
||||
using ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true);
|
||||
scope.ReadLock(Constants.Locks.ContentTree);
|
||||
|
||||
// Note: filter=null is valid and means no additional filtering beyond the content type
|
||||
return DocumentRepository.GetPage(
|
||||
Query<IContent>()?.Where(x => x.ContentTypeId == contentTypeId),
|
||||
pageIndex,
|
||||
pageSize,
|
||||
out totalRecords,
|
||||
filter,
|
||||
ordering);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IEnumerable<IContent> GetPagedOfTypes(
|
||||
int[] contentTypeIds,
|
||||
long pageIndex,
|
||||
int pageSize,
|
||||
out long totalRecords,
|
||||
IQuery<IContent>? filter = null,
|
||||
Ordering? ordering = null)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(contentTypeIds);
|
||||
|
||||
if (pageIndex < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(pageIndex));
|
||||
}
|
||||
|
||||
if (pageSize <= 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(pageSize));
|
||||
}
|
||||
|
||||
ordering ??= DefaultSortOrdering;
|
||||
|
||||
using ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true);
|
||||
|
||||
// Expression trees require a List for Contains() - array not supported.
|
||||
// This O(n) copy is unavoidable but contentTypeIds is typically small.
|
||||
List<int> contentTypeIdsAsList = [.. contentTypeIds];
|
||||
|
||||
scope.ReadLock(Constants.Locks.ContentTree);
|
||||
|
||||
// Note: filter=null is valid and means no additional filtering beyond the content types
|
||||
return DocumentRepository.GetPage(
|
||||
Query<IContent>()?.Where(x => contentTypeIdsAsList.Contains(x.ContentTypeId)),
|
||||
pageIndex,
|
||||
pageSize,
|
||||
out totalRecords,
|
||||
filter,
|
||||
ordering);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
using System.Collections.Immutable;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
@@ -44,9 +46,26 @@ public class ContentService : RepositoryService, IContentService
|
||||
private ContentSettings _contentSettings;
|
||||
private readonly IRelationService _relationService;
|
||||
private IQuery<IContent>? _queryNotTrashed;
|
||||
private readonly Lazy<IContentCrudService> _crudServiceLazy;
|
||||
|
||||
// Property for convenient access (deferred resolution for both paths)
|
||||
private IContentCrudService CrudService => _crudServiceLazy.Value;
|
||||
|
||||
// Query operation service fields (for Phase 2 extracted query operations)
|
||||
private readonly IContentQueryOperationService? _queryOperationService;
|
||||
private readonly Lazy<IContentQueryOperationService>? _queryOperationServiceLazy;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the query operation service.
|
||||
/// </summary>
|
||||
/// <exception cref="InvalidOperationException">Thrown if the service was not properly initialized.</exception>
|
||||
private IContentQueryOperationService QueryOperationService =>
|
||||
_queryOperationService ?? _queryOperationServiceLazy?.Value
|
||||
?? throw new InvalidOperationException("QueryOperationService not initialized. Ensure the service is properly injected via constructor.");
|
||||
|
||||
#region Constructors
|
||||
|
||||
[Microsoft.Extensions.DependencyInjection.ActivatorUtilitiesConstructor]
|
||||
public ContentService(
|
||||
ICoreScopeProvider provider,
|
||||
ILoggerFactory loggerFactory,
|
||||
@@ -64,7 +83,9 @@ public class ContentService : RepositoryService, IContentService
|
||||
PropertyEditorCollection propertyEditorCollection,
|
||||
IIdKeyMap idKeyMap,
|
||||
IOptionsMonitor<ContentSettings> optionsMonitor,
|
||||
IRelationService relationService)
|
||||
IRelationService relationService,
|
||||
IContentCrudService crudService,
|
||||
IContentQueryOperationService queryOperationService) // NEW PARAMETER - Phase 2 query operations
|
||||
: base(provider, loggerFactory, eventMessagesFactory)
|
||||
{
|
||||
_documentRepository = documentRepository;
|
||||
@@ -86,16 +107,25 @@ public class ContentService : RepositoryService, IContentService
|
||||
});
|
||||
_relationService = relationService;
|
||||
_logger = loggerFactory.CreateLogger<ContentService>();
|
||||
ArgumentNullException.ThrowIfNull(crudService);
|
||||
// Wrap in Lazy for consistent access pattern (already resolved, so returns immediately)
|
||||
_crudServiceLazy = new Lazy<IContentCrudService>(() => crudService);
|
||||
|
||||
// Phase 2: Query operation service (direct injection)
|
||||
ArgumentNullException.ThrowIfNull(queryOperationService);
|
||||
_queryOperationService = queryOperationService;
|
||||
_queryOperationServiceLazy = null; // Not needed when directly injected
|
||||
}
|
||||
|
||||
[Obsolete("Use the non-obsolete constructor instead. Scheduled removal in v19.")]
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public ContentService(
|
||||
ICoreScopeProvider provider,
|
||||
ILoggerFactory loggerFactory,
|
||||
IEventMessagesFactory eventMessagesFactory,
|
||||
IDocumentRepository documentRepository,
|
||||
IEntityRepository entityRepository,
|
||||
IAuditRepository auditRepository,
|
||||
IAuditRepository auditRepository, // Old parameter (kept for signature compatibility)
|
||||
IContentTypeRepository contentTypeRepository,
|
||||
IDocumentBlueprintRepository documentBlueprintRepository,
|
||||
ILanguageRepository languageRepository,
|
||||
@@ -107,35 +137,51 @@ public class ContentService : RepositoryService, IContentService
|
||||
IIdKeyMap idKeyMap,
|
||||
IOptionsMonitor<ContentSettings> optionsMonitor,
|
||||
IRelationService relationService)
|
||||
: this(
|
||||
provider,
|
||||
loggerFactory,
|
||||
eventMessagesFactory,
|
||||
documentRepository,
|
||||
entityRepository,
|
||||
StaticServiceProvider.Instance.GetRequiredService<IAuditService>(),
|
||||
contentTypeRepository,
|
||||
documentBlueprintRepository,
|
||||
languageRepository,
|
||||
propertyValidationService,
|
||||
shortStringHelper,
|
||||
cultureImpactFactory,
|
||||
userIdKeyResolver,
|
||||
propertyEditorCollection,
|
||||
idKeyMap,
|
||||
optionsMonitor,
|
||||
relationService)
|
||||
: base(provider, loggerFactory, eventMessagesFactory)
|
||||
{
|
||||
// All existing field assignments...
|
||||
_documentRepository = documentRepository ?? throw new ArgumentNullException(nameof(documentRepository));
|
||||
_entityRepository = entityRepository ?? throw new ArgumentNullException(nameof(entityRepository));
|
||||
_contentTypeRepository = contentTypeRepository ?? throw new ArgumentNullException(nameof(contentTypeRepository));
|
||||
_documentBlueprintRepository = documentBlueprintRepository ?? throw new ArgumentNullException(nameof(documentBlueprintRepository));
|
||||
_languageRepository = languageRepository ?? throw new ArgumentNullException(nameof(languageRepository));
|
||||
_propertyValidationService = propertyValidationService ?? throw new ArgumentNullException(nameof(propertyValidationService));
|
||||
_shortStringHelper = shortStringHelper ?? throw new ArgumentNullException(nameof(shortStringHelper));
|
||||
_cultureImpactFactory = cultureImpactFactory ?? throw new ArgumentNullException(nameof(cultureImpactFactory));
|
||||
_userIdKeyResolver = userIdKeyResolver ?? throw new ArgumentNullException(nameof(userIdKeyResolver));
|
||||
_propertyEditorCollection = propertyEditorCollection ?? throw new ArgumentNullException(nameof(propertyEditorCollection));
|
||||
_idKeyMap = idKeyMap ?? throw new ArgumentNullException(nameof(idKeyMap));
|
||||
_contentSettings = optionsMonitor?.CurrentValue ?? throw new ArgumentNullException(nameof(optionsMonitor));
|
||||
optionsMonitor.OnChange((contentSettings) =>
|
||||
{
|
||||
_contentSettings = contentSettings;
|
||||
});
|
||||
_relationService = relationService ?? throw new ArgumentNullException(nameof(relationService));
|
||||
_logger = loggerFactory.CreateLogger<ContentService>();
|
||||
|
||||
// Lazy resolution of IAuditService (from StaticServiceProvider)
|
||||
_auditService = StaticServiceProvider.Instance.GetRequiredService<IAuditService>();
|
||||
|
||||
// NEW: Lazy resolution of IContentCrudService
|
||||
_crudServiceLazy = new Lazy<IContentCrudService>(() =>
|
||||
StaticServiceProvider.Instance.GetRequiredService<IContentCrudService>(),
|
||||
LazyThreadSafetyMode.ExecutionAndPublication);
|
||||
|
||||
// Phase 2: Lazy resolution of IContentQueryOperationService
|
||||
_queryOperationServiceLazy = new Lazy<IContentQueryOperationService>(() =>
|
||||
StaticServiceProvider.Instance.GetRequiredService<IContentQueryOperationService>(),
|
||||
LazyThreadSafetyMode.ExecutionAndPublication);
|
||||
}
|
||||
|
||||
[Obsolete("Use the non-obsolete constructor instead. Scheduled removal in v19.")]
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public ContentService(
|
||||
ICoreScopeProvider provider,
|
||||
ILoggerFactory loggerFactory,
|
||||
IEventMessagesFactory eventMessagesFactory,
|
||||
IDocumentRepository documentRepository,
|
||||
IEntityRepository entityRepository,
|
||||
IAuditRepository auditRepository,
|
||||
IAuditRepository auditRepository, // Old parameter (kept for signature compatibility)
|
||||
IAuditService auditService,
|
||||
IContentTypeRepository contentTypeRepository,
|
||||
IDocumentBlueprintRepository documentBlueprintRepository,
|
||||
@@ -148,25 +194,38 @@ public class ContentService : RepositoryService, IContentService
|
||||
IIdKeyMap idKeyMap,
|
||||
IOptionsMonitor<ContentSettings> optionsMonitor,
|
||||
IRelationService relationService)
|
||||
: this(
|
||||
provider,
|
||||
loggerFactory,
|
||||
eventMessagesFactory,
|
||||
documentRepository,
|
||||
entityRepository,
|
||||
auditService,
|
||||
contentTypeRepository,
|
||||
documentBlueprintRepository,
|
||||
languageRepository,
|
||||
propertyValidationService,
|
||||
shortStringHelper,
|
||||
cultureImpactFactory,
|
||||
userIdKeyResolver,
|
||||
propertyEditorCollection,
|
||||
idKeyMap,
|
||||
optionsMonitor,
|
||||
relationService)
|
||||
: base(provider, loggerFactory, eventMessagesFactory)
|
||||
{
|
||||
// All existing field assignments...
|
||||
_documentRepository = documentRepository ?? throw new ArgumentNullException(nameof(documentRepository));
|
||||
_entityRepository = entityRepository ?? throw new ArgumentNullException(nameof(entityRepository));
|
||||
_auditService = auditService ?? throw new ArgumentNullException(nameof(auditService));
|
||||
_contentTypeRepository = contentTypeRepository ?? throw new ArgumentNullException(nameof(contentTypeRepository));
|
||||
_documentBlueprintRepository = documentBlueprintRepository ?? throw new ArgumentNullException(nameof(documentBlueprintRepository));
|
||||
_languageRepository = languageRepository ?? throw new ArgumentNullException(nameof(languageRepository));
|
||||
_propertyValidationService = propertyValidationService ?? throw new ArgumentNullException(nameof(propertyValidationService));
|
||||
_shortStringHelper = shortStringHelper ?? throw new ArgumentNullException(nameof(shortStringHelper));
|
||||
_cultureImpactFactory = cultureImpactFactory ?? throw new ArgumentNullException(nameof(cultureImpactFactory));
|
||||
_userIdKeyResolver = userIdKeyResolver ?? throw new ArgumentNullException(nameof(userIdKeyResolver));
|
||||
_propertyEditorCollection = propertyEditorCollection ?? throw new ArgumentNullException(nameof(propertyEditorCollection));
|
||||
_idKeyMap = idKeyMap ?? throw new ArgumentNullException(nameof(idKeyMap));
|
||||
_contentSettings = optionsMonitor?.CurrentValue ?? throw new ArgumentNullException(nameof(optionsMonitor));
|
||||
optionsMonitor.OnChange((contentSettings) =>
|
||||
{
|
||||
_contentSettings = contentSettings;
|
||||
});
|
||||
_relationService = relationService ?? throw new ArgumentNullException(nameof(relationService));
|
||||
_logger = loggerFactory.CreateLogger<ContentService>();
|
||||
|
||||
// NEW: Lazy resolution of IContentCrudService
|
||||
_crudServiceLazy = new Lazy<IContentCrudService>(() =>
|
||||
StaticServiceProvider.Instance.GetRequiredService<IContentCrudService>(),
|
||||
LazyThreadSafetyMode.ExecutionAndPublication);
|
||||
|
||||
// Phase 2: Lazy resolution of IContentQueryOperationService
|
||||
_queryOperationServiceLazy = new Lazy<IContentQueryOperationService>(() =>
|
||||
StaticServiceProvider.Instance.GetRequiredService<IContentQueryOperationService>(),
|
||||
LazyThreadSafetyMode.ExecutionAndPublication);
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -243,40 +302,16 @@ public class ContentService : RepositoryService, IContentService
|
||||
#region Count
|
||||
|
||||
public int CountPublished(string? contentTypeAlias = null)
|
||||
{
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true))
|
||||
{
|
||||
scope.ReadLock(Constants.Locks.ContentTree);
|
||||
return _documentRepository.CountPublished(contentTypeAlias);
|
||||
}
|
||||
}
|
||||
=> QueryOperationService.CountPublished(contentTypeAlias);
|
||||
|
||||
public int Count(string? contentTypeAlias = null)
|
||||
{
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true))
|
||||
{
|
||||
scope.ReadLock(Constants.Locks.ContentTree);
|
||||
return _documentRepository.Count(contentTypeAlias);
|
||||
}
|
||||
}
|
||||
=> QueryOperationService.Count(contentTypeAlias);
|
||||
|
||||
public int CountChildren(int parentId, string? contentTypeAlias = null)
|
||||
{
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true))
|
||||
{
|
||||
scope.ReadLock(Constants.Locks.ContentTree);
|
||||
return _documentRepository.CountChildren(parentId, contentTypeAlias);
|
||||
}
|
||||
}
|
||||
=> QueryOperationService.CountChildren(parentId, contentTypeAlias);
|
||||
|
||||
public int CountDescendants(int parentId, string? contentTypeAlias = null)
|
||||
{
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true))
|
||||
{
|
||||
scope.ReadLock(Constants.Locks.ContentTree);
|
||||
return _documentRepository.CountDescendants(parentId, contentTypeAlias);
|
||||
}
|
||||
}
|
||||
=> QueryOperationService.CountDescendants(parentId, contentTypeAlias);
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -348,11 +383,7 @@ public class ContentService : RepositoryService, IContentService
|
||||
/// <see cref="IContent" />
|
||||
/// </returns>
|
||||
public IContent Create(string name, Guid parentId, string contentTypeAlias, int userId = Constants.Security.SuperUserId)
|
||||
{
|
||||
// TODO: what about culture?
|
||||
IContent? parent = GetById(parentId);
|
||||
return Create(name, parent, contentTypeAlias, userId);
|
||||
}
|
||||
=> CrudService.Create(name, parentId, contentTypeAlias, userId);
|
||||
|
||||
/// <summary>
|
||||
/// Creates an <see cref="IContent" /> object of a specified content type.
|
||||
@@ -368,11 +399,7 @@ public class ContentService : RepositoryService, IContentService
|
||||
/// <param name="userId">The optional id of the user creating the content.</param>
|
||||
/// <returns>The content object.</returns>
|
||||
public IContent Create(string name, int parentId, string contentTypeAlias, int userId = Constants.Security.SuperUserId)
|
||||
{
|
||||
// TODO: what about culture?
|
||||
IContentType contentType = GetContentType(contentTypeAlias);
|
||||
return Create(name, parentId, contentType, userId);
|
||||
}
|
||||
=> CrudService.Create(name, parentId, contentTypeAlias, userId);
|
||||
|
||||
/// <summary>
|
||||
/// Creates an <see cref="IContent" /> object of a specified content type.
|
||||
@@ -388,22 +415,7 @@ public class ContentService : RepositoryService, IContentService
|
||||
/// <param name="userId">The optional id of the user creating the content.</param>
|
||||
/// <returns>The content object.</returns>
|
||||
public IContent Create(string name, int parentId, IContentType contentType, int userId = Constants.Security.SuperUserId)
|
||||
{
|
||||
if (contentType is null)
|
||||
{
|
||||
throw new ArgumentException("Content type must be specified", nameof(contentType));
|
||||
}
|
||||
|
||||
IContent? parent = parentId > 0 ? GetById(parentId) : null;
|
||||
if (parentId > 0 && parent is null)
|
||||
{
|
||||
throw new ArgumentException("No content with that id.", nameof(parentId));
|
||||
}
|
||||
|
||||
var content = new Content(name, parentId, contentType, userId);
|
||||
|
||||
return content;
|
||||
}
|
||||
=> CrudService.Create(name, parentId, contentType, userId);
|
||||
|
||||
/// <summary>
|
||||
/// Creates an <see cref="IContent" /> object of a specified content type, under a parent.
|
||||
@@ -419,21 +431,7 @@ public class ContentService : RepositoryService, IContentService
|
||||
/// <param name="userId">The optional id of the user creating the content.</param>
|
||||
/// <returns>The content object.</returns>
|
||||
public IContent Create(string name, IContent? parent, string contentTypeAlias, int userId = Constants.Security.SuperUserId)
|
||||
{
|
||||
// TODO: what about culture?
|
||||
if (parent == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(parent));
|
||||
}
|
||||
|
||||
IContentType contentType = GetContentType(contentTypeAlias)
|
||||
// causes rollback
|
||||
?? throw new ArgumentException("No content type with that alias.", nameof(contentTypeAlias));
|
||||
|
||||
var content = new Content(name, parent, contentType, userId);
|
||||
|
||||
return content;
|
||||
}
|
||||
=> CrudService.Create(name, parent, contentTypeAlias, userId);
|
||||
|
||||
/// <summary>
|
||||
/// Creates an <see cref="IContent" /> object of a specified content type.
|
||||
@@ -445,36 +443,7 @@ public class ContentService : RepositoryService, IContentService
|
||||
/// <param name="userId">The optional id of the user creating the content.</param>
|
||||
/// <returns>The content object.</returns>
|
||||
public IContent CreateAndSave(string name, int parentId, string contentTypeAlias, int userId = Constants.Security.SuperUserId)
|
||||
{
|
||||
// TODO: what about culture?
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope())
|
||||
{
|
||||
// locking the content tree secures content types too
|
||||
scope.WriteLock(Constants.Locks.ContentTree);
|
||||
|
||||
IContentType contentType = GetContentType(contentTypeAlias)
|
||||
// + locks
|
||||
??
|
||||
// causes rollback
|
||||
throw new ArgumentException("No content type with that alias.", nameof(contentTypeAlias));
|
||||
|
||||
IContent? parent = parentId > 0 ? GetById(parentId) : null; // + locks
|
||||
if (parentId > 0 && parent == null)
|
||||
{
|
||||
throw new ArgumentException("No content with that id.", nameof(parentId)); // causes rollback
|
||||
}
|
||||
|
||||
Content content = parentId > 0
|
||||
? new Content(name, parent!, contentType, userId)
|
||||
: new Content(name, parentId, contentType, userId);
|
||||
|
||||
Save(content, userId);
|
||||
|
||||
scope.Complete();
|
||||
|
||||
return content;
|
||||
}
|
||||
}
|
||||
=> CrudService.CreateAndSave(name, parentId, contentTypeAlias, userId);
|
||||
|
||||
/// <summary>
|
||||
/// Creates an <see cref="IContent" /> object of a specified content type, under a parent.
|
||||
@@ -486,32 +455,7 @@ public class ContentService : RepositoryService, IContentService
|
||||
/// <param name="userId">The optional id of the user creating the content.</param>
|
||||
/// <returns>The content object.</returns>
|
||||
public IContent CreateAndSave(string name, IContent parent, string contentTypeAlias, int userId = Constants.Security.SuperUserId)
|
||||
{
|
||||
// TODO: what about culture?
|
||||
if (parent == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(parent));
|
||||
}
|
||||
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope())
|
||||
{
|
||||
// locking the content tree secures content types too
|
||||
scope.WriteLock(Constants.Locks.ContentTree);
|
||||
|
||||
IContentType contentType = GetContentType(contentTypeAlias)
|
||||
// + locks
|
||||
??
|
||||
// causes rollback
|
||||
throw new ArgumentException("No content type with that alias.", nameof(contentTypeAlias));
|
||||
|
||||
var content = new Content(name, parent, contentType, userId);
|
||||
|
||||
Save(content, userId);
|
||||
|
||||
scope.Complete();
|
||||
return content;
|
||||
}
|
||||
}
|
||||
=> CrudService.CreateAndSave(name, parent, contentTypeAlias, userId);
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -525,13 +469,7 @@ public class ContentService : RepositoryService, IContentService
|
||||
/// <see cref="IContent" />
|
||||
/// </returns>
|
||||
public IContent? GetById(int id)
|
||||
{
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true))
|
||||
{
|
||||
scope.ReadLock(Constants.Locks.ContentTree);
|
||||
return _documentRepository.Get(id);
|
||||
}
|
||||
}
|
||||
=> CrudService.GetById(id);
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="IContent" /> object by Id
|
||||
@@ -541,21 +479,7 @@ public class ContentService : RepositoryService, IContentService
|
||||
/// <see cref="IContent" />
|
||||
/// </returns>
|
||||
public IEnumerable<IContent> GetByIds(IEnumerable<int> ids)
|
||||
{
|
||||
var idsA = ids.ToArray();
|
||||
if (idsA.Length == 0)
|
||||
{
|
||||
return Enumerable.Empty<IContent>();
|
||||
}
|
||||
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true))
|
||||
{
|
||||
scope.ReadLock(Constants.Locks.ContentTree);
|
||||
IEnumerable<IContent> items = _documentRepository.GetMany(idsA);
|
||||
var index = items.ToDictionary(x => x.Id, x => x);
|
||||
return idsA.Select(x => index.GetValueOrDefault(x)).WhereNotNull();
|
||||
}
|
||||
}
|
||||
=> CrudService.GetByIds(ids);
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="IContent" /> object by its 'UniqueId'
|
||||
@@ -565,13 +489,7 @@ public class ContentService : RepositoryService, IContentService
|
||||
/// <see cref="IContent" />
|
||||
/// </returns>
|
||||
public IContent? GetById(Guid key)
|
||||
{
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true))
|
||||
{
|
||||
scope.ReadLock(Constants.Locks.ContentTree);
|
||||
return _documentRepository.Get(key);
|
||||
}
|
||||
}
|
||||
=> CrudService.GetById(key);
|
||||
|
||||
/// <inheritdoc />
|
||||
public ContentScheduleCollection GetContentScheduleByContentId(int contentId)
|
||||
@@ -621,28 +539,7 @@ public class ContentService : RepositoryService, IContentService
|
||||
/// <see cref="IContent" />
|
||||
/// </returns>
|
||||
public IEnumerable<IContent> GetByIds(IEnumerable<Guid> ids)
|
||||
{
|
||||
Guid[] idsA = ids.ToArray();
|
||||
if (idsA.Length == 0)
|
||||
{
|
||||
return Enumerable.Empty<IContent>();
|
||||
}
|
||||
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true))
|
||||
{
|
||||
scope.ReadLock(Constants.Locks.ContentTree);
|
||||
IEnumerable<IContent>? items = _documentRepository.GetMany(idsA);
|
||||
|
||||
if (items is not null)
|
||||
{
|
||||
var index = items.ToDictionary(x => x.Key, x => x);
|
||||
|
||||
return idsA.Select(x => index.GetValueOrDefault(x)).WhereNotNull();
|
||||
}
|
||||
|
||||
return Enumerable.Empty<IContent>();
|
||||
}
|
||||
}
|
||||
=> CrudService.GetByIds(ids);
|
||||
|
||||
/// <inheritdoc />
|
||||
public IEnumerable<IContent> GetPagedOfType(
|
||||
@@ -652,63 +549,11 @@ public class ContentService : RepositoryService, IContentService
|
||||
out long totalRecords,
|
||||
IQuery<IContent>? filter = null,
|
||||
Ordering? ordering = null)
|
||||
{
|
||||
if (pageIndex < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(pageIndex));
|
||||
}
|
||||
|
||||
if (pageSize <= 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(pageSize));
|
||||
}
|
||||
|
||||
ordering ??= Ordering.By("sortOrder");
|
||||
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true))
|
||||
{
|
||||
scope.ReadLock(Constants.Locks.ContentTree);
|
||||
return _documentRepository.GetPage(
|
||||
Query<IContent>()?.Where(x => x.ContentTypeId == contentTypeId),
|
||||
pageIndex,
|
||||
pageSize,
|
||||
out totalRecords,
|
||||
filter,
|
||||
ordering);
|
||||
}
|
||||
}
|
||||
=> QueryOperationService.GetPagedOfType(contentTypeId, pageIndex, pageSize, out totalRecords, filter, ordering);
|
||||
|
||||
/// <inheritdoc />
|
||||
public IEnumerable<IContent> GetPagedOfTypes(int[] contentTypeIds, long pageIndex, int pageSize, out long totalRecords, IQuery<IContent>? filter, Ordering? ordering = null)
|
||||
{
|
||||
if (pageIndex < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(pageIndex));
|
||||
}
|
||||
|
||||
if (pageSize <= 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(pageSize));
|
||||
}
|
||||
|
||||
ordering ??= Ordering.By("sortOrder");
|
||||
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true))
|
||||
{
|
||||
// Need to use a List here because the expression tree cannot convert the array when used in Contains.
|
||||
// See ExpressionTests.Sql_In().
|
||||
List<int> contentTypeIdsAsList = [.. contentTypeIds];
|
||||
|
||||
scope.ReadLock(Constants.Locks.ContentTree);
|
||||
return _documentRepository.GetPage(
|
||||
Query<IContent>()?.Where(x => contentTypeIdsAsList.Contains(x.ContentTypeId)),
|
||||
pageIndex,
|
||||
pageSize,
|
||||
out totalRecords,
|
||||
filter,
|
||||
ordering);
|
||||
}
|
||||
}
|
||||
=> QueryOperationService.GetPagedOfTypes(contentTypeIds, pageIndex, pageSize, out totalRecords, filter, ordering);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a collection of <see cref="IContent" /> objects by Level
|
||||
@@ -717,14 +562,7 @@ public class ContentService : RepositoryService, IContentService
|
||||
/// <returns>An Enumerable list of <see cref="IContent" /> objects</returns>
|
||||
/// <remarks>Contrary to most methods, this method filters out trashed content items.</remarks>
|
||||
public IEnumerable<IContent> GetByLevel(int level)
|
||||
{
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true))
|
||||
{
|
||||
scope.ReadLock(Constants.Locks.ContentTree);
|
||||
IQuery<IContent>? query = Query<IContent>().Where(x => x.Level == level && x.Trashed == false);
|
||||
return _documentRepository.Get(query);
|
||||
}
|
||||
}
|
||||
=> QueryOperationService.GetByLevel(level);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a specific version of an <see cref="IContent" /> item.
|
||||
@@ -787,16 +625,7 @@ public class ContentService : RepositoryService, IContentService
|
||||
/// <param name="id">Id of the <see cref="IContent" /> to retrieve ancestors for</param>
|
||||
/// <returns>An Enumerable list of <see cref="IContent" /> objects</returns>
|
||||
public IEnumerable<IContent> GetAncestors(int id)
|
||||
{
|
||||
// intentionally not locking
|
||||
IContent? content = GetById(id);
|
||||
if (content is null)
|
||||
{
|
||||
return Enumerable.Empty<IContent>();
|
||||
}
|
||||
|
||||
return GetAncestors(content);
|
||||
}
|
||||
=> CrudService.GetAncestors(id);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a collection of <see cref="IContent" /> objects, which are ancestors of the current content.
|
||||
@@ -804,25 +633,7 @@ public class ContentService : RepositoryService, IContentService
|
||||
/// <param name="content"><see cref="IContent" /> to retrieve ancestors for</param>
|
||||
/// <returns>An Enumerable list of <see cref="IContent" /> objects</returns>
|
||||
public IEnumerable<IContent> GetAncestors(IContent content)
|
||||
{
|
||||
// null check otherwise we get exceptions
|
||||
if (content.Path.IsNullOrWhiteSpace())
|
||||
{
|
||||
return Enumerable.Empty<IContent>();
|
||||
}
|
||||
|
||||
var ids = content.GetAncestorIds()?.ToArray();
|
||||
if (ids?.Any() == false)
|
||||
{
|
||||
return new List<IContent>();
|
||||
}
|
||||
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true))
|
||||
{
|
||||
scope.ReadLock(Constants.Locks.ContentTree);
|
||||
return _documentRepository.GetMany(ids!);
|
||||
}
|
||||
}
|
||||
=> CrudService.GetAncestors(content);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a collection of published <see cref="IContent" /> objects by Parent Id
|
||||
@@ -841,54 +652,11 @@ public class ContentService : RepositoryService, IContentService
|
||||
|
||||
/// <inheritdoc />
|
||||
public IEnumerable<IContent> GetPagedChildren(int id, long pageIndex, int pageSize, out long totalChildren, IQuery<IContent>? filter = null, Ordering? ordering = null)
|
||||
{
|
||||
if (pageIndex < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(pageIndex));
|
||||
}
|
||||
|
||||
if (pageSize <= 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(pageSize));
|
||||
}
|
||||
|
||||
ordering ??= Ordering.By("sortOrder");
|
||||
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true))
|
||||
{
|
||||
scope.ReadLock(Constants.Locks.ContentTree);
|
||||
|
||||
IQuery<IContent>? query = Query<IContent>()?.Where(x => x.ParentId == id);
|
||||
return _documentRepository.GetPage(query, pageIndex, pageSize, out totalChildren, filter, ordering);
|
||||
}
|
||||
}
|
||||
=> CrudService.GetPagedChildren(id, pageIndex, pageSize, out totalChildren, filter, ordering);
|
||||
|
||||
/// <inheritdoc />
|
||||
public IEnumerable<IContent> GetPagedDescendants(int id, long pageIndex, int pageSize, out long totalChildren, IQuery<IContent>? filter = null, Ordering? ordering = null)
|
||||
{
|
||||
ordering ??= Ordering.By("Path");
|
||||
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true))
|
||||
{
|
||||
scope.ReadLock(Constants.Locks.ContentTree);
|
||||
|
||||
// if the id is System Root, then just get all
|
||||
if (id != Constants.System.Root)
|
||||
{
|
||||
TreeEntityPath[] contentPath =
|
||||
_entityRepository.GetAllPaths(Constants.ObjectTypes.Document, id).ToArray();
|
||||
if (contentPath.Length == 0)
|
||||
{
|
||||
totalChildren = 0;
|
||||
return Enumerable.Empty<IContent>();
|
||||
}
|
||||
|
||||
return GetPagedLocked(GetPagedDescendantQuery(contentPath[0].Path), pageIndex, pageSize, out totalChildren, filter, ordering);
|
||||
}
|
||||
|
||||
return GetPagedLocked(null, pageIndex, pageSize, out totalChildren, filter, ordering);
|
||||
}
|
||||
}
|
||||
=> CrudService.GetPagedDescendants(id, pageIndex, pageSize, out totalChildren, filter, ordering);
|
||||
|
||||
private IQuery<IContent>? GetPagedDescendantQuery(string contentPath)
|
||||
{
|
||||
@@ -927,11 +695,7 @@ public class ContentService : RepositoryService, IContentService
|
||||
/// <param name="id">Id of the <see cref="IContent" /> to retrieve the parent from</param>
|
||||
/// <returns>Parent <see cref="IContent" /> object</returns>
|
||||
public IContent? GetParent(int id)
|
||||
{
|
||||
// intentionally not locking
|
||||
IContent? content = GetById(id);
|
||||
return GetParent(content);
|
||||
}
|
||||
=> CrudService.GetParent(id);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the parent of the current content as an <see cref="IContent" /> item.
|
||||
@@ -939,29 +703,14 @@ public class ContentService : RepositoryService, IContentService
|
||||
/// <param name="content"><see cref="IContent" /> to retrieve the parent from</param>
|
||||
/// <returns>Parent <see cref="IContent" /> object</returns>
|
||||
public IContent? GetParent(IContent? content)
|
||||
{
|
||||
if (content?.ParentId == Constants.System.Root || content?.ParentId == Constants.System.RecycleBinContent ||
|
||||
content is null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return GetById(content.ParentId);
|
||||
}
|
||||
=> CrudService.GetParent(content);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a collection of <see cref="IContent" /> objects, which reside at the first level / root
|
||||
/// </summary>
|
||||
/// <returns>An Enumerable list of <see cref="IContent" /> objects</returns>
|
||||
public IEnumerable<IContent> GetRootContent()
|
||||
{
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true))
|
||||
{
|
||||
scope.ReadLock(Constants.Locks.ContentTree);
|
||||
IQuery<IContent> query = Query<IContent>().Where(x => x.ParentId == Constants.System.Root);
|
||||
return _documentRepository.Get(query);
|
||||
}
|
||||
}
|
||||
=> CrudService.GetRootContent();
|
||||
|
||||
/// <summary>
|
||||
/// Gets all published content items
|
||||
@@ -1018,8 +767,24 @@ public class ContentService : RepositoryService, IContentService
|
||||
/// </summary>
|
||||
/// <param name="id">Id of the <see cref="IContent" /></param>
|
||||
/// <returns>True if the content has any children otherwise False</returns>
|
||||
public bool HasChildren(int id) => CountChildren(id) > 0;
|
||||
public bool HasChildren(int id)
|
||||
=> CrudService.HasChildren(id);
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether a document with the specified id exists.
|
||||
/// </summary>
|
||||
/// <param name="id">The document id.</param>
|
||||
/// <returns>True if the document exists; otherwise false.</returns>
|
||||
public bool Exists(int id)
|
||||
=> CrudService.Exists(id);
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether a document with the specified key exists.
|
||||
/// </summary>
|
||||
/// <param name="key">The document key.</param>
|
||||
/// <returns>True if the document exists; otherwise false.</returns>
|
||||
public bool Exists(Guid key)
|
||||
=> CrudService.Exists(key);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IDictionary<int, IEnumerable<ContentSchedule>> GetContentSchedulesByIds(Guid[] keys)
|
||||
@@ -1086,126 +851,11 @@ public class ContentService : RepositoryService, IContentService
|
||||
|
||||
/// <inheritdoc />
|
||||
public OperationResult Save(IContent content, int? userId = null, ContentScheduleCollection? contentSchedule = null)
|
||||
{
|
||||
PublishedState publishedState = content.PublishedState;
|
||||
if (publishedState != PublishedState.Published && publishedState != PublishedState.Unpublished)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"Cannot save (un)publishing content with name: {content.Name} - and state: {content.PublishedState}, use the dedicated SavePublished method.");
|
||||
}
|
||||
|
||||
if (content.Name != null && content.Name.Length > 255)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"Content with the name {content.Name} cannot be more than 255 characters in length.");
|
||||
}
|
||||
|
||||
EventMessages eventMessages = EventMessagesFactory.Get();
|
||||
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope())
|
||||
{
|
||||
var savingNotification = new ContentSavingNotification(content, eventMessages);
|
||||
if (scope.Notifications.PublishCancelable(savingNotification))
|
||||
{
|
||||
scope.Complete();
|
||||
return OperationResult.Cancel(eventMessages);
|
||||
}
|
||||
|
||||
scope.WriteLock(Constants.Locks.ContentTree);
|
||||
userId ??= Constants.Security.SuperUserId;
|
||||
|
||||
if (content.HasIdentity == false)
|
||||
{
|
||||
content.CreatorId = userId.Value;
|
||||
}
|
||||
|
||||
content.WriterId = userId.Value;
|
||||
|
||||
// track the cultures that have changed
|
||||
List<string>? culturesChanging = content.ContentType.VariesByCulture()
|
||||
? content.CultureInfos?.Values.Where(x => x.IsDirty()).Select(x => x.Culture).ToList()
|
||||
: null;
|
||||
|
||||
// TODO: Currently there's no way to change track which variant properties have changed, we only have change
|
||||
// tracking enabled on all values on the Property which doesn't allow us to know which variants have changed.
|
||||
// in this particular case, determining which cultures have changed works with the above with names since it will
|
||||
// have always changed if it's been saved in the back office but that's not really fail safe.
|
||||
_documentRepository.Save(content);
|
||||
|
||||
if (contentSchedule != null)
|
||||
{
|
||||
_documentRepository.PersistContentSchedule(content, contentSchedule);
|
||||
}
|
||||
|
||||
scope.Notifications.Publish(
|
||||
new ContentSavedNotification(content, eventMessages).WithStateFrom(savingNotification));
|
||||
|
||||
// TODO: we had code here to FORCE that this event can never be suppressed. But that just doesn't make a ton of sense?!
|
||||
// I understand that if its suppressed that the caches aren't updated, but that would be expected. If someone
|
||||
// is supressing events then I think it's expected that nothing will happen. They are probably doing it for perf
|
||||
// reasons like bulk import and in those cases we don't want this occuring.
|
||||
scope.Notifications.Publish(
|
||||
new ContentTreeChangeNotification(content, TreeChangeTypes.RefreshNode, eventMessages));
|
||||
|
||||
if (culturesChanging != null)
|
||||
{
|
||||
var langs = GetLanguageDetailsForAuditEntry(culturesChanging);
|
||||
Audit(AuditType.SaveVariant, userId.Value, content.Id, $"Saved languages: {langs}", langs);
|
||||
}
|
||||
else
|
||||
{
|
||||
Audit(AuditType.Save, userId.Value, content.Id);
|
||||
}
|
||||
|
||||
scope.Complete();
|
||||
}
|
||||
|
||||
return OperationResult.Succeed(eventMessages);
|
||||
}
|
||||
=> CrudService.Save(content, userId, contentSchedule);
|
||||
|
||||
/// <inheritdoc />
|
||||
public OperationResult Save(IEnumerable<IContent> contents, int userId = Constants.Security.SuperUserId)
|
||||
{
|
||||
EventMessages eventMessages = EventMessagesFactory.Get();
|
||||
IContent[] contentsA = contents.ToArray();
|
||||
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope())
|
||||
{
|
||||
var savingNotification = new ContentSavingNotification(contentsA, eventMessages);
|
||||
if (scope.Notifications.PublishCancelable(savingNotification))
|
||||
{
|
||||
scope.Complete();
|
||||
return OperationResult.Cancel(eventMessages);
|
||||
}
|
||||
|
||||
scope.WriteLock(Constants.Locks.ContentTree);
|
||||
foreach (IContent content in contentsA)
|
||||
{
|
||||
if (content.HasIdentity == false)
|
||||
{
|
||||
content.CreatorId = userId;
|
||||
}
|
||||
|
||||
content.WriterId = userId;
|
||||
|
||||
_documentRepository.Save(content);
|
||||
}
|
||||
|
||||
scope.Notifications.Publish(
|
||||
new ContentSavedNotification(contentsA, eventMessages).WithStateFrom(savingNotification));
|
||||
|
||||
// TODO: See note above about supressing events
|
||||
scope.Notifications.Publish(
|
||||
new ContentTreeChangeNotification(contentsA, TreeChangeTypes.RefreshNode, eventMessages));
|
||||
|
||||
string contentIds = string.Join(", ", contentsA.Select(x => x.Id));
|
||||
Audit(AuditType.Save, userId, Constants.System.Root, $"Saved multiple content items (#{contentIds.Length})");
|
||||
|
||||
scope.Complete();
|
||||
}
|
||||
|
||||
return OperationResult.Succeed(eventMessages);
|
||||
}
|
||||
=> CrudService.Save(contents, userId);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public PublishResult Publish(IContent content, string[] cultures, int userId = Constants.Security.SuperUserId)
|
||||
@@ -2286,38 +1936,7 @@ public class ContentService : RepositoryService, IContentService
|
||||
|
||||
/// <inheritdoc />
|
||||
public OperationResult Delete(IContent content, int userId = Constants.Security.SuperUserId)
|
||||
{
|
||||
EventMessages eventMessages = EventMessagesFactory.Get();
|
||||
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope())
|
||||
{
|
||||
if (scope.Notifications.PublishCancelable(new ContentDeletingNotification(content, eventMessages)))
|
||||
{
|
||||
scope.Complete();
|
||||
return OperationResult.Cancel(eventMessages);
|
||||
}
|
||||
|
||||
scope.WriteLock(Constants.Locks.ContentTree);
|
||||
|
||||
// if it's not trashed yet, and published, we should unpublish
|
||||
// but... Unpublishing event makes no sense (not going to cancel?) and no need to save
|
||||
// just raise the event
|
||||
if (content.Trashed == false && content.Published)
|
||||
{
|
||||
scope.Notifications.Publish(new ContentUnpublishedNotification(content, eventMessages));
|
||||
}
|
||||
|
||||
DeleteLocked(scope, content, eventMessages);
|
||||
|
||||
scope.Notifications.Publish(
|
||||
new ContentTreeChangeNotification(content, TreeChangeTypes.Remove, eventMessages));
|
||||
Audit(AuditType.Delete, userId, content.Id);
|
||||
|
||||
scope.Complete();
|
||||
}
|
||||
|
||||
return OperationResult.Succeed(eventMessages);
|
||||
}
|
||||
=> CrudService.Delete(content, userId);
|
||||
|
||||
private void DeleteLocked(ICoreScope scope, IContent content, EventMessages evtMsgs)
|
||||
{
|
||||
|
||||
69
src/Umbraco.Core/Services/ContentServiceBase.cs
Normal file
69
src/Umbraco.Core/Services/ContentServiceBase.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Umbraco.Cms.Core.Events;
|
||||
using Umbraco.Cms.Core.Models;
|
||||
using Umbraco.Cms.Core.Persistence.Querying;
|
||||
using Umbraco.Cms.Core.Persistence.Repositories;
|
||||
using Umbraco.Cms.Core.Scoping;
|
||||
|
||||
namespace Umbraco.Cms.Core.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Abstract base class for content-related services providing shared infrastructure.
|
||||
/// </summary>
|
||||
public abstract class ContentServiceBase : RepositoryService
|
||||
{
|
||||
protected readonly IDocumentRepository DocumentRepository;
|
||||
protected readonly IAuditService AuditService;
|
||||
protected readonly IUserIdKeyResolver UserIdKeyResolver;
|
||||
|
||||
protected ContentServiceBase(
|
||||
ICoreScopeProvider provider,
|
||||
ILoggerFactory loggerFactory,
|
||||
IEventMessagesFactory eventMessagesFactory,
|
||||
IDocumentRepository documentRepository,
|
||||
IAuditService auditService,
|
||||
IUserIdKeyResolver userIdKeyResolver)
|
||||
: base(provider, loggerFactory, eventMessagesFactory)
|
||||
{
|
||||
DocumentRepository = documentRepository ?? throw new ArgumentNullException(nameof(documentRepository));
|
||||
AuditService = auditService ?? throw new ArgumentNullException(nameof(auditService));
|
||||
UserIdKeyResolver = userIdKeyResolver ?? throw new ArgumentNullException(nameof(userIdKeyResolver));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Records an audit entry for a content operation (synchronous).
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Uses ConfigureAwait(false) to avoid capturing synchronization context and prevent deadlocks.
|
||||
/// TODO: Replace with sync overloads when IAuditService.Add and IUserIdKeyResolver.Get are available.
|
||||
/// </remarks>
|
||||
protected void Audit(AuditType type, int userId, int objectId, string? message = null, string? parameters = null)
|
||||
{
|
||||
// Use ConfigureAwait(false) to avoid context capture and potential deadlocks
|
||||
Guid userKey = UserIdKeyResolver.GetAsync(userId).ConfigureAwait(false).GetAwaiter().GetResult();
|
||||
|
||||
AuditService.AddAsync(
|
||||
type,
|
||||
userKey,
|
||||
objectId,
|
||||
UmbracoObjectTypes.Document.GetName(),
|
||||
message,
|
||||
parameters).ConfigureAwait(false).GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Records an audit entry for a content operation asynchronously.
|
||||
/// </summary>
|
||||
protected async Task AuditAsync(AuditType type, int userId, int objectId, string? message = null, string? parameters = null)
|
||||
{
|
||||
Guid userKey = await UserIdKeyResolver.GetAsync(userId).ConfigureAwait(false);
|
||||
|
||||
await AuditService.AddAsync(
|
||||
type,
|
||||
userKey,
|
||||
objectId,
|
||||
UmbracoObjectTypes.Document.GetName(),
|
||||
message,
|
||||
parameters).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
12
src/Umbraco.Core/Services/ContentServiceConstants.cs
Normal file
12
src/Umbraco.Core/Services/ContentServiceConstants.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
namespace Umbraco.Cms.Core.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Constants used by content-related services.
|
||||
/// </summary>
|
||||
public static class ContentServiceConstants
|
||||
{
|
||||
/// <summary>
|
||||
/// Default page size for batch operations (e.g., cascade delete).
|
||||
/// </summary>
|
||||
public const int DefaultBatchPageSize = 500;
|
||||
}
|
||||
251
src/Umbraco.Core/Services/IContentCrudService.cs
Normal file
251
src/Umbraco.Core/Services/IContentCrudService.cs
Normal file
@@ -0,0 +1,251 @@
|
||||
// src/Umbraco.Core/Services/IContentCrudService.cs
|
||||
using Umbraco.Cms.Core.Models;
|
||||
using Umbraco.Cms.Core.Persistence.Querying;
|
||||
|
||||
namespace Umbraco.Cms.Core.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Service for content CRUD (Create, Read, Update, Delete) operations.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// <strong>Implementation Note:</strong> Do not implement this interface directly.
|
||||
/// Instead, inherit from <see cref="ContentServiceBase"/> which provides required
|
||||
/// infrastructure (scoping, repository access, auditing). Direct implementation
|
||||
/// without this base class will result in missing functionality.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// This interface is part of the ContentService refactoring initiative.
|
||||
/// It extracts core CRUD operations into a focused, testable service.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// <strong>Versioning Policy:</strong> This interface follows additive-only changes.
|
||||
/// New methods may be added with default implementations. Existing methods will not
|
||||
/// be removed or have signatures changed without a 2 major version deprecation period.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// <strong>Version History:</strong>
|
||||
/// <list type="bullet">
|
||||
/// <item><description>v1.0 (Phase 1): Initial interface with Create, Read, Save, Delete operations</description></item>
|
||||
/// </list>
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
/// <since>1.0</since>
|
||||
public interface IContentCrudService : IService
|
||||
{
|
||||
#region Create
|
||||
|
||||
/// <summary>
|
||||
/// Creates a document without persisting it.
|
||||
/// </summary>
|
||||
/// <param name="name">Name of the document.</param>
|
||||
/// <param name="parentId">Id of the parent, or -1 for root.</param>
|
||||
/// <param name="contentTypeAlias">Alias of the content type.</param>
|
||||
/// <param name="userId">Optional id of the user creating the content.</param>
|
||||
/// <returns>The new document.</returns>
|
||||
IContent Create(string name, int parentId, string contentTypeAlias, int userId = Constants.Security.SuperUserId);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a document without persisting it.
|
||||
/// </summary>
|
||||
/// <param name="name">Name of the document.</param>
|
||||
/// <param name="parentId">Guid key of the parent.</param>
|
||||
/// <param name="contentTypeAlias">Alias of the content type.</param>
|
||||
/// <param name="userId">Optional id of the user creating the content.</param>
|
||||
/// <returns>The new document.</returns>
|
||||
IContent Create(string name, Guid parentId, string contentTypeAlias, int userId = Constants.Security.SuperUserId);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a document without persisting it.
|
||||
/// </summary>
|
||||
/// <param name="name">Name of the document.</param>
|
||||
/// <param name="parentId">Id of the parent, or -1 for root.</param>
|
||||
/// <param name="contentType">The content type.</param>
|
||||
/// <param name="userId">Optional id of the user creating the content.</param>
|
||||
/// <returns>The new document.</returns>
|
||||
IContent Create(string name, int parentId, IContentType contentType, int userId = Constants.Security.SuperUserId);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a document without persisting it.
|
||||
/// </summary>
|
||||
/// <param name="name">Name of the document.</param>
|
||||
/// <param name="parent">The parent document.</param>
|
||||
/// <param name="contentTypeAlias">Alias of the content type.</param>
|
||||
/// <param name="userId">Optional id of the user creating the content.</param>
|
||||
/// <returns>The new document.</returns>
|
||||
IContent Create(string name, IContent? parent, string contentTypeAlias, int userId = Constants.Security.SuperUserId);
|
||||
|
||||
/// <summary>
|
||||
/// Creates and persists a document.
|
||||
/// </summary>
|
||||
/// <param name="name">Name of the document.</param>
|
||||
/// <param name="parentId">Id of the parent, or -1 for root.</param>
|
||||
/// <param name="contentTypeAlias">Alias of the content type.</param>
|
||||
/// <param name="userId">Optional id of the user creating the content.</param>
|
||||
/// <returns>The persisted document.</returns>
|
||||
IContent CreateAndSave(string name, int parentId, string contentTypeAlias, int userId = Constants.Security.SuperUserId);
|
||||
|
||||
/// <summary>
|
||||
/// Creates and persists a document.
|
||||
/// </summary>
|
||||
/// <param name="name">Name of the document.</param>
|
||||
/// <param name="parent">The parent document.</param>
|
||||
/// <param name="contentTypeAlias">Alias of the content type.</param>
|
||||
/// <param name="userId">Optional id of the user creating the content.</param>
|
||||
/// <returns>The persisted document.</returns>
|
||||
IContent CreateAndSave(string name, IContent parent, string contentTypeAlias, int userId = Constants.Security.SuperUserId);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Read
|
||||
|
||||
/// <summary>
|
||||
/// Gets a document by id.
|
||||
/// </summary>
|
||||
/// <param name="id">The document id.</param>
|
||||
/// <returns>The document, or null if not found.</returns>
|
||||
IContent? GetById(int id);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a document by key.
|
||||
/// </summary>
|
||||
/// <param name="key">The document key.</param>
|
||||
/// <returns>The document, or null if not found.</returns>
|
||||
IContent? GetById(Guid key);
|
||||
|
||||
/// <summary>
|
||||
/// Gets documents by ids.
|
||||
/// </summary>
|
||||
/// <param name="ids">The document ids.</param>
|
||||
/// <returns>The documents.</returns>
|
||||
IEnumerable<IContent> GetByIds(IEnumerable<int> ids);
|
||||
|
||||
/// <summary>
|
||||
/// Gets documents by keys.
|
||||
/// </summary>
|
||||
/// <param name="ids">The document keys.</param>
|
||||
/// <returns>The documents.</returns>
|
||||
IEnumerable<IContent> GetByIds(IEnumerable<Guid> ids);
|
||||
|
||||
/// <summary>
|
||||
/// Gets root-level documents.
|
||||
/// </summary>
|
||||
/// <returns>The root documents.</returns>
|
||||
IEnumerable<IContent> GetRootContent();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the parent of a document.
|
||||
/// </summary>
|
||||
/// <param name="id">Id of the document.</param>
|
||||
/// <returns>The parent document, or null if at root.</returns>
|
||||
IContent? GetParent(int id);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the parent of a document.
|
||||
/// </summary>
|
||||
/// <param name="content">The document.</param>
|
||||
/// <returns>The parent document, or null if at root.</returns>
|
||||
IContent? GetParent(IContent? content);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Read (Tree Traversal)
|
||||
|
||||
/// <summary>
|
||||
/// Gets ancestors of a document.
|
||||
/// </summary>
|
||||
/// <param name="id">Id of the document.</param>
|
||||
/// <returns>The ancestor documents, from root to parent (closest to root first).</returns>
|
||||
IEnumerable<IContent> GetAncestors(int id);
|
||||
|
||||
/// <summary>
|
||||
/// Gets ancestors of a document.
|
||||
/// </summary>
|
||||
/// <param name="content">The document.</param>
|
||||
/// <returns>The ancestor documents, from root to parent (closest to root first).</returns>
|
||||
IEnumerable<IContent> GetAncestors(IContent content);
|
||||
|
||||
/// <summary>
|
||||
/// Gets paged children of a document.
|
||||
/// </summary>
|
||||
/// <param name="id">Id of the parent document.</param>
|
||||
/// <param name="pageIndex">Zero-based page index.</param>
|
||||
/// <param name="pageSize">Page size.</param>
|
||||
/// <param name="totalChildren">Total number of children.</param>
|
||||
/// <param name="filter">Optional filter query.</param>
|
||||
/// <param name="ordering">Optional ordering.</param>
|
||||
/// <returns>The child documents.</returns>
|
||||
IEnumerable<IContent> GetPagedChildren(int id, long pageIndex, int pageSize, out long totalChildren, IQuery<IContent>? filter = null, Ordering? ordering = null);
|
||||
|
||||
/// <summary>
|
||||
/// Gets paged descendants of a document.
|
||||
/// </summary>
|
||||
/// <param name="id">Id of the ancestor document.</param>
|
||||
/// <param name="pageIndex">Zero-based page index.</param>
|
||||
/// <param name="pageSize">Page size.</param>
|
||||
/// <param name="totalChildren">Total number of descendants.</param>
|
||||
/// <param name="filter">Optional filter query.</param>
|
||||
/// <param name="ordering">Optional ordering.</param>
|
||||
/// <returns>The descendant documents.</returns>
|
||||
IEnumerable<IContent> GetPagedDescendants(int id, long pageIndex, int pageSize, out long totalChildren, IQuery<IContent>? filter = null, Ordering? ordering = null);
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether a document has children.
|
||||
/// </summary>
|
||||
/// <param name="id">The document id.</param>
|
||||
/// <returns>True if the document has children; otherwise false.</returns>
|
||||
bool HasChildren(int id);
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether a document with the specified id exists.
|
||||
/// </summary>
|
||||
/// <param name="id">The document id.</param>
|
||||
/// <returns>True if the document exists; otherwise false.</returns>
|
||||
bool Exists(int id);
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether a document with the specified key exists.
|
||||
/// </summary>
|
||||
/// <param name="key">The document key.</param>
|
||||
/// <returns>True if the document exists; otherwise false.</returns>
|
||||
bool Exists(Guid key);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Save
|
||||
|
||||
/// <summary>
|
||||
/// Saves a document.
|
||||
/// </summary>
|
||||
/// <param name="content">The document to save.</param>
|
||||
/// <param name="userId">Optional id of the user saving the content.</param>
|
||||
/// <param name="contentSchedule">Optional content schedule.</param>
|
||||
/// <returns>The operation result.</returns>
|
||||
OperationResult Save(IContent content, int? userId = null, ContentScheduleCollection? contentSchedule = null);
|
||||
|
||||
/// <summary>
|
||||
/// Saves multiple documents.
|
||||
/// </summary>
|
||||
/// <param name="contents">The documents to save.</param>
|
||||
/// <param name="userId">Optional id of the user saving the content.</param>
|
||||
/// <returns>The operation result.</returns>
|
||||
/// <remarks>
|
||||
/// This method does not support content schedules. To save content with schedules,
|
||||
/// use the single-item <see cref="Save(IContent, int?, ContentScheduleCollection?)"/> overload.
|
||||
/// </remarks>
|
||||
OperationResult Save(IEnumerable<IContent> contents, int userId = Constants.Security.SuperUserId);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Delete
|
||||
|
||||
/// <summary>
|
||||
/// Permanently deletes a document and all its descendants.
|
||||
/// </summary>
|
||||
/// <param name="content">The document to delete.</param>
|
||||
/// <param name="userId">Optional id of the user deleting the content.</param>
|
||||
/// <returns>The operation result.</returns>
|
||||
OperationResult Delete(IContent content, int userId = Constants.Security.SuperUserId);
|
||||
|
||||
#endregion
|
||||
}
|
||||
123
src/Umbraco.Core/Services/IContentQueryOperationService.cs
Normal file
123
src/Umbraco.Core/Services/IContentQueryOperationService.cs
Normal file
@@ -0,0 +1,123 @@
|
||||
// src/Umbraco.Core/Services/IContentQueryOperationService.cs
|
||||
using Umbraco.Cms.Core.Models;
|
||||
using Umbraco.Cms.Core.Persistence.Querying;
|
||||
|
||||
namespace Umbraco.Cms.Core.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Service for content query operations (counting, filtering by type/level).
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// <strong>Implementation Note:</strong> Do not implement this interface directly.
|
||||
/// Instead, inherit from <see cref="ContentServiceBase"/> which provides required
|
||||
/// infrastructure (scoping, repository access, auditing). Direct implementation
|
||||
/// without this base class will result in missing functionality.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// This interface is part of the ContentService refactoring initiative (Phase 2).
|
||||
/// It extracts query operations into a focused, testable service.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// <strong>Versioning Policy:</strong> This interface follows additive-only changes.
|
||||
/// New methods may be added with default implementations. Existing methods will not
|
||||
/// be removed or have signatures changed without a 2 major version deprecation period.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// <strong>Version History:</strong>
|
||||
/// <list type="bullet">
|
||||
/// <item><description>v1.0 (Phase 2): Initial interface with Count, GetByLevel, GetPagedOfType operations</description></item>
|
||||
/// </list>
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
/// <since>1.0</since>
|
||||
public interface IContentQueryOperationService : IService
|
||||
{
|
||||
#region Count Operations
|
||||
|
||||
/// <summary>
|
||||
/// Counts content items, optionally filtered by content type.
|
||||
/// </summary>
|
||||
/// <param name="contentTypeAlias">Optional content type alias to filter by. If the alias doesn't exist, returns 0.</param>
|
||||
/// <returns>The count of matching content items (includes trashed items).</returns>
|
||||
int Count(string? contentTypeAlias = null);
|
||||
|
||||
/// <summary>
|
||||
/// Counts published content items, optionally filtered by content type.
|
||||
/// </summary>
|
||||
/// <param name="contentTypeAlias">Optional content type alias to filter by. If the alias doesn't exist, returns 0.</param>
|
||||
/// <returns>The count of matching published content items.</returns>
|
||||
int CountPublished(string? contentTypeAlias = null);
|
||||
|
||||
/// <summary>
|
||||
/// Counts children of a parent, optionally filtered by content type.
|
||||
/// </summary>
|
||||
/// <param name="parentId">The parent content id. If the parent doesn't exist, returns 0.</param>
|
||||
/// <param name="contentTypeAlias">Optional content type alias to filter by. If the alias doesn't exist, returns 0.</param>
|
||||
/// <returns>The count of matching child content items.</returns>
|
||||
int CountChildren(int parentId, string? contentTypeAlias = null);
|
||||
|
||||
/// <summary>
|
||||
/// Counts descendants of an ancestor, optionally filtered by content type.
|
||||
/// </summary>
|
||||
/// <param name="parentId">The ancestor content id. If the ancestor doesn't exist, returns 0.</param>
|
||||
/// <param name="contentTypeAlias">Optional content type alias to filter by. If the alias doesn't exist, returns 0.</param>
|
||||
/// <returns>The count of matching descendant content items.</returns>
|
||||
int CountDescendants(int parentId, string? contentTypeAlias = null);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Hierarchy Queries
|
||||
|
||||
/// <summary>
|
||||
/// Gets content items at a specific tree level.
|
||||
/// </summary>
|
||||
/// <param name="level">The tree level (1 = root children, 2 = grandchildren, etc.).</param>
|
||||
/// <returns>Content items at the specified level, excluding trashed items.</returns>
|
||||
IEnumerable<IContent> GetByLevel(int level);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Paged Type Queries
|
||||
|
||||
/// <summary>
|
||||
/// Gets paged content items of a specific content type.
|
||||
/// </summary>
|
||||
/// <param name="contentTypeId">The content type id. If the content type doesn't exist, returns empty results with totalRecords = 0.</param>
|
||||
/// <param name="pageIndex">Zero-based page index.</param>
|
||||
/// <param name="pageSize">Page size.</param>
|
||||
/// <param name="totalRecords">Output: total number of matching records.</param>
|
||||
/// <param name="filter">Optional filter query.</param>
|
||||
/// <param name="ordering">Optional ordering (defaults to sortOrder).</param>
|
||||
/// <returns>Paged content items.</returns>
|
||||
/// <exception cref="ArgumentOutOfRangeException">Thrown when pageIndex is negative or pageSize is less than or equal to zero.</exception>
|
||||
IEnumerable<IContent> GetPagedOfType(
|
||||
int contentTypeId,
|
||||
long pageIndex,
|
||||
int pageSize,
|
||||
out long totalRecords,
|
||||
IQuery<IContent>? filter = null,
|
||||
Ordering? ordering = null);
|
||||
|
||||
/// <summary>
|
||||
/// Gets paged content items of multiple content types.
|
||||
/// </summary>
|
||||
/// <param name="contentTypeIds">The content type ids. If empty or containing non-existent IDs, returns empty results with totalRecords = 0.</param>
|
||||
/// <param name="pageIndex">Zero-based page index.</param>
|
||||
/// <param name="pageSize">Page size.</param>
|
||||
/// <param name="totalRecords">Output: total number of matching records.</param>
|
||||
/// <param name="filter">Optional filter query.</param>
|
||||
/// <param name="ordering">Optional ordering (defaults to sortOrder).</param>
|
||||
/// <returns>Paged content items.</returns>
|
||||
/// <exception cref="ArgumentNullException">Thrown when contentTypeIds is null.</exception>
|
||||
/// <exception cref="ArgumentOutOfRangeException">Thrown when pageIndex is negative or pageSize is less than or equal to zero.</exception>
|
||||
IEnumerable<IContent> GetPagedOfTypes(
|
||||
int[] contentTypeIds,
|
||||
long pageIndex,
|
||||
int pageSize,
|
||||
out long totalRecords,
|
||||
IQuery<IContent>? filter = null,
|
||||
Ordering? ordering = null);
|
||||
|
||||
#endregion
|
||||
}
|
||||
170
src/Umbraco.Web.UI.Login/package-lock.json
generated
170
src/Umbraco.Web.UI.Login/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
27
test-output.txt
Normal file
27
test-output.txt
Normal file
@@ -0,0 +1,27 @@
|
||||
Test run for /home/yv01p/Umbraco-CMS/tests/Umbraco.Tests.Integration/bin/Debug/net10.0/Umbraco.Tests.Integration.dll (.NETCoreApp,Version=v10.0)
|
||||
VSTest version 18.0.1 (x64)
|
||||
|
||||
Starting test execution, please wait...
|
||||
A total of 1 test files matched the specified pattern.
|
||||
Failed Cannot_Create_Content_With_Non_Existing_ContentType_Alias [364 ms]
|
||||
Error Message:
|
||||
Expected: <System.Exception>
|
||||
But was: <System.ArgumentException: No ContentType matching the passed in Alias: 'umbAliasDoesntExist' was found (Parameter 'contentTypeAlias')
|
||||
at Umbraco.Cms.Core.Services.ContentCrudService.Create(String name, Int32 parentId, String contentTypeAlias, Int32 userId) in /home/yv01p/Umbraco-CMS/src/Umbraco.Core/Services/ContentCrudService.cs:line 51
|
||||
at Umbraco.Cms.Core.Services.ContentService.Create(String name, Int32 parentId, String contentTypeAlias, Int32 userId) in /home/yv01p/Umbraco-CMS/src/Umbraco.Core/Services/ContentService.cs:line 398
|
||||
at Umbraco.Cms.Tests.Integration.Umbraco.Core.Services.ContentServiceTests.<Cannot_Create_Content_With_Non_Existing_ContentType_Alias>b__50_0() in /home/yv01p/Umbraco-CMS/tests/Umbraco.Tests.Integration/Umbraco.Core/Services/ContentServiceTests.cs:line 531
|
||||
at NUnit.Framework.Assert.Throws(IResolveConstraint expression, TestDelegate code, String message, Object[] args)>
|
||||
|
||||
Stack Trace:
|
||||
at Umbraco.Cms.Tests.Integration.Umbraco.Core.Services.ContentServiceTests.Cannot_Create_Content_With_Non_Existing_ContentType_Alias() in /home/yv01p/Umbraco-CMS/tests/Umbraco.Tests.Integration/Umbraco.Core/Services/ContentServiceTests.cs:line 531
|
||||
|
||||
1) at Umbraco.Cms.Tests.Integration.Umbraco.Core.Services.ContentServiceTests.Cannot_Create_Content_With_Non_Existing_ContentType_Alias() in /home/yv01p/Umbraco-CMS/tests/Umbraco.Tests.Integration/Umbraco.Core/Services/ContentServiceTests.cs:line 531
|
||||
|
||||
|
||||
Standard Output Messages:
|
||||
Start test 55: Cannot_Create_Content_With_Non_Existing_ContentType_Alias Failed
|
||||
|
||||
Skipped TagsAreUpdatedWhenContentIsTrashedAndUnTrashed_Tree [< 1 ms]
|
||||
Skipped TagsAreUpdatedWhenContentIsUnpublishedAndRePublished_Tree [< 1 ms]
|
||||
|
||||
Failed! - Failed: 1, Passed: 208, Skipped: 2, Total: 211, Duration: 3 m 18 s - Umbraco.Tests.Integration.dll (net10.0)
|
||||
@@ -0,0 +1,254 @@
|
||||
// Copyright (c) Umbraco.
|
||||
// See LICENSE for more details.
|
||||
|
||||
using System.Diagnostics;
|
||||
using System.Text.Json;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Umbraco.Cms.Tests.Integration.Testing;
|
||||
|
||||
/// <summary>
|
||||
/// Base class for ContentService performance benchmarks.
|
||||
/// Extends UmbracoIntegrationTestWithContent with structured benchmark recording.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Usage:
|
||||
/// <code>
|
||||
/// [Test]
|
||||
/// [LongRunning]
|
||||
/// public void MyBenchmark()
|
||||
/// {
|
||||
/// var sw = Stopwatch.StartNew();
|
||||
/// // ... operation under test ...
|
||||
/// sw.Stop();
|
||||
/// RecordBenchmark("MyBenchmark", sw.ElapsedMilliseconds, itemCount);
|
||||
/// }
|
||||
/// </code>
|
||||
///
|
||||
/// Results are output in both human-readable and JSON formats for baseline comparison.
|
||||
/// </remarks>
|
||||
public abstract class ContentServiceBenchmarkBase : UmbracoIntegrationTestWithContent
|
||||
{
|
||||
private readonly List<BenchmarkResult> _results = new();
|
||||
|
||||
// Regression enforcement configuration
|
||||
private const double DefaultRegressionThreshold = 20.0;
|
||||
|
||||
// Allow CI override via environment variable
|
||||
private static readonly double RegressionThreshold =
|
||||
double.TryParse(Environment.GetEnvironmentVariable("BENCHMARK_REGRESSION_THRESHOLD"), out var t)
|
||||
? t
|
||||
: DefaultRegressionThreshold;
|
||||
|
||||
// Optional strict mode: fail if baseline is missing (useful for CI)
|
||||
private static readonly bool RequireBaseline =
|
||||
bool.TryParse(Environment.GetEnvironmentVariable("BENCHMARK_REQUIRE_BASELINE"), out var b) && b;
|
||||
|
||||
// Thread-safe lazy initialization of repository root
|
||||
private static readonly Lazy<string> _repositoryRoot = new(FindRepositoryRoot);
|
||||
|
||||
// Thread-safe lazy initialization of baseline data
|
||||
private static readonly Lazy<Dictionary<string, BenchmarkResult>> _baselineLoader =
|
||||
new(() => LoadBaselineInternal(), LazyThreadSafetyMode.ExecutionAndPublication);
|
||||
|
||||
private static Dictionary<string, BenchmarkResult> Baseline => _baselineLoader.Value;
|
||||
|
||||
private static string BaselinePath => Path.Combine(_repositoryRoot.Value, "docs", "plans", "baseline-phase0.json");
|
||||
|
||||
/// <summary>
|
||||
/// Records a benchmark result for later output.
|
||||
/// </summary>
|
||||
/// <param name="name">Name of the benchmark (should match method name).</param>
|
||||
/// <param name="elapsedMs">Elapsed time in milliseconds.</param>
|
||||
/// <param name="itemCount">Number of items processed (for per-item metrics).</param>
|
||||
protected void RecordBenchmark(string name, long elapsedMs, int itemCount)
|
||||
{
|
||||
var result = new BenchmarkResult(name, elapsedMs, itemCount);
|
||||
_results.Add(result);
|
||||
|
||||
// Human-readable output
|
||||
TestContext.WriteLine($"[BENCHMARK] {name}: {elapsedMs}ms ({result.MsPerItem:F2}ms/item, {itemCount} items)");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Records a benchmark result without item count (for single-item operations).
|
||||
/// </summary>
|
||||
protected void RecordBenchmark(string name, long elapsedMs)
|
||||
=> RecordBenchmark(name, elapsedMs, 1);
|
||||
|
||||
/// <summary>
|
||||
/// Measures and records a benchmark for the given action.
|
||||
/// </summary>
|
||||
/// <param name="name">Name of the benchmark.</param>
|
||||
/// <param name="itemCount">Number of items processed.</param>
|
||||
/// <param name="action">The action to benchmark.</param>
|
||||
/// <param name="skipWarmup">Skip warmup for destructive operations (delete, empty recycle bin).</param>
|
||||
/// <returns>Elapsed time in milliseconds.</returns>
|
||||
protected long MeasureAndRecord(string name, int itemCount, Action action, bool skipWarmup = false)
|
||||
{
|
||||
// Warmup iteration: triggers JIT compilation, warms connection pool and caches.
|
||||
// Skip for destructive operations that would fail on second execution.
|
||||
if (!skipWarmup)
|
||||
{
|
||||
try
|
||||
{
|
||||
action();
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Warmup failure is acceptable for some operations; continue to measured run
|
||||
}
|
||||
}
|
||||
|
||||
var sw = Stopwatch.StartNew();
|
||||
action();
|
||||
sw.Stop();
|
||||
RecordBenchmark(name, sw.ElapsedMilliseconds, itemCount);
|
||||
return sw.ElapsedMilliseconds;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Measures and records a benchmark, returning the result of the function.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Performs a warmup call before measurement to trigger JIT compilation.
|
||||
/// Safe for read-only operations that can be repeated without side effects.
|
||||
/// </remarks>
|
||||
protected T MeasureAndRecord<T>(string name, int itemCount, Func<T> func)
|
||||
{
|
||||
// Warmup: triggers JIT compilation, warms caches
|
||||
try { func(); } catch { /* ignore warmup errors */ }
|
||||
|
||||
var sw = Stopwatch.StartNew();
|
||||
var result = func();
|
||||
sw.Stop();
|
||||
RecordBenchmark(name, sw.ElapsedMilliseconds, itemCount);
|
||||
return result;
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void OutputBenchmarkResults()
|
||||
{
|
||||
if (_results.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// JSON output for automated comparison
|
||||
// Wrapped in markers for easy extraction from test output
|
||||
var json = JsonSerializer.Serialize(_results, new JsonSerializerOptions { WriteIndented = true });
|
||||
TestContext.WriteLine($"[BENCHMARK_JSON]{json}[/BENCHMARK_JSON]");
|
||||
|
||||
_results.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finds the repository root by searching for umbraco.sln.
|
||||
/// </summary>
|
||||
private static string FindRepositoryRoot()
|
||||
{
|
||||
var dir = new DirectoryInfo(TestContext.CurrentContext.TestDirectory);
|
||||
while (dir != null)
|
||||
{
|
||||
if (File.Exists(Path.Combine(dir.FullName, "umbraco.sln")))
|
||||
{
|
||||
return dir.FullName;
|
||||
}
|
||||
dir = dir.Parent;
|
||||
}
|
||||
throw new InvalidOperationException(
|
||||
$"Cannot find repository root (umbraco.sln) starting from {TestContext.CurrentContext.TestDirectory}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Records a benchmark and asserts no regression beyond the threshold.
|
||||
/// </summary>
|
||||
/// <param name="name">Benchmark name (must match baseline JSON key).</param>
|
||||
/// <param name="elapsedMs">Measured elapsed time in milliseconds.</param>
|
||||
/// <param name="itemCount">Number of items processed.</param>
|
||||
/// <param name="thresholdPercent">Maximum allowed regression percentage (default: 20%, configurable via BENCHMARK_REGRESSION_THRESHOLD env var).</param>
|
||||
protected void AssertNoRegression(string name, long elapsedMs, int itemCount, double thresholdPercent = -1)
|
||||
{
|
||||
RecordBenchmark(name, elapsedMs, itemCount);
|
||||
|
||||
// Use environment-configurable threshold if not explicitly specified
|
||||
var effectiveThreshold = thresholdPercent < 0 ? RegressionThreshold : thresholdPercent;
|
||||
|
||||
if (Baseline.TryGetValue(name, out var baselineResult))
|
||||
{
|
||||
var maxAllowed = baselineResult.ElapsedMs * (1 + effectiveThreshold / 100);
|
||||
|
||||
if (elapsedMs > maxAllowed)
|
||||
{
|
||||
var regressionPct = ((double)(elapsedMs - baselineResult.ElapsedMs) / baselineResult.ElapsedMs) * 100;
|
||||
Assert.Fail(
|
||||
$"Performance regression detected for '{name}': " +
|
||||
$"{elapsedMs}ms exceeds threshold of {maxAllowed:F0}ms " +
|
||||
$"(baseline: {baselineResult.ElapsedMs}ms, regression: +{regressionPct:F1}%, threshold: {effectiveThreshold}%)");
|
||||
}
|
||||
|
||||
TestContext.WriteLine($"[REGRESSION_CHECK] {name}: PASS ({elapsedMs}ms <= {maxAllowed:F0}ms, baseline: {baselineResult.ElapsedMs}ms, threshold: {effectiveThreshold}%)");
|
||||
}
|
||||
else if (RequireBaseline)
|
||||
{
|
||||
Assert.Fail($"No baseline entry found for '{name}' and BENCHMARK_REQUIRE_BASELINE=true");
|
||||
}
|
||||
else
|
||||
{
|
||||
TestContext.WriteLine($"[REGRESSION_CHECK] {name}: SKIPPED (no baseline entry)");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Measures, records, and asserts no regression for the given action.
|
||||
/// </summary>
|
||||
protected long MeasureAndAssertNoRegression(string name, int itemCount, Action action, bool skipWarmup = false, double thresholdPercent = -1)
|
||||
{
|
||||
// Warmup iteration (skip for destructive operations)
|
||||
if (!skipWarmup)
|
||||
{
|
||||
try { action(); }
|
||||
catch (Exception ex)
|
||||
{
|
||||
TestContext.WriteLine($"[WARMUP] {name} warmup failed: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
var sw = Stopwatch.StartNew();
|
||||
action();
|
||||
sw.Stop();
|
||||
|
||||
AssertNoRegression(name, sw.ElapsedMilliseconds, itemCount, thresholdPercent);
|
||||
return sw.ElapsedMilliseconds;
|
||||
}
|
||||
|
||||
private static Dictionary<string, BenchmarkResult> LoadBaselineInternal()
|
||||
{
|
||||
if (!File.Exists(BaselinePath))
|
||||
{
|
||||
TestContext.WriteLine($"[BASELINE] File not found: {BaselinePath}");
|
||||
return new Dictionary<string, BenchmarkResult>();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var json = File.ReadAllText(BaselinePath);
|
||||
var results = JsonSerializer.Deserialize<List<BenchmarkResult>>(json) ?? new List<BenchmarkResult>();
|
||||
TestContext.WriteLine($"[BASELINE] Loaded {results.Count} baseline entries from {BaselinePath}");
|
||||
return results.ToDictionary(r => r.Name, r => r);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
TestContext.WriteLine($"[BASELINE] Failed to load baseline: {ex.Message}");
|
||||
return new Dictionary<string, BenchmarkResult>();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents a single benchmark measurement.
|
||||
/// </summary>
|
||||
internal sealed record BenchmarkResult(string Name, long ElapsedMs, int ItemCount)
|
||||
{
|
||||
public double MsPerItem => ItemCount > 0 ? (double)ElapsedMs / ItemCount : 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,212 @@
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Cms.Core.Models;
|
||||
using Umbraco.Cms.Core.Services;
|
||||
using Umbraco.Cms.Tests.Common.Builders;
|
||||
using Umbraco.Cms.Tests.Common.Testing;
|
||||
using Umbraco.Cms.Tests.Integration.Testing;
|
||||
|
||||
namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Integration tests for ContentQueryOperationService.
|
||||
/// </summary>
|
||||
[TestFixture]
|
||||
[UmbracoTest(
|
||||
Database = UmbracoTestOptions.Database.NewSchemaPerTest,
|
||||
WithApplication = true)]
|
||||
public class ContentQueryOperationServiceTests : UmbracoIntegrationTestWithContent
|
||||
{
|
||||
private IContentQueryOperationService QueryService => GetRequiredService<IContentQueryOperationService>();
|
||||
|
||||
[Test]
|
||||
public void Count_WithNoFilter_ReturnsAllContentCount()
|
||||
{
|
||||
// Arrange - base class creates Textpage, Subpage, Subpage2, Subpage3, Trashed
|
||||
|
||||
// Act
|
||||
var count = QueryService.Count();
|
||||
|
||||
// Assert - should return 5 (all items including Trashed)
|
||||
Assert.That(count, Is.EqualTo(5));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Count_WithNonExistentContentTypeAlias_ReturnsZero()
|
||||
{
|
||||
// Arrange
|
||||
var nonExistentAlias = "nonexistent-content-type-alias";
|
||||
|
||||
// Act
|
||||
var count = QueryService.Count(nonExistentAlias);
|
||||
|
||||
// Assert
|
||||
Assert.That(count, Is.EqualTo(0));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Count_WithContentTypeAlias_ReturnsFilteredCount()
|
||||
{
|
||||
// Arrange
|
||||
var alias = ContentType.Alias;
|
||||
|
||||
// Act
|
||||
var count = QueryService.Count(alias);
|
||||
|
||||
// Assert - all 5 content items use the same content type
|
||||
Assert.That(count, Is.EqualTo(5));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CountChildren_ReturnsChildCount()
|
||||
{
|
||||
// Arrange - Textpage has children: Subpage, Subpage2, Subpage3
|
||||
var parentId = Textpage.Id;
|
||||
|
||||
// Act
|
||||
var count = QueryService.CountChildren(parentId);
|
||||
|
||||
// Assert
|
||||
Assert.That(count, Is.EqualTo(3));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetByLevel_ReturnsContentAtLevel()
|
||||
{
|
||||
// Arrange - level 1 is root content
|
||||
|
||||
// Act
|
||||
var items = QueryService.GetByLevel(1);
|
||||
|
||||
// Assert
|
||||
Assert.That(items, Is.Not.Null);
|
||||
Assert.That(items.All(x => x.Level == 1), Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetPagedOfType_ReturnsPaginatedResults()
|
||||
{
|
||||
// Arrange
|
||||
var contentTypeId = ContentType.Id;
|
||||
|
||||
// Act
|
||||
var items = QueryService.GetPagedOfType(contentTypeId, 0, 10, out var total);
|
||||
|
||||
// Assert
|
||||
Assert.That(items, Is.Not.Null);
|
||||
Assert.That(total, Is.EqualTo(5)); // All 5 content items are of this type
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetPagedOfTypes_WithEmptyArray_ReturnsEmpty()
|
||||
{
|
||||
// Act
|
||||
var items = QueryService.GetPagedOfTypes(Array.Empty<int>(), 0, 10, out var total);
|
||||
|
||||
// Assert
|
||||
Assert.That(items, Is.Empty);
|
||||
Assert.That(total, Is.EqualTo(0));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetPagedOfTypes_WithNonExistentContentTypeIds_ReturnsEmpty()
|
||||
{
|
||||
// Arrange
|
||||
var nonExistentIds = new[] { 999999, 999998 };
|
||||
|
||||
// Act
|
||||
var items = QueryService.GetPagedOfTypes(nonExistentIds, 0, 10, out var total);
|
||||
|
||||
// Assert
|
||||
Assert.That(items, Is.Empty);
|
||||
Assert.That(total, Is.EqualTo(0));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CountChildren_WithNonExistentParentId_ReturnsZero()
|
||||
{
|
||||
// Arrange
|
||||
var nonExistentParentId = 999999;
|
||||
|
||||
// Act
|
||||
var count = QueryService.CountChildren(nonExistentParentId);
|
||||
|
||||
// Assert
|
||||
Assert.That(count, Is.EqualTo(0));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetByLevel_WithLevelZero_ReturnsEmpty()
|
||||
{
|
||||
// Arrange - level 0 doesn't exist (content starts at level 1)
|
||||
|
||||
// Act
|
||||
var items = QueryService.GetByLevel(0);
|
||||
|
||||
// Assert
|
||||
Assert.That(items, Is.Empty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetByLevel_WithNegativeLevel_ReturnsEmpty()
|
||||
{
|
||||
// Arrange
|
||||
|
||||
// Act
|
||||
var items = QueryService.GetByLevel(-1);
|
||||
|
||||
// Assert
|
||||
Assert.That(items, Is.Empty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetPagedOfType_WithNonExistentContentTypeId_ReturnsEmpty()
|
||||
{
|
||||
// Arrange
|
||||
var nonExistentId = 999999;
|
||||
|
||||
// Act
|
||||
var items = QueryService.GetPagedOfType(nonExistentId, 0, 10, out var total);
|
||||
|
||||
// Assert
|
||||
Assert.That(items, Is.Empty);
|
||||
Assert.That(total, Is.EqualTo(0));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CountDescendants_ReturnsDescendantCount()
|
||||
{
|
||||
// Arrange - Textpage has descendants: Subpage, Subpage2, Subpage3
|
||||
var ancestorId = Textpage.Id;
|
||||
|
||||
// Act
|
||||
var count = QueryService.CountDescendants(ancestorId);
|
||||
|
||||
// Assert
|
||||
Assert.That(count, Is.EqualTo(3));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CountDescendants_WithNonExistentAncestorId_ReturnsZero()
|
||||
{
|
||||
// Arrange
|
||||
var nonExistentId = 999999;
|
||||
|
||||
// Act
|
||||
var count = QueryService.CountDescendants(nonExistentId);
|
||||
|
||||
// Assert
|
||||
Assert.That(count, Is.EqualTo(0));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CountPublished_WithNoPublishedContent_ReturnsZero()
|
||||
{
|
||||
// Arrange - base class creates content but doesn't publish
|
||||
|
||||
// Act
|
||||
var count = QueryService.CountPublished();
|
||||
|
||||
// Assert
|
||||
Assert.That(count, Is.EqualTo(0));
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,871 @@
|
||||
// Copyright (c) Umbraco.
|
||||
// See LICENSE for more details.
|
||||
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Cms.Core;
|
||||
using Umbraco.Cms.Core.Events;
|
||||
using Umbraco.Cms.Core.Models;
|
||||
using Umbraco.Cms.Core.Models.Entities;
|
||||
using Umbraco.Cms.Core.Models.Membership;
|
||||
using Umbraco.Cms.Core.Notifications;
|
||||
using Umbraco.Cms.Core.Services;
|
||||
using Umbraco.Cms.Tests.Common.Builders;
|
||||
using Umbraco.Cms.Tests.Common.Testing;
|
||||
using Umbraco.Cms.Tests.Integration.Testing;
|
||||
|
||||
namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Integration tests specifically for validating ContentService refactoring.
|
||||
/// These tests establish behavioral baselines that must pass throughout the refactoring phases.
|
||||
/// </summary>
|
||||
[TestFixture]
|
||||
[NonParallelizable] // Required: static notification handler state is shared across tests
|
||||
[Category("Refactoring")] // v1.2: Added for easier test filtering during refactoring
|
||||
[UmbracoTest(
|
||||
Database = UmbracoTestOptions.Database.NewSchemaPerTest,
|
||||
PublishedRepositoryEvents = true,
|
||||
WithApplication = true,
|
||||
Logger = UmbracoTestOptions.Logger.Console)]
|
||||
internal sealed class ContentServiceRefactoringTests : UmbracoIntegrationTestWithContent
|
||||
{
|
||||
private IContentTypeService ContentTypeService => GetRequiredService<IContentTypeService>();
|
||||
private IUserService UserService => GetRequiredService<IUserService>();
|
||||
private IUserGroupService UserGroupService => GetRequiredService<IUserGroupService>();
|
||||
|
||||
protected override void CustomTestSetup(IUmbracoBuilder builder) => builder
|
||||
.AddNotificationHandler<ContentSavingNotification, RefactoringTestNotificationHandler>()
|
||||
.AddNotificationHandler<ContentSavedNotification, RefactoringTestNotificationHandler>()
|
||||
.AddNotificationHandler<ContentPublishingNotification, RefactoringTestNotificationHandler>()
|
||||
.AddNotificationHandler<ContentPublishedNotification, RefactoringTestNotificationHandler>()
|
||||
.AddNotificationHandler<ContentUnpublishingNotification, RefactoringTestNotificationHandler>()
|
||||
.AddNotificationHandler<ContentUnpublishedNotification, RefactoringTestNotificationHandler>()
|
||||
.AddNotificationHandler<ContentMovingNotification, RefactoringTestNotificationHandler>()
|
||||
.AddNotificationHandler<ContentMovedNotification, RefactoringTestNotificationHandler>()
|
||||
.AddNotificationHandler<ContentMovingToRecycleBinNotification, RefactoringTestNotificationHandler>()
|
||||
.AddNotificationHandler<ContentMovedToRecycleBinNotification, RefactoringTestNotificationHandler>()
|
||||
.AddNotificationHandler<ContentSortingNotification, RefactoringTestNotificationHandler>()
|
||||
.AddNotificationHandler<ContentSortedNotification, RefactoringTestNotificationHandler>()
|
||||
.AddNotificationHandler<ContentDeletingNotification, RefactoringTestNotificationHandler>()
|
||||
.AddNotificationHandler<ContentDeletedNotification, RefactoringTestNotificationHandler>();
|
||||
|
||||
[SetUp]
|
||||
public override void Setup()
|
||||
{
|
||||
base.Setup();
|
||||
RefactoringTestNotificationHandler.Reset();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void Teardown()
|
||||
{
|
||||
RefactoringTestNotificationHandler.Reset();
|
||||
}
|
||||
|
||||
#region Notification Ordering Tests
|
||||
|
||||
/// <summary>
|
||||
/// Test 1: Verifies that MoveToRecycleBin for published content fires notifications in the correct order.
|
||||
/// Expected order: MovingToRecycleBin -> MovedToRecycleBin
|
||||
/// Note: As per design doc, MoveToRecycleBin does NOT unpublish first - content is "masked" not unpublished.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void MoveToRecycleBin_PublishedContent_FiresNotificationsInCorrectOrder()
|
||||
{
|
||||
// Arrange - Create and publish content
|
||||
// First publish parent if not already published
|
||||
if (!Textpage.Published)
|
||||
{
|
||||
ContentService.Publish(Textpage, new[] { "*" });
|
||||
}
|
||||
|
||||
var content = ContentBuilder.CreateSimpleContent(ContentType, "TestContent", Textpage.Id);
|
||||
ContentService.Save(content);
|
||||
ContentService.Publish(content, new[] { "*" });
|
||||
|
||||
// Verify it's published
|
||||
Assert.That(content.Published, Is.True, "Content should be published before test");
|
||||
|
||||
// Clear notification tracking
|
||||
RefactoringTestNotificationHandler.Reset();
|
||||
|
||||
// Act
|
||||
var result = ContentService.MoveToRecycleBin(content);
|
||||
|
||||
// Assert
|
||||
Assert.That(result.Success, Is.True, "MoveToRecycleBin should succeed");
|
||||
|
||||
var notifications = RefactoringTestNotificationHandler.NotificationOrder;
|
||||
|
||||
// Verify notification sequence
|
||||
Assert.That(notifications, Does.Contain(nameof(ContentMovingToRecycleBinNotification)),
|
||||
"MovingToRecycleBin notification should fire");
|
||||
Assert.That(notifications, Does.Contain(nameof(ContentMovedToRecycleBinNotification)),
|
||||
"MovedToRecycleBin notification should fire");
|
||||
|
||||
// Verify order: Moving comes before Moved
|
||||
var movingIndex = notifications.IndexOf(nameof(ContentMovingToRecycleBinNotification));
|
||||
var movedIndex = notifications.IndexOf(nameof(ContentMovedToRecycleBinNotification));
|
||||
Assert.That(movingIndex, Is.LessThan(movedIndex),
|
||||
"MovingToRecycleBin should fire before MovedToRecycleBin");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test 2: Verifies that MoveToRecycleBin for unpublished content only fires move notifications.
|
||||
/// No publish/unpublish notifications should be fired.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void MoveToRecycleBin_UnpublishedContent_OnlyFiresMoveNotifications()
|
||||
{
|
||||
// Arrange - Create content but don't publish
|
||||
// First publish parent if not already published (required for creating child content)
|
||||
if (!Textpage.Published)
|
||||
{
|
||||
ContentService.Publish(Textpage, new[] { "*" });
|
||||
}
|
||||
|
||||
var content = ContentBuilder.CreateSimpleContent(ContentType, "UnpublishedContent", Textpage.Id);
|
||||
ContentService.Save(content);
|
||||
|
||||
// Verify it's not published
|
||||
Assert.That(content.Published, Is.False, "Content should not be published before test");
|
||||
|
||||
// Clear notification tracking
|
||||
RefactoringTestNotificationHandler.Reset();
|
||||
|
||||
// Act
|
||||
var result = ContentService.MoveToRecycleBin(content);
|
||||
|
||||
// Assert
|
||||
Assert.That(result.Success, Is.True, "MoveToRecycleBin should succeed");
|
||||
|
||||
var notifications = RefactoringTestNotificationHandler.NotificationOrder;
|
||||
|
||||
// Verify move notifications fire
|
||||
Assert.That(notifications, Does.Contain(nameof(ContentMovingToRecycleBinNotification)),
|
||||
"MovingToRecycleBin notification should fire");
|
||||
Assert.That(notifications, Does.Contain(nameof(ContentMovedToRecycleBinNotification)),
|
||||
"MovedToRecycleBin notification should fire");
|
||||
|
||||
// Verify no publish/unpublish notifications
|
||||
Assert.That(notifications, Does.Not.Contain(nameof(ContentPublishingNotification)),
|
||||
"Publishing notification should not fire for unpublished content");
|
||||
Assert.That(notifications, Does.Not.Contain(nameof(ContentPublishedNotification)),
|
||||
"Published notification should not fire for unpublished content");
|
||||
Assert.That(notifications, Does.Not.Contain(nameof(ContentUnpublishingNotification)),
|
||||
"Unpublishing notification should not fire for unpublished content");
|
||||
Assert.That(notifications, Does.Not.Contain(nameof(ContentUnpublishedNotification)),
|
||||
"Unpublished notification should not fire for unpublished content");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Sort Operation Tests
|
||||
|
||||
/// <summary>
|
||||
/// Test 3: Verifies Sort(IEnumerable<IContent>) correctly reorders children.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void Sort_WithContentItems_ChangesSortOrder()
|
||||
{
|
||||
// Arrange - Use existing subpages from base class (Subpage, Subpage2, Subpage3)
|
||||
// Get fresh copies to ensure we have current sort orders
|
||||
var child1 = ContentService.GetById(Subpage.Id)!;
|
||||
var child2 = ContentService.GetById(Subpage2.Id)!;
|
||||
var child3 = ContentService.GetById(Subpage3.Id)!;
|
||||
|
||||
// v1.2: Verify initial sort order assumption
|
||||
Assert.That(child1.SortOrder, Is.LessThan(child2.SortOrder), "Setup: child1 before child2");
|
||||
Assert.That(child2.SortOrder, Is.LessThan(child3.SortOrder), "Setup: child2 before child3");
|
||||
|
||||
// Record original sort orders
|
||||
var originalOrder1 = child1.SortOrder;
|
||||
var originalOrder2 = child2.SortOrder;
|
||||
var originalOrder3 = child3.SortOrder;
|
||||
|
||||
// Create reversed order list
|
||||
var reorderedItems = new[] { child3, child2, child1 };
|
||||
|
||||
// Act
|
||||
var result = ContentService.Sort(reorderedItems);
|
||||
|
||||
// Assert
|
||||
Assert.That(result.Success, Is.True, "Sort should succeed");
|
||||
|
||||
// Re-fetch to verify persisted order
|
||||
child1 = ContentService.GetById(Subpage.Id)!;
|
||||
child2 = ContentService.GetById(Subpage2.Id)!;
|
||||
child3 = ContentService.GetById(Subpage3.Id)!;
|
||||
|
||||
Assert.That(child3.SortOrder, Is.EqualTo(0), "Child3 should now be first (sort order 0)");
|
||||
Assert.That(child2.SortOrder, Is.EqualTo(1), "Child2 should now be second (sort order 1)");
|
||||
Assert.That(child1.SortOrder, Is.EqualTo(2), "Child1 should now be third (sort order 2)");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test 4: Verifies Sort(IEnumerable<int>) correctly reorders children by ID.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void Sort_WithIds_ChangesSortOrder()
|
||||
{
|
||||
// Arrange - Use existing subpages from base class
|
||||
var child1 = ContentService.GetById(Subpage.Id)!;
|
||||
var child2 = ContentService.GetById(Subpage2.Id)!;
|
||||
var child3 = ContentService.GetById(Subpage3.Id)!;
|
||||
|
||||
// v1.2: Verify initial sort order assumption
|
||||
Assert.That(child1.SortOrder, Is.LessThan(child2.SortOrder), "Setup: child1 before child2");
|
||||
Assert.That(child2.SortOrder, Is.LessThan(child3.SortOrder), "Setup: child2 before child3");
|
||||
|
||||
var child1Id = Subpage.Id;
|
||||
var child2Id = Subpage2.Id;
|
||||
var child3Id = Subpage3.Id;
|
||||
|
||||
// Create reversed order list by ID
|
||||
var reorderedIds = new[] { child3Id, child2Id, child1Id };
|
||||
|
||||
// Act
|
||||
var result = ContentService.Sort(reorderedIds);
|
||||
|
||||
// Assert
|
||||
Assert.That(result.Success, Is.True, "Sort should succeed");
|
||||
|
||||
// Re-fetch to verify persisted order (v1.3: removed var to avoid shadowing)
|
||||
child1 = ContentService.GetById(child1Id)!;
|
||||
child2 = ContentService.GetById(child2Id)!;
|
||||
child3 = ContentService.GetById(child3Id)!;
|
||||
|
||||
Assert.That(child3.SortOrder, Is.EqualTo(0), "Child3 should now be first (sort order 0)");
|
||||
Assert.That(child2.SortOrder, Is.EqualTo(1), "Child2 should now be second (sort order 1)");
|
||||
Assert.That(child1.SortOrder, Is.EqualTo(2), "Child1 should now be third (sort order 2)");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test 5: Verifies Sort fires Sorting and Sorted notifications in correct sequence.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void Sort_FiresSortingAndSortedNotifications()
|
||||
{
|
||||
// Arrange - Use existing subpages from base class
|
||||
var child1 = ContentService.GetById(Subpage.Id)!;
|
||||
var child2 = ContentService.GetById(Subpage2.Id)!;
|
||||
var child3 = ContentService.GetById(Subpage3.Id)!;
|
||||
|
||||
// v1.2: Verify initial sort order assumption
|
||||
Assert.That(child1.SortOrder, Is.LessThan(child2.SortOrder), "Setup: child1 before child2");
|
||||
Assert.That(child2.SortOrder, Is.LessThan(child3.SortOrder), "Setup: child2 before child3");
|
||||
|
||||
var reorderedItems = new[] { child3, child2, child1 };
|
||||
|
||||
// Clear notification tracking
|
||||
RefactoringTestNotificationHandler.Reset();
|
||||
|
||||
// Act
|
||||
var result = ContentService.Sort(reorderedItems);
|
||||
|
||||
// Assert
|
||||
Assert.That(result.Success, Is.True, "Sort should succeed");
|
||||
|
||||
var notifications = RefactoringTestNotificationHandler.NotificationOrder;
|
||||
|
||||
// Verify both sorting notifications fire
|
||||
Assert.That(notifications, Does.Contain(nameof(ContentSortingNotification)),
|
||||
"Sorting notification should fire");
|
||||
Assert.That(notifications, Does.Contain(nameof(ContentSortedNotification)),
|
||||
"Sorted notification should fire");
|
||||
|
||||
// Also verify Saving/Saved fire (Sort saves content)
|
||||
Assert.That(notifications, Does.Contain(nameof(ContentSavingNotification)),
|
||||
"Saving notification should fire during sort");
|
||||
Assert.That(notifications, Does.Contain(nameof(ContentSavedNotification)),
|
||||
"Saved notification should fire during sort");
|
||||
|
||||
// Verify order: Sorting -> Saving -> Saved -> Sorted
|
||||
var sortingIndex = notifications.IndexOf(nameof(ContentSortingNotification));
|
||||
var sortedIndex = notifications.IndexOf(nameof(ContentSortedNotification));
|
||||
|
||||
Assert.That(sortingIndex, Is.LessThan(sortedIndex),
|
||||
"Sorting should fire before Sorted");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region DeleteOfType Tests
|
||||
|
||||
/// <summary>
|
||||
/// Test 6: Verifies DeleteOfType with hierarchical content deletes everything correctly.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void DeleteOfType_MovesDescendantsToRecycleBinFirst()
|
||||
{
|
||||
// Arrange - Create a second content type for descendants
|
||||
var template = FileService.GetTemplate("defaultTemplate");
|
||||
Assert.That(template, Is.Not.Null, "Default template must exist for test setup");
|
||||
var childContentType = ContentTypeBuilder.CreateSimpleContentType(
|
||||
"childType", "Child Type", defaultTemplateId: template!.Id);
|
||||
ContentTypeService.Save(childContentType);
|
||||
|
||||
// Create parent of target type
|
||||
var parent = ContentBuilder.CreateSimpleContent(ContentType, "ParentToDelete", -1);
|
||||
ContentService.Save(parent);
|
||||
|
||||
// Create child of different type (should be moved to bin, not deleted)
|
||||
var childOfDifferentType = ContentBuilder.CreateSimpleContent(childContentType, "ChildDifferentType", parent.Id);
|
||||
ContentService.Save(childOfDifferentType);
|
||||
|
||||
// Create child of same type (should be deleted)
|
||||
var childOfSameType = ContentBuilder.CreateSimpleContent(ContentType, "ChildSameType", parent.Id);
|
||||
ContentService.Save(childOfSameType);
|
||||
|
||||
var parentId = parent.Id;
|
||||
var childDiffId = childOfDifferentType.Id;
|
||||
var childSameId = childOfSameType.Id;
|
||||
|
||||
// Act
|
||||
ContentService.DeleteOfType(ContentType.Id);
|
||||
|
||||
// Assert
|
||||
// Parent should be deleted (it's the target type)
|
||||
var deletedParent = ContentService.GetById(parentId);
|
||||
Assert.That(deletedParent, Is.Null, "Parent of target type should be deleted");
|
||||
|
||||
// Child of same type should be deleted
|
||||
var deletedChildSame = ContentService.GetById(childSameId);
|
||||
Assert.That(deletedChildSame, Is.Null, "Child of same type should be deleted");
|
||||
|
||||
// Child of different type should be in recycle bin
|
||||
var trashedChild = ContentService.GetById(childDiffId);
|
||||
Assert.That(trashedChild, Is.Not.Null, "Child of different type should still exist");
|
||||
Assert.That(trashedChild!.Trashed, Is.True, "Child of different type should be in recycle bin");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test 7: Verifies DeleteOfType only deletes content of the specified type.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void DeleteOfType_WithMixedTypes_OnlyDeletesSpecifiedType()
|
||||
{
|
||||
// Arrange - Create a second content type
|
||||
var template = FileService.GetTemplate("defaultTemplate");
|
||||
Assert.That(template, Is.Not.Null, "Default template must exist for test setup");
|
||||
var otherContentType = ContentTypeBuilder.CreateSimpleContentType(
|
||||
"otherType", "Other Type", defaultTemplateId: template!.Id);
|
||||
ContentTypeService.Save(otherContentType);
|
||||
|
||||
// Create content of target type
|
||||
var targetContent1 = ContentBuilder.CreateSimpleContent(ContentType, "Target1", -1);
|
||||
var targetContent2 = ContentBuilder.CreateSimpleContent(ContentType, "Target2", -1);
|
||||
ContentService.Save(targetContent1);
|
||||
ContentService.Save(targetContent2);
|
||||
|
||||
// Create content of other type (should survive)
|
||||
var otherContent = ContentBuilder.CreateSimpleContent(otherContentType, "Other", -1);
|
||||
ContentService.Save(otherContent);
|
||||
|
||||
var target1Id = targetContent1.Id;
|
||||
var target2Id = targetContent2.Id;
|
||||
var otherId = otherContent.Id;
|
||||
|
||||
// Act
|
||||
ContentService.DeleteOfType(ContentType.Id);
|
||||
|
||||
// Assert
|
||||
Assert.That(ContentService.GetById(target1Id), Is.Null, "Target1 should be deleted");
|
||||
Assert.That(ContentService.GetById(target2Id), Is.Null, "Target2 should be deleted");
|
||||
Assert.That(ContentService.GetById(otherId), Is.Not.Null, "Other type content should survive");
|
||||
Assert.That(ContentService.GetById(otherId)!.Trashed, Is.False, "Other type content should not be trashed");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test 8: Verifies DeleteOfTypes deletes multiple content types in a single operation.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void DeleteOfTypes_DeletesMultipleTypesAtOnce()
|
||||
{
|
||||
// Arrange - Create additional content types
|
||||
var template = FileService.GetTemplate("defaultTemplate");
|
||||
Assert.That(template, Is.Not.Null, "Default template must exist for test setup");
|
||||
|
||||
var type1 = ContentTypeBuilder.CreateSimpleContentType(
|
||||
"deleteType1", "Delete Type 1", defaultTemplateId: template!.Id);
|
||||
var type2 = ContentTypeBuilder.CreateSimpleContentType(
|
||||
"deleteType2", "Delete Type 2", defaultTemplateId: template.Id);
|
||||
var survivorType = ContentTypeBuilder.CreateSimpleContentType(
|
||||
"survivorType", "Survivor Type", defaultTemplateId: template.Id);
|
||||
|
||||
ContentTypeService.Save(type1);
|
||||
ContentTypeService.Save(type2);
|
||||
ContentTypeService.Save(survivorType);
|
||||
|
||||
// Create content of each type
|
||||
var content1 = ContentBuilder.CreateSimpleContent(type1, "Content1", -1);
|
||||
var content2 = ContentBuilder.CreateSimpleContent(type2, "Content2", -1);
|
||||
var survivor = ContentBuilder.CreateSimpleContent(survivorType, "Survivor", -1);
|
||||
|
||||
ContentService.Save(content1);
|
||||
ContentService.Save(content2);
|
||||
ContentService.Save(survivor);
|
||||
|
||||
var content1Id = content1.Id;
|
||||
var content2Id = content2.Id;
|
||||
var survivorId = survivor.Id;
|
||||
|
||||
// Act - Delete multiple types
|
||||
ContentService.DeleteOfTypes(new[] { type1.Id, type2.Id });
|
||||
|
||||
// Assert
|
||||
Assert.That(ContentService.GetById(content1Id), Is.Null, "Content of type1 should be deleted");
|
||||
Assert.That(ContentService.GetById(content2Id), Is.Null, "Content of type2 should be deleted");
|
||||
Assert.That(ContentService.GetById(survivorId), Is.Not.Null, "Content of survivor type should exist");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Permission Tests
|
||||
|
||||
/// <summary>
|
||||
/// Test 9: Verifies SetPermission assigns a permission and GetPermissions retrieves it.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task SetPermission_AssignsPermissionToUserGroup()
|
||||
{
|
||||
// Arrange
|
||||
var content = ContentBuilder.CreateSimpleContent(ContentType, "PermissionTest", -1);
|
||||
ContentService.Save(content);
|
||||
|
||||
// Get admin user group ID (should always exist)
|
||||
var adminGroup = await UserGroupService.GetAsync(Constants.Security.AdminGroupAlias);
|
||||
Assert.That(adminGroup, Is.Not.Null, "Admin group should exist");
|
||||
|
||||
// Act - Assign browse permission ('F' is typically the Browse Node permission)
|
||||
ContentService.SetPermission(content, "F", new[] { adminGroup!.Id });
|
||||
|
||||
// Assert
|
||||
var permissions = ContentService.GetPermissions(content);
|
||||
Assert.That(permissions, Is.Not.Null, "Permissions should be returned");
|
||||
|
||||
var adminPermissions = permissions.FirstOrDefault(p => p.UserGroupId == adminGroup.Id);
|
||||
Assert.That(adminPermissions, Is.Not.Null, "Should have permissions for admin group");
|
||||
Assert.That(adminPermissions!.AssignedPermissions, Does.Contain("F"),
|
||||
"Admin group should have Browse permission");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test 10: Verifies multiple SetPermission calls accumulate permissions for a user group.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// v1.2: Expected behavior documentation -
|
||||
/// SetPermission assigns permissions per-permission-type, not per-entity.
|
||||
/// Calling SetPermission("F", ...) then SetPermission("U", ...) results in both F and U
|
||||
/// permissions being assigned. Each call only replaces permissions of the same type.
|
||||
/// </remarks>
|
||||
[Test]
|
||||
public async Task SetPermission_MultiplePermissionsForSameGroup()
|
||||
{
|
||||
// Arrange
|
||||
var content = ContentBuilder.CreateSimpleContent(ContentType, "MultiPermissionTest", -1);
|
||||
ContentService.Save(content);
|
||||
|
||||
var adminGroup = (await UserGroupService.GetAsync(Constants.Security.AdminGroupAlias))!;
|
||||
|
||||
// Act - Assign multiple permissions
|
||||
ContentService.SetPermission(content, "F", new[] { adminGroup.Id }); // Browse
|
||||
ContentService.SetPermission(content, "U", new[] { adminGroup.Id }); // Update
|
||||
|
||||
// Assert
|
||||
var permissions = ContentService.GetPermissions(content);
|
||||
var adminPermissions = permissions.FirstOrDefault(p => p.UserGroupId == adminGroup.Id);
|
||||
|
||||
Assert.That(adminPermissions, Is.Not.Null, "Should have permissions for admin group");
|
||||
Assert.That(adminPermissions!.AssignedPermissions, Does.Contain("F"), "Should have Browse permission");
|
||||
Assert.That(adminPermissions.AssignedPermissions, Does.Contain("U"), "Should have Update permission");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test 11: Verifies SetPermissions assigns a complete permission set.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task SetPermissions_AssignsPermissionSet()
|
||||
{
|
||||
// Arrange
|
||||
var content = ContentBuilder.CreateSimpleContent(ContentType, "PermissionSetTest", -1);
|
||||
ContentService.Save(content);
|
||||
|
||||
var adminGroup = (await UserGroupService.GetAsync(Constants.Security.AdminGroupAlias))!;
|
||||
|
||||
// Create permission set
|
||||
var permissionSet = new EntityPermissionSet(
|
||||
content.Id,
|
||||
new EntityPermissionCollection(new[]
|
||||
{
|
||||
new EntityPermission(adminGroup.Id, content.Id, new HashSet<string> { "F", "U", "P" }) // Browse, Update, Publish
|
||||
}));
|
||||
|
||||
// Act
|
||||
ContentService.SetPermissions(permissionSet);
|
||||
|
||||
// Assert
|
||||
var permissions = ContentService.GetPermissions(content);
|
||||
var adminPermissions = permissions.FirstOrDefault(p => p.UserGroupId == adminGroup.Id);
|
||||
|
||||
Assert.That(adminPermissions, Is.Not.Null, "Should have permissions for admin group");
|
||||
Assert.That(adminPermissions!.AssignedPermissions, Does.Contain("F"), "Should have Browse permission");
|
||||
Assert.That(adminPermissions.AssignedPermissions, Does.Contain("U"), "Should have Update permission");
|
||||
Assert.That(adminPermissions.AssignedPermissions, Does.Contain("P"), "Should have Publish permission");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test 12: Verifies SetPermission can assign to multiple user groups simultaneously.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task SetPermission_AssignsToMultipleUserGroups()
|
||||
{
|
||||
// Arrange
|
||||
var content = ContentBuilder.CreateSimpleContent(ContentType, "MultiGroupTest", -1);
|
||||
ContentService.Save(content);
|
||||
|
||||
var adminGroup = (await UserGroupService.GetAsync(Constants.Security.AdminGroupAlias))!;
|
||||
var editorGroup = (await UserGroupService.GetAsync(Constants.Security.EditorGroupKey))!;
|
||||
|
||||
// Act - Assign permission to multiple groups at once
|
||||
ContentService.SetPermission(content, "F", new[] { adminGroup.Id, editorGroup.Id });
|
||||
|
||||
// Assert
|
||||
var permissions = ContentService.GetPermissions(content);
|
||||
|
||||
var adminPermissions = permissions.FirstOrDefault(p => p.UserGroupId == adminGroup.Id);
|
||||
var editorPermissions = permissions.FirstOrDefault(p => p.UserGroupId == editorGroup.Id);
|
||||
|
||||
Assert.That(adminPermissions, Is.Not.Null, "Should have permissions for admin group");
|
||||
Assert.That(adminPermissions!.AssignedPermissions, Does.Contain("F"), "Admin should have Browse permission");
|
||||
|
||||
Assert.That(editorPermissions, Is.Not.Null, "Should have permissions for editor group");
|
||||
Assert.That(editorPermissions!.AssignedPermissions, Does.Contain("F"), "Editor should have Browse permission");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Transaction Boundary Tests
|
||||
|
||||
/// <summary>
|
||||
/// Test 13: Verifies that multiple operations within an uncompleted scope all roll back together.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void AmbientScope_NestedOperationsShareTransaction()
|
||||
{
|
||||
// Arrange
|
||||
var content1 = ContentBuilder.CreateSimpleContent(ContentType, "RollbackTest1", -1);
|
||||
var content2 = ContentBuilder.CreateSimpleContent(ContentType, "RollbackTest2", -1);
|
||||
|
||||
// Act - Create scope, save content, but don't complete the scope
|
||||
using (var scope = ScopeProvider.CreateScope())
|
||||
{
|
||||
ContentService.Save(content1);
|
||||
ContentService.Save(content2);
|
||||
|
||||
// Verify content has IDs (was saved within transaction)
|
||||
Assert.That(content1.Id, Is.GreaterThan(0), "Content1 should have an ID");
|
||||
Assert.That(content2.Id, Is.GreaterThan(0), "Content2 should have an ID");
|
||||
|
||||
// v1.2: Note - IDs are captured for debugging but cannot be used after rollback
|
||||
// since they were assigned within the rolled-back transaction
|
||||
var id1 = content1.Id;
|
||||
var id2 = content2.Id;
|
||||
|
||||
// DON'T call scope.Complete() - should roll back
|
||||
}
|
||||
|
||||
// Assert - Content should not exist after rollback
|
||||
// We can't use the IDs because they were assigned in the rolled-back transaction
|
||||
// Instead, search by name
|
||||
var foundContent = ContentService.GetRootContent()
|
||||
.Where(c => c.Name == "RollbackTest1" || c.Name == "RollbackTest2")
|
||||
.ToList();
|
||||
|
||||
Assert.That(foundContent, Is.Empty, "Content should not exist after transaction rollback");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test 14: Verifies that multiple operations within a completed scope all commit together.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void AmbientScope_CompletedScopeCommitsAllOperations()
|
||||
{
|
||||
// Arrange
|
||||
var content1 = ContentBuilder.CreateSimpleContent(ContentType, "CommitTest1", -1);
|
||||
var content2 = ContentBuilder.CreateSimpleContent(ContentType, "CommitTest2", -1);
|
||||
int id1, id2;
|
||||
|
||||
// Act - Create scope, save content, and complete the scope
|
||||
using (var scope = ScopeProvider.CreateScope())
|
||||
{
|
||||
ContentService.Save(content1);
|
||||
ContentService.Save(content2);
|
||||
|
||||
id1 = content1.Id;
|
||||
id2 = content2.Id;
|
||||
|
||||
scope.Complete(); // Commit transaction
|
||||
}
|
||||
|
||||
// Assert - Content should exist after commit
|
||||
var retrieved1 = ContentService.GetById(id1);
|
||||
var retrieved2 = ContentService.GetById(id2);
|
||||
|
||||
Assert.That(retrieved1, Is.Not.Null, "Content1 should exist after commit");
|
||||
Assert.That(retrieved2, Is.Not.Null, "Content2 should exist after commit");
|
||||
Assert.That(retrieved1!.Name, Is.EqualTo("CommitTest1"));
|
||||
Assert.That(retrieved2!.Name, Is.EqualTo("CommitTest2"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test 15: Verifies MoveToRecycleBin within an uncompleted scope rolls back completely.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void AmbientScope_MoveToRecycleBinRollsBackCompletely()
|
||||
{
|
||||
// Arrange - Create and save content OUTSIDE the test scope so it persists
|
||||
var content = ContentBuilder.CreateSimpleContent(ContentType, "MoveRollbackTest", -1);
|
||||
ContentService.Save(content);
|
||||
var contentId = content.Id;
|
||||
|
||||
// Verify content exists and is not trashed
|
||||
var beforeMove = ContentService.GetById(contentId);
|
||||
Assert.That(beforeMove, Is.Not.Null, "Content should exist before test");
|
||||
Assert.That(beforeMove!.Trashed, Is.False, "Content should not be trashed before test");
|
||||
|
||||
// Act - Move to recycle bin within an uncompleted scope
|
||||
using (var scope = ScopeProvider.CreateScope())
|
||||
{
|
||||
ContentService.MoveToRecycleBin(content);
|
||||
|
||||
// Verify it's trashed within the transaction
|
||||
var duringMove = ContentService.GetById(contentId);
|
||||
Assert.That(duringMove!.Trashed, Is.True, "Content should be trashed within transaction");
|
||||
|
||||
// DON'T call scope.Complete() - should roll back
|
||||
}
|
||||
|
||||
// Assert - Content should be back to original state after rollback
|
||||
var afterRollback = ContentService.GetById(contentId);
|
||||
Assert.That(afterRollback, Is.Not.Null, "Content should still exist after rollback");
|
||||
Assert.That(afterRollback!.Trashed, Is.False, "Content should not be trashed after rollback");
|
||||
Assert.That(afterRollback.ParentId, Is.EqualTo(-1), "Content should be at root level after rollback");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Phase 1 Tests
|
||||
|
||||
/// <summary>
|
||||
/// Phase 1 Test: Verifies IContentCrudService is registered and resolvable from DI.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void IContentCrudService_CanBeResolvedFromDI()
|
||||
{
|
||||
// Act
|
||||
var crudService = GetRequiredService<IContentCrudService>();
|
||||
|
||||
// Assert
|
||||
Assert.That(crudService, Is.Not.Null);
|
||||
Assert.That(crudService, Is.InstanceOf<ContentCrudService>());
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Phase 2 - Count Method Delegation Tests
|
||||
|
||||
/// <summary>
|
||||
/// Phase 2 Test: Verifies Count() via facade returns same result as direct service call.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void Count_ViaFacade_ReturnsEquivalentResultToDirectService()
|
||||
{
|
||||
// Arrange
|
||||
var queryService = GetRequiredService<IContentQueryOperationService>();
|
||||
|
||||
// Act
|
||||
var facadeCount = ContentService.Count();
|
||||
var directCount = queryService.Count();
|
||||
|
||||
// Assert
|
||||
Assert.That(facadeCount, Is.EqualTo(directCount));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Phase 2 Test: Verifies CountPublished() via facade returns same result as direct service call.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void CountPublished_ViaFacade_ReturnsEquivalentResultToDirectService()
|
||||
{
|
||||
// Arrange
|
||||
var queryService = GetRequiredService<IContentQueryOperationService>();
|
||||
ContentService.Publish(Textpage, new[] { "*" });
|
||||
|
||||
// Act
|
||||
var facadeCount = ContentService.CountPublished();
|
||||
var directCount = queryService.CountPublished();
|
||||
|
||||
// Assert
|
||||
Assert.That(facadeCount, Is.EqualTo(directCount));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Phase 2 Test: Verifies CountChildren() via facade returns same result as direct service call.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void CountChildren_ViaFacade_ReturnsEquivalentResultToDirectService()
|
||||
{
|
||||
// Arrange
|
||||
var queryService = GetRequiredService<IContentQueryOperationService>();
|
||||
var parentId = Textpage.Id;
|
||||
|
||||
// Act
|
||||
var facadeCount = ContentService.CountChildren(parentId);
|
||||
var directCount = queryService.CountChildren(parentId);
|
||||
|
||||
// Assert
|
||||
Assert.That(facadeCount, Is.EqualTo(directCount));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Phase 2 Test: Verifies CountDescendants() via facade returns same result as direct service call.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void CountDescendants_ViaFacade_ReturnsEquivalentResultToDirectService()
|
||||
{
|
||||
// Arrange
|
||||
var queryService = GetRequiredService<IContentQueryOperationService>();
|
||||
var parentId = Textpage.Id;
|
||||
|
||||
// Act
|
||||
var facadeCount = ContentService.CountDescendants(parentId);
|
||||
var directCount = queryService.CountDescendants(parentId);
|
||||
|
||||
// Assert
|
||||
Assert.That(facadeCount, Is.EqualTo(directCount));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Phase 2 Test: Verifies GetByLevel() via facade returns same result as direct service call.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void GetByLevel_ViaFacade_ReturnsEquivalentResultToDirectService()
|
||||
{
|
||||
// Arrange
|
||||
var queryService = GetRequiredService<IContentQueryOperationService>();
|
||||
|
||||
// Act
|
||||
var facadeItems = ContentService.GetByLevel(1).ToList();
|
||||
var directItems = queryService.GetByLevel(1).ToList();
|
||||
|
||||
// Assert
|
||||
Assert.That(facadeItems.Count, Is.EqualTo(directItems.Count));
|
||||
Assert.That(facadeItems.Select(x => x.Id), Is.EquivalentTo(directItems.Select(x => x.Id)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Phase 2 Test: Verifies GetPagedOfType() via facade returns same result as direct service call.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void GetPagedOfType_ViaFacade_ReturnsEquivalentResultToDirectService()
|
||||
{
|
||||
// Arrange
|
||||
var queryService = GetRequiredService<IContentQueryOperationService>();
|
||||
var contentTypeId = ContentType.Id;
|
||||
|
||||
// Act
|
||||
var facadeItems = ContentService.GetPagedOfType(contentTypeId, 0, 10, out var facadeTotal).ToList();
|
||||
var directItems = queryService.GetPagedOfType(contentTypeId, 0, 10, out var directTotal).ToList();
|
||||
|
||||
// Assert
|
||||
Assert.That(facadeTotal, Is.EqualTo(directTotal));
|
||||
Assert.That(facadeItems.Select(x => x.Id), Is.EquivalentTo(directItems.Select(x => x.Id)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Phase 2 Test: Verifies GetPagedOfTypes() via facade returns same result as direct service call.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void GetPagedOfTypes_ViaFacade_ReturnsEquivalentResultToDirectService()
|
||||
{
|
||||
// Arrange
|
||||
var queryService = GetRequiredService<IContentQueryOperationService>();
|
||||
var contentTypeIds = new[] { ContentType.Id };
|
||||
|
||||
// Act
|
||||
var facadeItems = ContentService.GetPagedOfTypes(contentTypeIds, 0, 10, out var facadeTotal, null).ToList();
|
||||
var directItems = queryService.GetPagedOfTypes(contentTypeIds, 0, 10, out var directTotal).ToList();
|
||||
|
||||
// Assert
|
||||
Assert.That(facadeTotal, Is.EqualTo(directTotal));
|
||||
Assert.That(facadeItems.Select(x => x.Id), Is.EquivalentTo(directItems.Select(x => x.Id)));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Notification handler that tracks the order of notifications for test verification.
|
||||
/// </summary>
|
||||
internal sealed class RefactoringTestNotificationHandler :
|
||||
INotificationHandler<ContentSavingNotification>,
|
||||
INotificationHandler<ContentSavedNotification>,
|
||||
INotificationHandler<ContentPublishingNotification>,
|
||||
INotificationHandler<ContentPublishedNotification>,
|
||||
INotificationHandler<ContentUnpublishingNotification>,
|
||||
INotificationHandler<ContentUnpublishedNotification>,
|
||||
INotificationHandler<ContentMovingNotification>,
|
||||
INotificationHandler<ContentMovedNotification>,
|
||||
INotificationHandler<ContentMovingToRecycleBinNotification>,
|
||||
INotificationHandler<ContentMovedToRecycleBinNotification>,
|
||||
INotificationHandler<ContentSortingNotification>,
|
||||
INotificationHandler<ContentSortedNotification>,
|
||||
INotificationHandler<ContentDeletingNotification>,
|
||||
INotificationHandler<ContentDeletedNotification>
|
||||
{
|
||||
private static readonly List<string> _notificationOrder = new();
|
||||
private static readonly object _lock = new();
|
||||
|
||||
public static IReadOnlyList<string> NotificationOrder
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
return _notificationOrder.ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void Reset()
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
_notificationOrder.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
private static void Record(string notificationType)
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
_notificationOrder.Add(notificationType);
|
||||
}
|
||||
}
|
||||
|
||||
public void Handle(ContentSavingNotification notification) => Record(nameof(ContentSavingNotification));
|
||||
public void Handle(ContentSavedNotification notification) => Record(nameof(ContentSavedNotification));
|
||||
public void Handle(ContentPublishingNotification notification) => Record(nameof(ContentPublishingNotification));
|
||||
public void Handle(ContentPublishedNotification notification) => Record(nameof(ContentPublishedNotification));
|
||||
public void Handle(ContentUnpublishingNotification notification) => Record(nameof(ContentUnpublishingNotification));
|
||||
public void Handle(ContentUnpublishedNotification notification) => Record(nameof(ContentUnpublishedNotification));
|
||||
public void Handle(ContentMovingNotification notification) => Record(nameof(ContentMovingNotification));
|
||||
public void Handle(ContentMovedNotification notification) => Record(nameof(ContentMovedNotification));
|
||||
public void Handle(ContentMovingToRecycleBinNotification notification) => Record(nameof(ContentMovingToRecycleBinNotification));
|
||||
public void Handle(ContentMovedToRecycleBinNotification notification) => Record(nameof(ContentMovedToRecycleBinNotification));
|
||||
public void Handle(ContentSortingNotification notification) => Record(nameof(ContentSortingNotification));
|
||||
public void Handle(ContentSortedNotification notification) => Record(nameof(ContentSortedNotification));
|
||||
public void Handle(ContentDeletingNotification notification) => Record(nameof(ContentDeletingNotification));
|
||||
public void Handle(ContentDeletedNotification notification) => Record(nameof(ContentDeletedNotification));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,255 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Cms.Core;
|
||||
using Umbraco.Cms.Core.Events;
|
||||
using Umbraco.Cms.Core.Models;
|
||||
using Umbraco.Cms.Core.Notifications;
|
||||
using Umbraco.Cms.Core.Persistence.Querying;
|
||||
using Umbraco.Cms.Core.Persistence.Repositories;
|
||||
using Umbraco.Cms.Core.Scoping;
|
||||
using Umbraco.Cms.Core.Services;
|
||||
using Umbraco.Cms.Core.Services.OperationStatus;
|
||||
using Umbraco.Extensions;
|
||||
using IsolationLevel = System.Data.IsolationLevel;
|
||||
|
||||
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Services;
|
||||
|
||||
[TestFixture]
|
||||
[Category("UnitTest")]
|
||||
public class ContentCrudServiceTests
|
||||
{
|
||||
private Mock<ICoreScopeProvider> _scopeProvider = null!;
|
||||
private Mock<ILoggerFactory> _loggerFactory = null!;
|
||||
private Mock<IEventMessagesFactory> _eventMessagesFactory = null!;
|
||||
private Mock<IDocumentRepository> _documentRepository = null!;
|
||||
private Mock<IEntityRepository> _entityRepository = null!;
|
||||
private Mock<IContentTypeRepository> _contentTypeRepository = null!;
|
||||
private Mock<IAuditService> _auditService = null!;
|
||||
private Mock<IUserIdKeyResolver> _userIdKeyResolver = null!;
|
||||
private Mock<ILanguageRepository> _languageRepository = null!;
|
||||
private ContentCrudService _sut = null!;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
_scopeProvider = new Mock<ICoreScopeProvider>();
|
||||
_loggerFactory = new Mock<ILoggerFactory>();
|
||||
_eventMessagesFactory = new Mock<IEventMessagesFactory>();
|
||||
_documentRepository = new Mock<IDocumentRepository>();
|
||||
_entityRepository = new Mock<IEntityRepository>();
|
||||
_contentTypeRepository = new Mock<IContentTypeRepository>();
|
||||
_auditService = new Mock<IAuditService>();
|
||||
_userIdKeyResolver = new Mock<IUserIdKeyResolver>();
|
||||
_languageRepository = new Mock<ILanguageRepository>();
|
||||
|
||||
// Setup logger factory to return a mock logger
|
||||
_loggerFactory.Setup(x => x.CreateLogger(It.IsAny<string>()))
|
||||
.Returns(Mock.Of<ILogger>());
|
||||
|
||||
// Setup event messages factory
|
||||
_eventMessagesFactory.Setup(x => x.Get())
|
||||
.Returns(new EventMessages());
|
||||
|
||||
// Setup CreateQuery for Query<T>() calls
|
||||
_scopeProvider.Setup(x => x.CreateQuery<IContentType>())
|
||||
.Returns(Mock.Of<IQuery<IContentType>>());
|
||||
_scopeProvider.Setup(x => x.CreateQuery<IContent>())
|
||||
.Returns(Mock.Of<IQuery<IContent>>());
|
||||
|
||||
_sut = new ContentCrudService(
|
||||
_scopeProvider.Object,
|
||||
_loggerFactory.Object,
|
||||
_eventMessagesFactory.Object,
|
||||
_documentRepository.Object,
|
||||
_entityRepository.Object,
|
||||
_contentTypeRepository.Object,
|
||||
_auditService.Object,
|
||||
_userIdKeyResolver.Object,
|
||||
_languageRepository.Object);
|
||||
}
|
||||
|
||||
#region Mock Setup Helpers
|
||||
|
||||
/// <summary>
|
||||
/// Creates a mock scope configured for read operations.
|
||||
/// </summary>
|
||||
private ICoreScope CreateMockScopeWithReadLock()
|
||||
{
|
||||
var scope = new Mock<ICoreScope>();
|
||||
scope.Setup(x => x.ReadLock(It.IsAny<int[]>()));
|
||||
scope.Setup(x => x.Complete());
|
||||
_scopeProvider.Setup(x => x.CreateCoreScope(
|
||||
It.IsAny<IsolationLevel>(),
|
||||
It.IsAny<RepositoryCacheMode>(),
|
||||
It.IsAny<IEventDispatcher?>(),
|
||||
It.IsAny<IScopedNotificationPublisher?>(),
|
||||
It.IsAny<bool?>(),
|
||||
It.IsAny<bool>(),
|
||||
It.IsAny<bool>()))
|
||||
.Returns(scope.Object);
|
||||
return scope.Object;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a mock scope configured for write operations.
|
||||
/// </summary>
|
||||
private ICoreScope CreateMockScopeWithWriteLock()
|
||||
{
|
||||
var scope = CreateMockScopeWithReadLock();
|
||||
Mock.Get(scope).Setup(x => x.WriteLock(It.IsAny<int[]>()));
|
||||
|
||||
var notificationPublisher = new Mock<IScopedNotificationPublisher>();
|
||||
notificationPublisher.Setup(x => x.Publish(It.IsAny<INotification>()));
|
||||
notificationPublisher.Setup(x => x.PublishCancelable(It.IsAny<ICancelableNotification>())).Returns(false);
|
||||
|
||||
Mock.Get(scope).Setup(x => x.Notifications).Returns(notificationPublisher.Object);
|
||||
return scope;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
[Test]
|
||||
public void Constructor_WithValidDependencies_CreatesInstance()
|
||||
{
|
||||
// Assert
|
||||
Assert.That(_sut, Is.Not.Null);
|
||||
Assert.That(_sut, Is.InstanceOf<IContentCrudService>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Create_WithInvalidParentId_ThrowsArgumentException()
|
||||
{
|
||||
// Arrange
|
||||
CreateMockScopeWithReadLock();
|
||||
var contentType = Mock.Of<IContentType>(x => x.Alias == "testType");
|
||||
_contentTypeRepository.Setup(x => x.Get(It.IsAny<IQuery<IContentType>>()))
|
||||
.Returns(new[] { contentType });
|
||||
_documentRepository.Setup(x => x.Get(999)).Returns((IContent?)null);
|
||||
|
||||
// Act & Assert
|
||||
Assert.Throws<ArgumentException>(() =>
|
||||
_sut.Create("Test", 999, "testType"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Create_WithNonExistentContentType_ThrowsException()
|
||||
{
|
||||
// Arrange
|
||||
CreateMockScopeWithReadLock();
|
||||
_contentTypeRepository.Setup(x => x.Get(It.IsAny<IQuery<IContentType>>()))
|
||||
.Returns(Enumerable.Empty<IContentType>());
|
||||
|
||||
// Act & Assert
|
||||
// Note: Throws generic Exception to match original ContentService behavior
|
||||
Assert.Throws<Exception>(() =>
|
||||
_sut.Create("Test", Constants.System.Root, "nonExistentType"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetById_WithNonExistentId_ReturnsNull()
|
||||
{
|
||||
// Arrange
|
||||
CreateMockScopeWithReadLock();
|
||||
_documentRepository.Setup(x => x.Get(999)).Returns((IContent?)null);
|
||||
|
||||
// Act
|
||||
var result = _sut.GetById(999);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Is.Null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Save_WithEmptyCollection_ReturnsSuccessWithoutCallingRepository()
|
||||
{
|
||||
// Arrange
|
||||
CreateMockScopeWithWriteLock();
|
||||
|
||||
// Act
|
||||
var result = _sut.Save(Enumerable.Empty<IContent>());
|
||||
|
||||
// Assert
|
||||
Assert.That(result.Success, Is.True);
|
||||
_documentRepository.Verify(x => x.Save(It.IsAny<IContent>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Exists_WithExistingId_ReturnsTrue()
|
||||
{
|
||||
// Arrange
|
||||
CreateMockScopeWithReadLock();
|
||||
_documentRepository.Setup(x => x.Exists(123)).Returns(true);
|
||||
|
||||
// Act
|
||||
var result = _sut.Exists(123);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void HasChildren_WithNoChildren_ReturnsFalse()
|
||||
{
|
||||
// Arrange
|
||||
CreateMockScopeWithReadLock();
|
||||
_documentRepository.Setup(x => x.Count(It.IsAny<IQuery<IContent>>())).Returns(0);
|
||||
|
||||
// Act
|
||||
var result = _sut.HasChildren(123);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Is.False);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Save_WithVariantContent_CallsLanguageRepository()
|
||||
{
|
||||
// Arrange
|
||||
var scope = CreateMockScopeWithWriteLock();
|
||||
|
||||
var contentType = new Mock<ISimpleContentType>();
|
||||
contentType.Setup(x => x.Variations).Returns(ContentVariation.Culture);
|
||||
|
||||
// Use real ContentCultureInfos instance instead of mocking
|
||||
var cultureInfo = new ContentCultureInfos("en-US");
|
||||
cultureInfo.Name = "Test Name";
|
||||
|
||||
// Use real ContentCultureInfosCollection instead of mocking
|
||||
var cultureInfosCollection = new ContentCultureInfosCollection();
|
||||
cultureInfosCollection.Add(cultureInfo);
|
||||
|
||||
var content = new Mock<IContent>();
|
||||
content.Setup(x => x.ContentType).Returns(contentType.Object);
|
||||
content.Setup(x => x.CultureInfos).Returns(cultureInfosCollection);
|
||||
content.Setup(x => x.HasIdentity).Returns(true);
|
||||
content.Setup(x => x.PublishedState).Returns(PublishedState.Unpublished);
|
||||
content.Setup(x => x.Name).Returns("Test");
|
||||
content.Setup(x => x.Id).Returns(123);
|
||||
|
||||
// Setup language repository to return languages
|
||||
var language = new Mock<ILanguage>();
|
||||
language.Setup(x => x.IsoCode).Returns("en-US");
|
||||
_languageRepository.Setup(x => x.GetMany()).Returns(new[] { language.Object });
|
||||
|
||||
// Setup async methods for audit
|
||||
_userIdKeyResolver.Setup(x => x.GetAsync(It.IsAny<int>()))
|
||||
.ReturnsAsync(Guid.NewGuid());
|
||||
_auditService.Setup(x => x.AddAsync(
|
||||
It.IsAny<AuditType>(),
|
||||
It.IsAny<Guid>(),
|
||||
It.IsAny<int>(),
|
||||
It.IsAny<string>(),
|
||||
It.IsAny<string?>(),
|
||||
It.IsAny<string?>()))
|
||||
.ReturnsAsync(Attempt.Succeed(AuditLogOperationStatus.Success));
|
||||
|
||||
// Act
|
||||
var result = _sut.Save(content.Object);
|
||||
|
||||
// Assert
|
||||
Assert.That(result.Success, Is.True);
|
||||
_documentRepository.Verify(x => x.Save(content.Object), Times.Once);
|
||||
_languageRepository.Verify(x => x.GetMany(), Times.Once);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
// tests/Umbraco.Tests.UnitTests/Umbraco.Core/Services/ContentQueryOperationServiceInterfaceTests.cs
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Cms.Core.Services;
|
||||
|
||||
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Services;
|
||||
|
||||
[TestFixture]
|
||||
public class ContentQueryOperationServiceInterfaceTests
|
||||
{
|
||||
[Test]
|
||||
public void IContentQueryOperationService_Interface_Exists()
|
||||
{
|
||||
// Arrange & Act
|
||||
var interfaceType = typeof(IContentQueryOperationService);
|
||||
|
||||
// Assert
|
||||
Assert.That(interfaceType, Is.Not.Null);
|
||||
Assert.That(interfaceType.IsInterface, Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IContentQueryOperationService_Extends_IService()
|
||||
{
|
||||
// Arrange
|
||||
var interfaceType = typeof(IContentQueryOperationService);
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(typeof(IService).IsAssignableFrom(interfaceType), Is.True);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,231 @@
|
||||
// Copyright (c) Umbraco.
|
||||
// See LICENSE for more details.
|
||||
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Cms.Core.Events;
|
||||
using Umbraco.Cms.Core.Models;
|
||||
using Umbraco.Cms.Core.Persistence.Repositories;
|
||||
using Umbraco.Cms.Core.Scoping;
|
||||
using Umbraco.Cms.Core.Services;
|
||||
|
||||
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Unit tests for ContentServiceBase (shared infrastructure for extracted services).
|
||||
/// These tests establish the expected contract for the base class before it's created.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// ContentServiceBase will be created in Phase 1. These tests validate the design requirements:
|
||||
/// - Audit helper method behavior
|
||||
/// - Scope provider access patterns
|
||||
/// - Logger injection patterns
|
||||
/// </remarks>
|
||||
[TestFixture]
|
||||
public class ContentServiceBaseTests
|
||||
{
|
||||
// Note: These tests will be uncommented when ContentServiceBase is created in Phase 1.
|
||||
// For now, they serve as documentation of the expected behavior.
|
||||
|
||||
/*
|
||||
private Mock<ICoreScopeProvider> _scopeProviderMock;
|
||||
private Mock<IAuditService> _auditServiceMock;
|
||||
private Mock<IEventMessagesFactory> _eventMessagesFactoryMock;
|
||||
private Mock<ILogger<TestContentService>> _loggerMock;
|
||||
private TestContentService _service;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_scopeProviderMock = new Mock<ICoreScopeProvider>();
|
||||
_auditServiceMock = new Mock<IAuditService>();
|
||||
_eventMessagesFactoryMock = new Mock<IEventMessagesFactory>();
|
||||
_loggerMock = new Mock<ILogger<TestContentService>>();
|
||||
|
||||
_eventMessagesFactoryMock.Setup(x => x.Get()).Returns(new EventMessages());
|
||||
|
||||
_service = new TestContentService(
|
||||
_scopeProviderMock.Object,
|
||||
_auditServiceMock.Object,
|
||||
_eventMessagesFactoryMock.Object,
|
||||
_loggerMock.Object);
|
||||
}
|
||||
|
||||
#region Audit Helper Method Tests
|
||||
|
||||
[Test]
|
||||
public void Audit_WithValidParameters_CreatesAuditEntry()
|
||||
{
|
||||
// Arrange
|
||||
var userId = 1;
|
||||
var objectId = 100;
|
||||
var message = "Test audit message";
|
||||
|
||||
// Act
|
||||
_service.TestAudit(AuditType.Save, userId, objectId, message);
|
||||
|
||||
// Assert
|
||||
_auditServiceMock.Verify(x => x.Write(
|
||||
userId,
|
||||
message,
|
||||
It.IsAny<string>(),
|
||||
objectId), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Audit_WithNullMessage_UsesDefaultMessage()
|
||||
{
|
||||
// Arrange
|
||||
var userId = 1;
|
||||
var objectId = 100;
|
||||
|
||||
// Act
|
||||
_service.TestAudit(AuditType.Save, userId, objectId, null);
|
||||
|
||||
// Assert
|
||||
_auditServiceMock.Verify(x => x.Write(
|
||||
userId,
|
||||
It.Is<string>(s => !string.IsNullOrEmpty(s)),
|
||||
It.IsAny<string>(),
|
||||
objectId), Times.Once);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Scope Provider Access Pattern Tests
|
||||
|
||||
[Test]
|
||||
public void CreateScope_ReturnsValidCoreScope()
|
||||
{
|
||||
// Arrange
|
||||
var scopeMock = new Mock<ICoreScope>();
|
||||
_scopeProviderMock.Setup(x => x.CreateCoreScope(
|
||||
It.IsAny<IsolationLevel>(),
|
||||
It.IsAny<RepositoryCacheMode>(),
|
||||
It.IsAny<IEventDispatcher>(),
|
||||
It.IsAny<IScopedNotificationPublisher>(),
|
||||
It.IsAny<bool>(),
|
||||
It.IsAny<bool>(),
|
||||
It.IsAny<bool>()))
|
||||
.Returns(scopeMock.Object);
|
||||
|
||||
// Act
|
||||
var scope = _service.TestCreateScope();
|
||||
|
||||
// Assert
|
||||
Assert.That(scope, Is.Not.Null);
|
||||
_scopeProviderMock.Verify(x => x.CreateCoreScope(
|
||||
It.IsAny<IsolationLevel>(),
|
||||
It.IsAny<RepositoryCacheMode>(),
|
||||
It.IsAny<IEventDispatcher>(),
|
||||
It.IsAny<IScopedNotificationPublisher>(),
|
||||
It.IsAny<bool>(),
|
||||
It.IsAny<bool>(),
|
||||
It.IsAny<bool>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CreateScope_WithAmbientScope_ReusesExisting()
|
||||
{
|
||||
// Arrange
|
||||
var ambientScopeMock = new Mock<ICoreScope>();
|
||||
_scopeProviderMock.SetupGet(x => x.AmbientScope).Returns(ambientScopeMock.Object);
|
||||
|
||||
// When ambient scope exists, CreateCoreScope should still be called
|
||||
// but the scope provider handles the nesting
|
||||
_scopeProviderMock.Setup(x => x.CreateCoreScope(
|
||||
It.IsAny<IsolationLevel>(),
|
||||
It.IsAny<RepositoryCacheMode>(),
|
||||
It.IsAny<IEventDispatcher>(),
|
||||
It.IsAny<IScopedNotificationPublisher>(),
|
||||
It.IsAny<bool>(),
|
||||
It.IsAny<bool>(),
|
||||
It.IsAny<bool>()))
|
||||
.Returns(ambientScopeMock.Object);
|
||||
|
||||
// Act
|
||||
var scope = _service.TestCreateScope();
|
||||
|
||||
// Assert - scope should be the ambient scope (or nested in it)
|
||||
Assert.That(scope, Is.Not.Null);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Logger Injection Tests
|
||||
|
||||
[Test]
|
||||
public void Logger_IsInjectedCorrectly()
|
||||
{
|
||||
// Assert
|
||||
Assert.That(_service.TestLogger, Is.Not.Null);
|
||||
Assert.That(_service.TestLogger, Is.EqualTo(_loggerMock.Object));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Logger_UsesCorrectCategoryName()
|
||||
{
|
||||
// The logger should be typed to the concrete service class
|
||||
// This is verified by the generic type parameter
|
||||
Assert.That(_service.TestLogger, Is.InstanceOf<ILogger<TestContentService>>());
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Repository Access Tests
|
||||
|
||||
[Test]
|
||||
public void DocumentRepository_IsAccessibleWithinScope()
|
||||
{
|
||||
// This test validates that the base class provides access to the document repository
|
||||
// The actual repository access pattern will be tested in integration tests
|
||||
Assert.Pass("Repository access validated in integration tests");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Test implementation of ContentServiceBase for unit testing.
|
||||
/// </summary>
|
||||
private class TestContentService : ContentServiceBase
|
||||
{
|
||||
public TestContentService(
|
||||
ICoreScopeProvider scopeProvider,
|
||||
IAuditService auditService,
|
||||
IEventMessagesFactory eventMessagesFactory,
|
||||
ILogger<TestContentService> logger)
|
||||
: base(scopeProvider, auditService, eventMessagesFactory, logger)
|
||||
{
|
||||
}
|
||||
|
||||
// Expose protected members for testing
|
||||
public void TestAudit(AuditType type, int userId, int objectId, string? message)
|
||||
=> Audit(type, userId, objectId, message);
|
||||
|
||||
public ICoreScope TestCreateScope() => ScopeProvider.CreateCoreScope();
|
||||
|
||||
public ILogger<TestContentService> TestLogger => Logger;
|
||||
}
|
||||
*/
|
||||
|
||||
/// <summary>
|
||||
/// v1.3: Tracking test that fails when ContentServiceBase is created.
|
||||
/// When this test fails, uncomment all tests in this file and delete this placeholder.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void ContentServiceBase_WhenCreated_UncommentTests()
|
||||
{
|
||||
// This tracking test uses reflection to detect when ContentServiceBase is created.
|
||||
// When you see this test fail, it means Phase 1 has created ContentServiceBase.
|
||||
// At that point:
|
||||
// 1. Uncomment all the tests in this file (the commented section above)
|
||||
// 2. Delete this tracking test
|
||||
// 3. Verify all tests pass
|
||||
|
||||
var type = Type.GetType("Umbraco.Cms.Core.Services.ContentServiceBase, Umbraco.Core");
|
||||
|
||||
Assert.That(type, Is.Null,
|
||||
"ContentServiceBase now exists! Uncomment all tests in this file and delete this tracking test.");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
---
|
||||
date: 2025-12-13T04:47:12+00:00
|
||||
researcher: Claude
|
||||
git_commit: 45edc5916b4e2e8e210c2fc9d9d3e6701d3ad218
|
||||
branch: refactor/Utf8ToAsciiConverter
|
||||
repository: Umbraco-CMS
|
||||
topic: "Utf8ToAsciiConverter Refactoring Analysis"
|
||||
tags: [analysis, refactoring, strings, simd, performance]
|
||||
status: complete
|
||||
last_updated: 2025-12-13
|
||||
last_updated_by: Claude
|
||||
type: analysis
|
||||
---
|
||||
|
||||
# Handoff: Utf8ToAsciiConverter Refactoring Analysis
|
||||
|
||||
## Task(s)
|
||||
**Completed:**
|
||||
1. Cyclomatic complexity comparison between original and refactored implementation
|
||||
2. Test count comparison before and after refactoring
|
||||
|
||||
## Critical References
|
||||
- `src/Umbraco.Core/Strings/Utf8ToAsciiConverter.cs` - New SIMD-optimized implementation
|
||||
- `src/Umbraco.Core/Strings/Utf8ToAsciiConverterOriginal.cs` - Original implementation (disabled with `#if false`)
|
||||
- `tests/Umbraco.Tests.UnitTests/Umbraco.Core/Strings/TestData/golden-mappings.json` - 1,308 character mappings for regression testing
|
||||
|
||||
## Recent changes
|
||||
No code changes made in this session - analysis only.
|
||||
|
||||
## Learnings
|
||||
|
||||
### Cyclomatic Complexity Reduction
|
||||
- **Original**: ~287 total complexity (dominated by ~280 in single switch statement with 276 case groups)
|
||||
- **New**: 25 total complexity (distributed across 4 focused methods)
|
||||
- **Reduction**: 91% overall, 97% for maximum method complexity
|
||||
|
||||
### Architectural Changes
|
||||
1. **Switch Statement → Dictionary Lookup**: 3,400-line switch replaced by `FrozenDictionary<char, string>` loaded from JSON
|
||||
2. **Unicode Normalization**: ~180 case groups eliminated by using `NormalizationForm.FormD` for accented Latin characters
|
||||
3. **SIMD Fast Path**: Uses `SearchValues<char>` for vectorized ASCII detection
|
||||
4. **Separation of Concerns**: Logic split into `Convert()`, `ProcessNonAscii()`, `TryNormalize()`
|
||||
|
||||
### Test Coverage Added
|
||||
- **Before**: 0 dedicated tests existed
|
||||
- **After**: 2,649 test cases across 4 test files
|
||||
- Golden file testing validates all 1,308 character mappings from original implementation
|
||||
|
||||
## Artifacts
|
||||
Analysis results documented in conversation - no files created.
|
||||
|
||||
Key files analyzed:
|
||||
- `src/Umbraco.Core/Strings/Utf8ToAsciiConverter.cs:1-209` - New implementation (~210 LOC)
|
||||
- `src/Umbraco.Core/Strings/Utf8ToAsciiConverterOriginal.cs:1-3633` - Original implementation (~3,600 LOC)
|
||||
- `tests/Umbraco.Tests.UnitTests/Umbraco.Core/Strings/Utf8ToAsciiConverterTests.cs` - 30 test cases
|
||||
- `tests/Umbraco.Tests.UnitTests/Umbraco.Core/Strings/Utf8ToAsciiConverterGoldenTests.cs` - 2,616 test cases
|
||||
- `tests/Umbraco.Tests.UnitTests/Umbraco.Core/Strings/Utf8ToAsciiConverterInterfaceTests.cs` - 2 tests
|
||||
- `tests/Umbraco.Tests.UnitTests/Umbraco.Core/Strings/Utf8ToAsciiConverterNormalizationCoverageTests.cs` - 1 analysis test
|
||||
|
||||
## Action Items & Next Steps
|
||||
The refactoring analysis is complete. Potential follow-up:
|
||||
1. Review benchmark results in `docs/benchmarks/utf8-converter-final-2025-11-27.md`
|
||||
2. Consider merging branch to main if all tests pass
|
||||
3. Document normalization coverage findings from `Utf8ToAsciiConverterNormalizationCoverageTests`
|
||||
|
||||
## Other Notes
|
||||
|
||||
### Key Metrics Summary
|
||||
| Metric | Before | After | Change |
|
||||
|--------|--------|-------|--------|
|
||||
| Cyclomatic Complexity | ~287 | 25 | -91% |
|
||||
| Lines of Code | ~3,600 | ~210 | -94% |
|
||||
| Switch Cases | 276 | 0 | -100% |
|
||||
| Test Cases | 0 | 2,649 | +2,649 |
|
||||
|
||||
### Branch Status
|
||||
The branch `refactor/Utf8ToAsciiConverter` contains 16 commits implementing the SIMD-optimized converter with:
|
||||
- Interface abstraction (`IUtf8ToAsciiConverter`)
|
||||
- DI integration via `ICharacterMappingLoader`
|
||||
- Static wrapper for backwards compatibility (`Utf8ToAsciiConverterStatic`)
|
||||
- Comprehensive test suite with golden file validation
|
||||
@@ -0,0 +1,115 @@
|
||||
---
|
||||
date: 2025-12-13T06:23:36+00:00
|
||||
researcher: Claude
|
||||
git_commit: a1184533860623a1636620c78be6151490b0ea77
|
||||
branch: refactor/ContentService
|
||||
repository: Umbraco-CMS
|
||||
topic: "ContentService Refactoring Design Review and Revision"
|
||||
tags: [design-review, refactoring, contentservice, architecture]
|
||||
status: complete
|
||||
last_updated: 2025-12-13
|
||||
last_updated_by: Claude
|
||||
type: implementation_strategy
|
||||
---
|
||||
|
||||
# Handoff: ContentService Refactoring Design Review
|
||||
|
||||
## Task(s)
|
||||
|
||||
| Task | Status |
|
||||
|------|--------|
|
||||
| Review design document for major issues | Completed |
|
||||
| Identify architecture/codebase mismatches | Completed |
|
||||
| Make decisions on 9 major issues | Completed |
|
||||
| Revise design document with corrections | Completed |
|
||||
| Commit updated design | Completed |
|
||||
|
||||
The session focused on critically reviewing `docs/plans/2025-12-04-contentservice-refactoring-design.md` and identifying major issues where the design conflicted with the actual codebase structure.
|
||||
|
||||
## Critical References
|
||||
|
||||
- `docs/plans/2025-12-04-contentservice-refactoring-design.md` - The revised design document (primary artifact)
|
||||
- `src/Umbraco.Core/Services/ContentService.cs` - The 3,823-line god class being refactored
|
||||
- `src/Umbraco.Core/CLAUDE.md` - Core architecture guide with patterns
|
||||
|
||||
## Recent Changes
|
||||
|
||||
- `docs/plans/2025-12-04-contentservice-refactoring-design.md` - Complete revision addressing 9 major issues
|
||||
|
||||
## Learnings
|
||||
|
||||
### Critical Architecture Discovery
|
||||
The original design assumed implementations go in `Umbraco.Infrastructure`, but the actual codebase has:
|
||||
- `ContentService.cs` in `Umbraco.Core/Services/` (not Infrastructure)
|
||||
- `ContentEditingService.cs` in `Umbraco.Core/Services/`
|
||||
- `ContentPublishingService.cs` in `Umbraco.Core/Services/`
|
||||
|
||||
### Existing Service Complexity
|
||||
`ContentPublishingService` already has:
|
||||
- Background task handling via `ILongRunningOperationService`
|
||||
- Schedule management with `ContentScheduleCollection`
|
||||
- `IUmbracoContextFactory` integration
|
||||
|
||||
`ContentEditingService` uses inheritance from `ContentEditingServiceWithSortingBase`, not delegation.
|
||||
|
||||
### Return Type Patterns
|
||||
Three incompatible patterns exist in the codebase:
|
||||
1. Legacy `OperationResult`/`PublishResult` (IContentService)
|
||||
2. Modern `Attempt<TResult, TStatus>` (IContentEditingService)
|
||||
3. Proposed new types (design) - **rejected in favor of reusing existing**
|
||||
|
||||
### Pagination Patterns
|
||||
- Legacy: `pageIndex/pageSize` with `out long totalRecords`
|
||||
- Modern: `PagedModel<T>` containing items and total
|
||||
- Design should use `PagedModel<T>` for new services
|
||||
|
||||
## Artifacts
|
||||
|
||||
Primary artifact produced:
|
||||
- `docs/plans/2025-12-04-contentservice-refactoring-design.md` - Revised design document
|
||||
|
||||
Key sections added/updated:
|
||||
- Lines 22-36: Design Decisions Log (new section documenting all 8 decisions)
|
||||
- Lines 39-123: Revised Architecture section with corrected layer structure
|
||||
- Lines 203-253: Updated `IContentQueryService` with `PagedModel<T>` and complete method list
|
||||
- Lines 255-338: Simplified pipeline components using existing types
|
||||
- Lines 342-389: Corrected file locations (all in Umbraco.Core)
|
||||
|
||||
## Action Items & Next Steps
|
||||
|
||||
1. **Begin Phase 1 Implementation** - Introduce pipeline components:
|
||||
- Create `IPublishingValidator`, `IPublishingExecutor`, `IPublishingStrategy`, `IPublishingNotifier`
|
||||
- Location: `src/Umbraco.Core/Services/Publishing/`
|
||||
- Components only depend on repositories (one-way dependencies)
|
||||
|
||||
2. **Create Phase 1 Implementation Plan** - Run `/superpowers:write-plan` to generate detailed task breakdown for Phase 1
|
||||
|
||||
3. **Set Up Benchmarks** - Create `tests/Umbraco.Tests.Benchmarks/ContentPublishingBenchmarks.cs` to establish baseline before changes
|
||||
|
||||
4. **Integration with ContentPublishingService** - Modify `ContentPublishingService` to use new components internally while keeping public API unchanged
|
||||
|
||||
## Other Notes
|
||||
|
||||
### Key Design Decisions Made
|
||||
|
||||
| # | Issue | Decision |
|
||||
|---|-------|----------|
|
||||
| 1 | Architecture | Implementations in `Umbraco.Core` (match existing) |
|
||||
| 2 | Service relationships | Gradual extraction - components are helpers |
|
||||
| 3 | Dependencies | One-way only - components depend on repositories |
|
||||
| 4 | Async/sync | Query service stays sync |
|
||||
| 5 | Return types | Reuse existing `PublishResult` |
|
||||
| 6 | Pagination | Use `PagedModel<T>` |
|
||||
| 7 | DI registration | Add to existing `UmbracoBuilder.Services.cs` |
|
||||
| 8 | Query capabilities | Pragmatic split |
|
||||
|
||||
### Removed from Original Design
|
||||
- `IContentMutationService` - keep in facades
|
||||
- `IContentTreeService` - keep in facades
|
||||
- `IContentPublishingPipeline` - use individual components instead
|
||||
- New status enums - reuse existing types
|
||||
|
||||
### Important File Locations
|
||||
- Existing services: `src/Umbraco.Core/Services/`
|
||||
- DI registration: `src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.Services.cs`
|
||||
- Test location: `tests/Umbraco.Tests.UnitTests/Umbraco.Core/Services/`
|
||||
@@ -0,0 +1,120 @@
|
||||
---
|
||||
date: 2025-12-14T02:34:25+0000
|
||||
researcher: Claude
|
||||
git_commit: 41ecbd1bc1122c87ee63fb47a732cebe8699a0e2
|
||||
branch: refactor/ContentService
|
||||
repository: Umbraco-CMS
|
||||
topic: "Phase 1 Publishing Pipeline Implementation"
|
||||
tags: [implementation, publishing-pipeline, contentservice-refactoring, subagent-driven-development]
|
||||
status: in_progress
|
||||
last_updated: 2025-12-14
|
||||
last_updated_by: Claude
|
||||
type: implementation_strategy
|
||||
---
|
||||
|
||||
# Handoff: Phase 1 Publishing Pipeline Implementation
|
||||
|
||||
## Task(s)
|
||||
|
||||
Implementing Phase 1 of the ContentService publishing pipeline refactoring using **subagent-driven development**.
|
||||
|
||||
**Plan Document:** `docs/plans/2025-12-13-phase-1-implementation-fixes.md`
|
||||
|
||||
### Task Status (11 total)
|
||||
|
||||
| Task | Description | Status |
|
||||
|------|-------------|--------|
|
||||
| 1 | Update Phase 1 Design with ICultureImpactFactory Dependency | **Completed** |
|
||||
| 2 | Document Pipeline Order Decision | **Completed** |
|
||||
| 3 | Document PublishAction Enum Omission | **Completed** |
|
||||
| 4 | Update IPublishingStrategy Interface | **Completed** |
|
||||
| 5 | Implement PublishingStrategy with Repository | **Completed** (code review passed) |
|
||||
| 6 | Create BatchValidationContext | **Pending** - next up |
|
||||
| 7 | Implement PublishingValidator with Parallel Processing | Pending |
|
||||
| 8 | Implement PublishingExecutor with Repository Batch Operations | Pending |
|
||||
| 9 | Create Integration Tests Comparing Pipeline to Legacy | Pending |
|
||||
| 10 | Update Benchmark to Use .NET 10.0 | Pending |
|
||||
| 11 | Add ContentValidationResult with Factory Methods | Pending |
|
||||
|
||||
**Current Phase:** Task 6 is next
|
||||
|
||||
## Critical References
|
||||
|
||||
1. **Implementation Plan:** `docs/plans/2025-12-13-phase-1-implementation-fixes.md` - The detailed implementation plan with code snippets for each task
|
||||
2. **Design Document:** `docs/plans/2025-12-13-phase-1-publishing-pipeline-design.md` - Phase 1 architectural design
|
||||
3. **Main Design:** `docs/plans/2025-12-04-contentservice-refactoring-design.md` - Overall ContentService refactoring design
|
||||
|
||||
## Recent changes
|
||||
|
||||
- `f1401e8dd5`: docs: add ICultureImpactFactory to Phase 1 validator dependencies
|
||||
- `b7045649c9`: docs: document pipeline order difference for branch publishing
|
||||
- `ca448fd7c2`: docs: document PublishAction enum omission in Phase 1
|
||||
- `a7b5f1d043`: feat(core): add IPublishingStrategy interface
|
||||
- `4fc6c009da`: test(perf): add PublishBranch performance baseline tests
|
||||
- `41ecbd1bc1`: feat(core): implement PublishingStrategy with IDocumentRepository
|
||||
|
||||
## Learnings
|
||||
|
||||
1. **Implementation goes in Infrastructure, not Core**: The plan specified implementation in `Umbraco.Core`, but `ISqlContext` dependency requires implementation in `Umbraco.Infrastructure`. Interface stays in Core, implementation goes to Infrastructure.
|
||||
|
||||
2. **InternalsVisibleTo required**: Added `InternalsVisibleTo` for `Umbraco.Infrastructure` in `Umbraco.Core.csproj` so Infrastructure can access internal types like `PublishingPlan`.
|
||||
|
||||
3. **Baseline performance established**: Legacy `PublishBranch` performance at 50 items = **62.7 items/sec**. Target is 2x = **125+ items/sec**.
|
||||
|
||||
4. **Test mocking pattern**: For `VariesByCulture()` extension method, mock the underlying `Variations` property on `ISimpleContentType`, not the extension method directly.
|
||||
|
||||
5. **ContentType creation in tests**: Don't use `ContentTypeBuilder`. Use direct instantiation: `new ContentType(ShortStringHelper, -1) { Alias = "...", Name = "...", Variations = ContentVariation.Nothing }`
|
||||
|
||||
## Artifacts
|
||||
|
||||
**Created/Modified Files:**
|
||||
|
||||
- `docs/plans/2025-12-13-phase-1-publishing-pipeline-design.md:87` - Added ICultureImpactFactory dependency
|
||||
- `docs/plans/2025-12-13-phase-1-publishing-pipeline-design.md:168` - Added PublishAction omission note
|
||||
- `docs/plans/2025-12-04-contentservice-refactoring-design.md:36` - Added decision #10 for pipeline order
|
||||
- `docs/plans/2025-12-04-contentservice-refactoring-design.md:131-152` - Updated Component Flow section
|
||||
- `docs/plans/2025-12-14-phase-1-baseline-performance.md` - Performance baseline document
|
||||
- `src/Umbraco.Core/Services/Publishing/IPublishingStrategy.cs` - Interface (27 lines)
|
||||
- `src/Umbraco.Infrastructure/Services/Publishing/PublishingStrategy.cs` - Implementation (238 lines)
|
||||
- `src/Umbraco.Core/Umbraco.Core.csproj` - Added InternalsVisibleTo
|
||||
- `tests/Umbraco.Tests.UnitTests/Umbraco.Core/Services/Publishing/PublishingStrategyTests.cs` - Unit tests (159 lines)
|
||||
- `tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentServicePublishBranchPerformanceTests.cs` - Performance tests (121 lines)
|
||||
|
||||
## Action Items & Next Steps
|
||||
|
||||
1. **Resume from Task 6**: Read the plan at `docs/plans/2025-12-13-phase-1-implementation-fixes.md` and continue with Task 6 (Create BatchValidationContext)
|
||||
|
||||
2. **Follow TDD pattern**: For each task, write failing test first, then implementation, then verify tests pass, then commit
|
||||
|
||||
3. **Use code review after implementation tasks**: After Tasks 6, 7, 8 (the main implementation tasks), dispatch a code-reviewer subagent
|
||||
|
||||
4. **Run performance tests after all tasks**: Compare against baseline (62.7 items/sec target: 125+ items/sec)
|
||||
|
||||
5. **Remaining tasks (6-11)**:
|
||||
- Task 6: Create `BatchValidationContext` record
|
||||
- Task 7: Implement `PublishingValidator` with parallel processing
|
||||
- Task 8: Implement `PublishingExecutor` with repository batch operations
|
||||
- Task 9: Create integration tests comparing pipeline to legacy
|
||||
- Task 10: Update benchmark to use .NET 10.0
|
||||
- Task 11: Add `ContentValidationResult` with factory methods
|
||||
|
||||
## Other Notes
|
||||
|
||||
**Skill in use:** `superpowers:subagent-driven-development` - Dispatches fresh subagent per task with code review between tasks.
|
||||
|
||||
**Baseline test command:**
|
||||
```bash
|
||||
dotnet test tests/Umbraco.Tests.Integration \
|
||||
--filter "FullyQualifiedName~ContentServicePublishBranchPerformanceTests" \
|
||||
-v normal
|
||||
```
|
||||
|
||||
**Existing tests to verify (125 pass):**
|
||||
- `ContentServicePublishBranchTests`: 20 tests
|
||||
- `ContentPublishingServiceTests`: 105 tests
|
||||
|
||||
**Key directories:**
|
||||
- Pipeline types: `src/Umbraco.Core/Services/Publishing/`
|
||||
- Pipeline implementations: `src/Umbraco.Infrastructure/Services/Publishing/`
|
||||
- Unit tests: `tests/Umbraco.Tests.UnitTests/Umbraco.Core/Services/Publishing/`
|
||||
- Integration tests: `tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/`
|
||||
@@ -0,0 +1,129 @@
|
||||
---
|
||||
date: 2025-12-14T03:05:10+00:00
|
||||
researcher: Claude
|
||||
git_commit: c33cce455ca0daaaabaad586032e62c04a507d3c
|
||||
branch: refactor/ContentService
|
||||
repository: Umbraco-CMS
|
||||
topic: "Phase 1 Publishing Pipeline Plan Merge Analysis"
|
||||
tags: [implementation, publishing-pipeline, contentservice-refactoring, plan-analysis]
|
||||
status: in_progress
|
||||
last_updated: 2025-12-14
|
||||
last_updated_by: Claude
|
||||
type: implementation_strategy
|
||||
---
|
||||
|
||||
# Handoff: Phase 1 Publishing Pipeline - Plan Merge Analysis
|
||||
|
||||
## Task(s)
|
||||
|
||||
**Analyzed two overlapping implementation plan documents** to determine how to merge them and assessed current implementation progress.
|
||||
|
||||
### Documents Analyzed
|
||||
|
||||
1. **Original Plan**: `docs/plans/2025-12-13-phase-1-publishing-pipeline-implementation.md` (17 tasks)
|
||||
2. **Fixes Plan**: `docs/plans/2025-12-13-phase-1-implementation-fixes.md` (11 tasks)
|
||||
|
||||
### Key Finding
|
||||
|
||||
The "Fixes Plan" is authoritative - it corrects critical architectural issues in the original:
|
||||
|
||||
| Component | Original Plan | Fixes Plan |
|
||||
|-----------|--------------|------------|
|
||||
| PublishingStrategy | `IContentService.GetPagedDescendants` | `IDocumentRepository.GetPage` |
|
||||
| PublishingExecutor | `IContentService.Publish` | `IDocumentRepository.Save` |
|
||||
| PublishingValidator | Sequential validation | `Parallel.For` + `Environment.ProcessorCount` |
|
||||
| Benchmark | `RuntimeMoniker.Net90` | `RuntimeMoniker.Net100` |
|
||||
|
||||
### Implementation Status (Fixes Plan)
|
||||
|
||||
| Task | Description | Status |
|
||||
|------|-------------|--------|
|
||||
| 1-3 | Documentation updates (ICultureImpactFactory, pipeline order, PublishAction) | **Completed** |
|
||||
| 4 | IPublishingStrategy interface | **Completed** |
|
||||
| 5 | PublishingStrategy with IDocumentRepository | **Completed** (code review passed) |
|
||||
| 6 | BatchValidationContext | **Completed** |
|
||||
| 7 | PublishingValidator with parallel processing | **Completed** (code review passed with fixes) |
|
||||
| 8 | PublishingExecutor with IDocumentRepository | **Pending** |
|
||||
| 9 | Integration tests | **Pending** |
|
||||
| 10 | Benchmark RuntimeMoniker fix | **Pending** |
|
||||
| 11 | ContentValidationResult (already done in Task 7) | **Completed** |
|
||||
|
||||
## Critical References
|
||||
|
||||
1. **Fixes Plan (Authoritative)**: `docs/plans/2025-12-13-phase-1-implementation-fixes.md`
|
||||
2. **Original Plan (Supplementary)**: `docs/plans/2025-12-13-phase-1-publishing-pipeline-implementation.md`
|
||||
3. **Design Document**: `docs/plans/2025-12-04-contentservice-refactoring-design.md`
|
||||
|
||||
## Recent changes
|
||||
|
||||
The previous handoff (`2025-12-14_02-34-25_phase1-publishing-pipeline.md`) documented commits through Task 5. Since then:
|
||||
|
||||
- `411cc4c595`: feat(core): add BatchValidationContext record (Task 6)
|
||||
- `c33cce455c`: feat(core): implement PublishingValidator with parallel processing (Task 7, amended with fixes)
|
||||
|
||||
## Learnings
|
||||
|
||||
1. **Fixes Plan supersedes Original Plan**: The original plan had architectural issues (using IContentService instead of IDocumentRepository). Always use the fixes plan.
|
||||
|
||||
2. **Missing pieces in Fixes Plan**: The fixes plan doesn't include:
|
||||
- Supporting types (PublishingOperation, SkippedContent, PublishingPlan) - these already exist from prior work
|
||||
- DI registration (original Task 14)
|
||||
- ContentPublishingService integration (original Task 15)
|
||||
- IPublishingNotifier/PublishingNotifier (original Tasks 9-10)
|
||||
|
||||
3. **Infrastructure vs Core**: Components needing `ISqlContext` (PublishingStrategy) must be in `Umbraco.Infrastructure`, not `Umbraco.Core`. This requires `InternalsVisibleTo` in Core.csproj.
|
||||
|
||||
4. **BatchValidationContext usage**: The context is built but not fully utilized in PublishingValidator yet - it's infrastructure for future optimization when IPropertyValidationService is refactored.
|
||||
|
||||
## Artifacts
|
||||
|
||||
**Implementation files created (this session):**
|
||||
- `src/Umbraco.Core/Services/Publishing/BatchValidationContext.cs`
|
||||
- `src/Umbraco.Core/Services/Publishing/ContentValidationResult.cs`
|
||||
- `src/Umbraco.Core/Services/Publishing/IPublishingValidator.cs`
|
||||
- `src/Umbraco.Core/Services/Publishing/PublishingValidator.cs`
|
||||
- `tests/Umbraco.Tests.UnitTests/Umbraco.Core/Services/Publishing/BatchValidationContextTests.cs`
|
||||
- `tests/Umbraco.Tests.UnitTests/Umbraco.Core/Services/Publishing/PublishingValidatorTests.cs`
|
||||
|
||||
**Implementation files created (prior sessions):**
|
||||
- `src/Umbraco.Core/Services/Publishing/IPublishingStrategy.cs`
|
||||
- `src/Umbraco.Infrastructure/Services/Publishing/PublishingStrategy.cs`
|
||||
- `tests/Umbraco.Tests.UnitTests/Umbraco.Core/Services/Publishing/PublishingStrategyTests.cs`
|
||||
- Supporting types: PublishingOperation, SkippedContent, PublishingPlan (locations in `src/Umbraco.Core/Services/Publishing/`)
|
||||
|
||||
## Action Items & Next Steps
|
||||
|
||||
### Option 1: Continue Fixes Plan Implementation (Remaining Tasks 8-10)
|
||||
|
||||
1. **Task 8**: Implement PublishingExecutor with IDocumentRepository.Save
|
||||
2. **Task 9**: Create integration tests comparing pipeline to legacy
|
||||
3. **Task 10**: Update benchmark RuntimeMoniker to Net100
|
||||
|
||||
### Option 2: Create Merged Plan Document
|
||||
|
||||
Combine both plans into a single authoritative document:
|
||||
- Use fixes plan architecture (repository-based)
|
||||
- Add missing pieces from original (DI registration, integration)
|
||||
- Mark completed tasks
|
||||
|
||||
### Option 3: Both
|
||||
|
||||
Create merged doc AND continue implementation.
|
||||
|
||||
### Recommended
|
||||
|
||||
**Option 3** - Create the merged plan for documentation clarity, then continue with Task 8 (PublishingExecutor).
|
||||
|
||||
## Other Notes
|
||||
|
||||
**Key directories:**
|
||||
- Pipeline types: `src/Umbraco.Core/Services/Publishing/`
|
||||
- Pipeline implementations: `src/Umbraco.Infrastructure/Services/Publishing/`
|
||||
- Unit tests: `tests/Umbraco.Tests.UnitTests/Umbraco.Core/Services/Publishing/`
|
||||
- Integration tests: `tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/`
|
||||
|
||||
**Skill in use:** `superpowers:subagent-driven-development` - Dispatches fresh subagent per task with code review between tasks.
|
||||
|
||||
**Performance target:** Legacy PublishBranch at 50 items = 62.7 items/sec. Target is 2x = 125+ items/sec.
|
||||
|
||||
**Previous handoff:** `thoughts/shared/handoffs/general/2025-12-14_02-34-25_phase1-publishing-pipeline.md`
|
||||
@@ -0,0 +1,137 @@
|
||||
---
|
||||
date: 2025-12-14T04:13:01+00:00
|
||||
researcher: Claude
|
||||
git_commit: 99b50eaca4bbac78d83f894a06b58e255a73d2dc
|
||||
branch: refactor/ContentService
|
||||
repository: Umbraco-CMS
|
||||
topic: "Phase 1 Publishing Pipeline Implementation using Subagent-Driven Development"
|
||||
tags: [implementation, publishing-pipeline, content-service, subagent-driven-development]
|
||||
status: in_progress
|
||||
last_updated: 2025-12-14
|
||||
last_updated_by: Claude
|
||||
type: implementation_strategy
|
||||
---
|
||||
|
||||
# Handoff: Phase 1 Publishing Pipeline - Subagent-Driven Development
|
||||
|
||||
## Task(s)
|
||||
|
||||
Implementing Phase 1 of the publishing pipeline refactoring using the **subagent-driven-development** skill. This creates four internal pipeline components (Strategy, Validator, Executor, Notifier) for branch publishing using repository-based architecture.
|
||||
|
||||
**Plan document**: `docs/plans/2025-12-14-phase-1-publishing-pipeline-combined-implementation.md`
|
||||
|
||||
### Status Summary
|
||||
|
||||
| Task | Description | Status |
|
||||
|------|-------------|--------|
|
||||
| Task 1-7 | Supporting types & first interfaces | **COMPLETED** (before session) |
|
||||
| Task 8 | IPublishingExecutor interface | **COMPLETED** |
|
||||
| Task 9 | IPublishingNotifier interface | **COMPLETED** |
|
||||
| Task 10-11 | PublishingStrategy & PublishingValidator implementations | **COMPLETED** (before session) |
|
||||
| Task 12 | PublishingExecutor with IDocumentRepository | **COMPLETED** |
|
||||
| Task 13 | PublishingNotifier implementation | **COMPLETED** |
|
||||
| Task 14 | Register pipeline components in DI | **COMPLETED** |
|
||||
| Task 15 | Add PerformPublishBranchPipelineAsync method | **COMPLETED** |
|
||||
| Task 16 | Create integration tests | **COMPLETED** |
|
||||
| Task 17 | Create benchmark infrastructure | **COMPLETED** |
|
||||
| Task 18 | Run full test suite | **PENDING** |
|
||||
|
||||
**Current Phase**: Task 18 (final verification) - need to run full test suite
|
||||
|
||||
## Critical References
|
||||
|
||||
1. **Implementation Plan**: `docs/plans/2025-12-14-phase-1-publishing-pipeline-combined-implementation.md`
|
||||
2. **Core CLAUDE.md**: `src/Umbraco.Core/CLAUDE.md` - defines scoping patterns, notification patterns
|
||||
3. **superpowers:subagent-driven-development skill** - workflow being followed
|
||||
|
||||
## Recent changes
|
||||
|
||||
All changes committed to `refactor/ContentService` branch:
|
||||
|
||||
- `src/Umbraco.Core/Services/Publishing/IPublishingExecutor.cs` - Added interface (Task 8)
|
||||
- `src/Umbraco.Core/Services/Publishing/IPublishingNotifier.cs` - Added interface (Task 9)
|
||||
- `src/Umbraco.Infrastructure/Services/Publishing/PublishingExecutor.cs` - Implementation with IDocumentRepository (Task 12)
|
||||
- `src/Umbraco.Core/Services/Publishing/PublishingNotifier.cs` - Implementation (Task 13)
|
||||
- `tests/Umbraco.Tests.UnitTests/Umbraco.Core/Services/Publishing/PublishingExecutorTests.cs` - 4 unit tests
|
||||
- `tests/Umbraco.Tests.UnitTests/Umbraco.Core/Services/Publishing/PublishingNotifierTests.cs` - 3 unit tests
|
||||
- `src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.Services.cs:92-96` - DI registration
|
||||
- `src/Umbraco.Core/Services/ContentPublishingService.cs` - Added pipeline fields, constructor params, and PerformPublishBranchPipelineAsync method
|
||||
- `tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/Publishing/PublishingPipelineIntegrationTests.cs` - 3 integration tests
|
||||
- `tests/Umbraco.Tests.Benchmarks/ContentPublishingPipelineBenchmarks.cs` - Benchmark infrastructure
|
||||
|
||||
## Learnings
|
||||
|
||||
1. **ContentValidationResult naming collision**: There are two types with this name in the codebase:
|
||||
- `Umbraco.Cms.Core.Models.ContentEditing.ContentValidationResult` (existing)
|
||||
- `Umbraco.Cms.Core.Services.Publishing.ContentValidationResult` (new pipeline type)
|
||||
- Fixed by using fully qualified names in `ContentPublishingService.cs:199,251,278`
|
||||
|
||||
2. **PublishCulture extension method signature**: The real method requires `PropertyEditorCollection` as a parameter, which wasn't in the plan. Had to add this dependency to `PublishingExecutor`.
|
||||
|
||||
3. **RuntimeMoniker for .NET 10**: Use `RuntimeMoniker.Net10_0` (not `Net100` as plan stated)
|
||||
|
||||
4. **InternalsVisibleTo already configured**: `Umbraco.Core.csproj` already exposes internals to `Umbraco.Infrastructure` at line 54.
|
||||
|
||||
5. **Constants.Security.SuperUserId = -1**: Defined in `Constants-Security.cs:11`
|
||||
|
||||
## Artifacts
|
||||
|
||||
### Implementation Files
|
||||
- `src/Umbraco.Core/Services/Publishing/IPublishingExecutor.cs`
|
||||
- `src/Umbraco.Core/Services/Publishing/IPublishingNotifier.cs`
|
||||
- `src/Umbraco.Infrastructure/Services/Publishing/PublishingExecutor.cs`
|
||||
- `src/Umbraco.Core/Services/Publishing/PublishingNotifier.cs`
|
||||
- `src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.Services.cs:92-96`
|
||||
- `src/Umbraco.Core/Services/ContentPublishingService.cs:32-35,49-52,69-72,383-493`
|
||||
|
||||
### Test Files
|
||||
- `tests/Umbraco.Tests.UnitTests/Umbraco.Core/Services/Publishing/PublishingExecutorTests.cs`
|
||||
- `tests/Umbraco.Tests.UnitTests/Umbraco.Core/Services/Publishing/PublishingNotifierTests.cs`
|
||||
- `tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/Publishing/PublishingPipelineIntegrationTests.cs`
|
||||
- `tests/Umbraco.Tests.Benchmarks/ContentPublishingPipelineBenchmarks.cs`
|
||||
|
||||
### Planning Documents
|
||||
- `docs/plans/2025-12-14-phase-1-publishing-pipeline-combined-implementation.md`
|
||||
|
||||
## Action Items & Next Steps
|
||||
|
||||
1. **Run Task 18 - Full Test Suite**:
|
||||
```bash
|
||||
dotnet build
|
||||
dotnet test tests/Umbraco.Tests.UnitTests --filter "FullyQualifiedName~Publishing"
|
||||
dotnet test tests/Umbraco.Tests.UnitTests
|
||||
```
|
||||
|
||||
2. **Code Review for Task 17**: Already passed, but was interrupted before marking complete
|
||||
|
||||
3. **Update plan document**: Mark remaining tasks as completed once verified
|
||||
|
||||
4. **Use finishing-a-development-branch skill**: After Task 18 passes, follow the skill to complete the branch (merge, PR, or cleanup options)
|
||||
|
||||
5. **Performance baseline**: After full verification, run the benchmark to establish baseline:
|
||||
```bash
|
||||
dotnet run -c Release --project tests/Umbraco.Tests.Benchmarks -- --filter "*PublishingPipeline*"
|
||||
```
|
||||
|
||||
## Other Notes
|
||||
|
||||
### Commits Made (most recent first)
|
||||
- `99b50eaca4` - perf(benchmarks): add publishing pipeline benchmark infrastructure (Task 17)
|
||||
- `4d898b10d0` - test(integration): add publishing pipeline integration tests (Task 16)
|
||||
- `a9adbdf3f9` - feat(core): add PerformPublishBranchPipelineAsync method (Task 15)
|
||||
- `d532c657f9` - chore(di): register publishing pipeline components (Task 14)
|
||||
- `80b141d2dd` - feat(core): implement PublishingNotifier (Task 13)
|
||||
- `e7d546f2b6` - feat(core): implement PublishingExecutor with IDocumentRepository (Task 12)
|
||||
- `85a90b2b93` - feat(core): add IPublishingNotifier interface (Task 9)
|
||||
- `75bb8ff8f7` - feat(core): add IPublishingExecutor interface (Task 8)
|
||||
|
||||
### Performance Gates (from plan)
|
||||
- Throughput (50+ items): >= 2x improvement over legacy
|
||||
- Memory allocations: <= legacy
|
||||
- Correctness: 100% parity with existing tests
|
||||
|
||||
### Key Architecture Decisions
|
||||
- Pipeline components are `internal` (not public API yet)
|
||||
- Uses `IDocumentRepository` instead of `IContentService` (avoids circular dependencies)
|
||||
- `PerformPublishBranchPipelineAsync` runs in PARALLEL with legacy path (not replacing it)
|
||||
- All components registered as **Scoped** services (appropriate for transaction-based operations)
|
||||
@@ -0,0 +1,107 @@
|
||||
---
|
||||
date: 2025-12-20T00:38:15+00:00
|
||||
researcher: Claude
|
||||
git_commit: f4a01ed50d5048da7839cf1149177fc011a50c6c
|
||||
branch: refactor/ContentService
|
||||
repository: Umbraco-CMS
|
||||
topic: "ContentService Refactoring Performance Review"
|
||||
tags: [implementation, performance, refactoring, contentservice]
|
||||
status: completed
|
||||
last_updated: 2025-12-20
|
||||
last_updated_by: Claude
|
||||
type: implementation_strategy
|
||||
---
|
||||
|
||||
# Handoff: ContentService Performance Review for Refactoring Design
|
||||
|
||||
## Task(s)
|
||||
|
||||
**Brainstorming session to review the ContentService refactoring design for performance improvements across four areas:**
|
||||
|
||||
| Area | Status | Decision |
|
||||
|------|--------|----------|
|
||||
| 1. Database Query Efficiency | **Completed** | Batch lookups (4 steps) |
|
||||
| 2. Memory Allocation Patterns | **Completed** | Aggressive, incremental (7 steps) |
|
||||
| 3. Concurrency & Locking | **Completed** | Moderate (4 steps) |
|
||||
| 4. Caching Strategies | **Completed** | Moderate (4 steps) |
|
||||
|
||||
Working from the design document at `docs/plans/2025-12-19-contentservice-refactor-design.md`.
|
||||
|
||||
## Critical References
|
||||
|
||||
1. `docs/plans/2025-12-19-contentservice-refactor-design.md` - The refactoring design being reviewed
|
||||
2. `src/Umbraco.Core/Services/ContentService.cs` - Current ~3800 line implementation being refactored
|
||||
3. `src/Umbraco.Core/Services/IContentService.cs` - Interface contract
|
||||
|
||||
## Recent changes
|
||||
|
||||
No code changes made. This is a design review/brainstorming session.
|
||||
|
||||
## Learnings
|
||||
|
||||
### Database Query Efficiency Issues Identified
|
||||
|
||||
1. **N+1 Query in `GetContentSchedulesByIds`** (ContentService.cs:1025-1049): Loop calling `_idKeyMap.GetIdForKey` for each key individually instead of batch lookup.
|
||||
|
||||
2. **Multiple repository calls in `CommitDocumentChangesInternal`** (ContentService.cs:1461+): Separate calls for `GetContentSchedule`, `Save`, and `PersistContentSchedule` within same scope.
|
||||
|
||||
3. **Repeated `GetById` calls**: `IsPathPublishable` (line 1070), `GetAncestors` (line 792) make multiple single-item lookups.
|
||||
|
||||
**Decision Made**: User approved **Option 1 (Batch lookups)** approach:
|
||||
- Add batch methods like `GetSchedulesByContentIds(int[] ids)`, `ArePathsPublished(int[] contentIds)`, `GetParents(int[] contentIds)`
|
||||
- Fix N+1 in key-to-id resolution by adding/using `IIdKeyMap.GetIdsForKeys(Guid[] keys, UmbracoObjectTypes type)`
|
||||
|
||||
### Memory Allocation Issues Identified
|
||||
|
||||
1. **Excessive ToArray/ToList materializations**: Lines 1170, 814, 2650 - materialize collections just to iterate
|
||||
2. **String allocations in hot paths**: Lines 1201, 2596-2598 - string concat in loops/move operations
|
||||
3. **Lambda/closure allocations**: Line 1125-1127 - creates list and closure on every save
|
||||
4. **Dictionary recreations**: Lines 555-556 - creates dictionary then iterates again
|
||||
|
||||
**Pending Decision**: User needs to choose approach:
|
||||
- **Conservative**: Fix obvious issues (ToArray before iteration, string concat in loops)
|
||||
- **Moderate**: Add StringBuilder pooling, avoid unnecessary materializations
|
||||
- **Aggressive**: Full Span/ArrayPool usage, pooled collections
|
||||
|
||||
## Artifacts
|
||||
|
||||
- `docs/plans/2025-12-19-contentservice-refactor-design.md` - Design document updated to Revision 1.2 with Performance Optimizations section
|
||||
|
||||
## Action Items & Next Steps
|
||||
|
||||
All performance review tasks completed. Design document updated with:
|
||||
|
||||
1. ✅ Database Query Efficiency - 4 batch lookup improvements
|
||||
2. ✅ Memory Allocation Patterns - 7 incremental optimization steps
|
||||
3. ✅ Concurrency & Locking - 4 lock optimization steps
|
||||
4. ✅ Caching Strategies - 4 cache optimization steps
|
||||
5. ✅ Design document updated at `docs/plans/2025-12-19-contentservice-refactor-design.md` (Revision 1.2)
|
||||
|
||||
**Next step**: Proceed to implementation planning with `superpowers:writing-plans`
|
||||
|
||||
## Other Notes
|
||||
|
||||
### Architecture Context
|
||||
|
||||
The refactoring splits ContentService into 5 public services + 2 internal managers:
|
||||
- `IContentCrudService` (~400 lines) - Create, Get, Save, Delete
|
||||
- `IContentPublishOperationService` (~1000 lines) - Publish, Unpublish, Scheduling
|
||||
- `IContentMoveService` (~350 lines) - Move, RecycleBin, Copy, Sort
|
||||
- `IContentQueryService` (~250 lines) - Count, Paged queries, Hierarchy
|
||||
- `IContentVersionService` (~200 lines) - Versions, Rollback
|
||||
- `ContentPermissionManager` (internal) - Permissions
|
||||
- `ContentBlueprintManager` (internal) - Blueprints
|
||||
|
||||
### Key Design Decisions Already Made
|
||||
|
||||
1. **Naming**: `IContentPublishOperationService` (not `IContentPublishingService`) to avoid collision with existing API-layer service
|
||||
2. **Scope Pattern**: Caller-Creates-Scope (Ambient Scope) - nested scopes participate in parent transaction
|
||||
3. **Lock Coordination**: Acquire locks at highest level that creates scope
|
||||
4. **Dependency Direction**: Unidirectional - Publish/Move may call CRUD, no reverse dependencies
|
||||
|
||||
### Relevant Codebase Locations
|
||||
|
||||
- Core interfaces: `src/Umbraco.Core/Services/`
|
||||
- Repository interfaces: `src/Umbraco.Core/Persistence/Repositories/`
|
||||
- Scoping: `src/Umbraco.Core/Scoping/`
|
||||
- ID/Key mapping: `IIdKeyMap` interface for key-to-id resolution
|
||||
@@ -0,0 +1,110 @@
|
||||
---
|
||||
date: 2025-12-20T01:01:02+00:00
|
||||
researcher: Claude
|
||||
git_commit: f4a01ed50d5048da7839cf1149177fc011a50c6c
|
||||
branch: refactor/ContentService
|
||||
repository: Umbraco-CMS
|
||||
topic: "ContentService Refactoring Test Coverage Analysis"
|
||||
tags: [testing, refactoring, contentservice, test-strategy]
|
||||
status: complete
|
||||
last_updated: 2025-12-20
|
||||
last_updated_by: Claude
|
||||
type: implementation_strategy
|
||||
---
|
||||
|
||||
# Handoff: ContentService Test Coverage Analysis for Refactoring
|
||||
|
||||
## Task(s)
|
||||
- **Completed**: Analyzed the ContentService refactoring design document
|
||||
- **Completed**: Reviewed all existing ContentService test files
|
||||
- **Completed**: Mapped existing test coverage to proposed service extraction
|
||||
- **Completed**: Identified test coverage gaps
|
||||
- **Completed**: Recommended test strategy for the refactoring
|
||||
- **Planned**: Write specific tests for identified gaps (not started)
|
||||
|
||||
## Critical References
|
||||
1. `docs/plans/2025-12-19-contentservice-refactor-design.md` - The master refactoring design document
|
||||
2. `tests/Umbraco.Tests.Integration/Umbraco.Core/Services/ContentServiceTests.cs` - Main test file (3707 lines, 91 tests)
|
||||
|
||||
## Recent changes
|
||||
No code changes made - this was a research/analysis session.
|
||||
|
||||
## Learnings
|
||||
|
||||
### Existing Test Coverage Summary
|
||||
The ContentService has substantial existing test coverage across 6 test files:
|
||||
|
||||
| Test File | Tests | Focus Area |
|
||||
|-----------|-------|------------|
|
||||
| `ContentServiceTests.cs` | 91 | Core CRUD, publishing, scheduling, hierarchy |
|
||||
| `ContentServiceNotificationTests.cs` | 8 | Saving/publishing notification handlers, culture variants |
|
||||
| `ContentServicePublishBranchTests.cs` | 10 | Branch publishing with various filters, variant/invariant content |
|
||||
| `ContentServiceVariantTests.cs` | 3 | Culture code casing consistency |
|
||||
| `ContentServiceTagsTests.cs` | 16 | Tag handling, invariant/variant transitions |
|
||||
| `ContentServicePerformanceTest.cs` | 8 | Bulk operations, caching performance |
|
||||
|
||||
### Proposed Service Extraction (from design doc)
|
||||
The design splits ContentService into 5 public services + 2 internal managers:
|
||||
1. `IContentCrudService` - Create, Get, Save, Delete
|
||||
2. `IContentPublishOperationService` - Publish, Unpublish, Scheduling, Branch
|
||||
3. `IContentMoveService` - Move, RecycleBin, Copy, Sort
|
||||
4. `IContentQueryService` - Count, Paged queries, Hierarchy
|
||||
5. `IContentVersionService` - Versions, Rollback, DeleteVersions
|
||||
6. `ContentPermissionManager` (internal)
|
||||
7. `ContentBlueprintManager` (internal)
|
||||
|
||||
### Test Strategy Recommendation
|
||||
**Option A with targeted additions** (recommended approach):
|
||||
- Keep existing tests as primary safety net (they test via IContentService which becomes the facade)
|
||||
- Add targeted tests for areas with new risk introduced by the refactoring
|
||||
|
||||
### Identified Test Coverage Gaps
|
||||
|
||||
| Gap Area | Current State | Why It Matters |
|
||||
|----------|--------------|----------------|
|
||||
| **Notification ordering in orchestrated ops** | No explicit test | `MoveToRecycleBin` must unpublish→move in correct sequence |
|
||||
| **Sort operation** | No test exists | `IContentMoveService.Sort()` has no coverage |
|
||||
| **DeleteOfType/DeleteOfTypes** | 1 test only | Complex orchestration: moves descendants to bin first |
|
||||
| **Permission operations** | No tests | `SetPermissions`/`SetPermission` have zero coverage |
|
||||
| **Transaction boundaries** | Implicit only | When services call each other, ambient scope must work |
|
||||
| **Lock coordination** | No explicit test | Services acquiring locks within ambient scopes |
|
||||
| **CommitDocumentChanges internal** | Limited | Culture unpublishing within this method not well tested |
|
||||
| **Independent service usage** | N/A (new) | Consumers may inject services directly (e.g., `IContentCrudService`) |
|
||||
|
||||
### Key Test File Locations
|
||||
- Integration tests: `tests/Umbraco.Tests.Integration/Umbraco.Core/Services/ContentServiceTests.cs`
|
||||
- More integration tests: `tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentService*Tests.cs`
|
||||
- Unit tests referencing ContentService: `tests/Umbraco.Tests.UnitTests/` (13 files, but mostly mock ContentService)
|
||||
|
||||
## Artifacts
|
||||
- `docs/plans/2025-12-19-contentservice-refactor-design.md` - Design document (reviewed)
|
||||
- This handoff document
|
||||
|
||||
## Action Items & Next Steps
|
||||
1. **Write notification ordering tests** - Verify `MoveToRecycleBin` fires `ContentUnpublishingNotification` before `ContentMovingToRecycleBinNotification`
|
||||
2. **Add Sort operation tests** - Test `Sort(IEnumerable<IContent>)` and `Sort(IEnumerable<int>)` methods
|
||||
3. **Expand DeleteOfType tests** - Verify descendant handling and notification ordering
|
||||
4. **Add permission tests** - Test `SetPermissions` and `SetPermission` methods
|
||||
5. **Add transaction boundary tests** - Verify ambient scope behavior when services chain calls
|
||||
6. **Consider independent service tests** - Once services are extracted, add tests that use them directly (not via facade)
|
||||
7. **Proceed with Phase 1 of refactoring** - Extract `IContentCrudService` first (establishes patterns)
|
||||
|
||||
## Other Notes
|
||||
|
||||
### Test Infrastructure Observations
|
||||
- Tests use `UmbracoIntegrationTest` base class with `NewSchemaPerTest` for isolation
|
||||
- `ContentRepositoryBase.ThrowOnWarning = true` is set in many tests for strict validation
|
||||
- Custom notification handlers are registered via `CustomTestSetup(IUmbracoBuilder builder)`
|
||||
- Tests use builder pattern extensively: `ContentTypeBuilder`, `ContentBuilder`, `TemplateBuilder`
|
||||
|
||||
### Key Methods That Need Careful Testing During Refactor
|
||||
Per the design doc's Notification Responsibility Matrix (`docs/plans/2025-12-19-contentservice-refactor-design.md:507-538`):
|
||||
- `MoveToRecycleBin` - Orchestrated in Facade (unpublish + move)
|
||||
- `DeleteOfType`/`DeleteOfTypes` - Orchestrated in Facade
|
||||
- All operations with cancellable notifications need pre/post verification
|
||||
|
||||
### Design Doc Key Sections
|
||||
- Service dependency diagram: lines 39-68
|
||||
- Method mapping tables: lines 386-496
|
||||
- Notification responsibility matrix: lines 507-538
|
||||
- Transaction/scope ownership: lines 105-156
|
||||
@@ -0,0 +1,114 @@
|
||||
---
|
||||
date: 2025-12-20T06:05:38+00:00
|
||||
researcher: Claude
|
||||
git_commit: bf054e9d6268b0ea26dda4fab3e32e3bb59c958b
|
||||
branch: refactor/ContentService
|
||||
repository: Umbraco-CMS
|
||||
topic: "ContentService Phase 0 Implementation Plan Critical Review"
|
||||
tags: [implementation, critical-review, contentservice, refactoring, testing]
|
||||
status: in_progress
|
||||
last_updated: 2025-12-20
|
||||
last_updated_by: Claude
|
||||
type: implementation_strategy
|
||||
---
|
||||
|
||||
# Handoff: ContentService Phase 0 Implementation Plan Critical Review
|
||||
|
||||
## Task(s)
|
||||
|
||||
| Task | Status |
|
||||
|------|--------|
|
||||
| Critical implementation review of Phase 0 plan | Completed |
|
||||
| Verify API signatures (Publish, GetContentSchedulesByIds) | Completed |
|
||||
| Verify DeleteOfType descendant handling behavior | Completed |
|
||||
| Verify IScopeProvider rollback semantics | Completed |
|
||||
| Identify duplicate tests in existing test files | Completed |
|
||||
| Apply fixes 1,2,4,5,6,7,8,9 to the plan | In Progress (interrupted) |
|
||||
| Answer user question about CI/Phase Gate Enforcement | Completed |
|
||||
|
||||
**Working from:** `docs/plans/2025-12-20-contentservice-refactor-phase0-implementation.md`
|
||||
|
||||
## Critical References
|
||||
|
||||
1. `docs/plans/2025-12-20-contentservice-refactor-phase0-implementation.md` - The Phase 0 implementation plan being reviewed
|
||||
2. `docs/plans/2025-12-19-contentservice-refactor-design.md` - The parent design document
|
||||
3. `build/azure-pipelines.yml` - CI pipeline configuration
|
||||
|
||||
## Recent changes
|
||||
|
||||
No code changes were made - this was a review session preparing to apply fixes.
|
||||
|
||||
## Learnings
|
||||
|
||||
### API Signatures Verified
|
||||
- `Publish(IContent content, string[] cultures, int userId)` - Plan uses `new[] { "*" }` correctly
|
||||
- `GetContentSchedulesByIds(Guid[] keys)` - Plan uses `keys.ToArray()` correctly (Guid[], not int[])
|
||||
- `EntityPermissionCollection(IEnumerable<EntityPermission> collection)` - Constructor exists as expected
|
||||
|
||||
### DeleteOfType Behavior (src/Umbraco.Core/Services/ContentService.cs:3498-3584)
|
||||
- Queries all content of specified type(s)
|
||||
- Orders by ParentId descending (deepest first)
|
||||
- For each item: moves ALL children to recycle bin (regardless of type), then deletes the item
|
||||
- Test 6 in plan is **correct** - descendants of different types go to bin, same type deleted
|
||||
|
||||
### IScopeProvider Rollback Semantics (src/Umbraco.Infrastructure/Scoping/IScopeProvider.cs)
|
||||
- `CreateScope()` returns `IScope` with `autoComplete = false` by default
|
||||
- If `scope.Complete()` is NOT called, transaction rolls back on dispose
|
||||
- Base test class exposes `ScopeProvider` property - no extra using needed for `Umbraco.Cms.Infrastructure.Scoping`
|
||||
|
||||
### CI Pipeline Configuration
|
||||
- **Platform:** Azure Pipelines
|
||||
- **Test filters for non-release builds:** `--filter TestCategory!=LongRunning&TestCategory!=NonCritical`
|
||||
- **LongRunning tests (benchmarks) are SKIPPED on normal PRs** - only run on release builds
|
||||
- Integration tests split into 3 shards by namespace:
|
||||
- Part 1: `Umbraco.Infrastructure` (excluding Service)
|
||||
- Part 2: `Umbraco.Infrastructure.Service` (where new tests will live)
|
||||
- Part 3: Everything else
|
||||
|
||||
### Duplicate Test Analysis
|
||||
No true duplicates found. Existing tests focus on different aspects:
|
||||
- `ContentEventsTests.cs:802-868` - Sort tests focus on cache refresh events, not notification order
|
||||
- `ContentServiceTests.cs:1862` - MoveToRecycleBin tests basic functionality, not notification sequence
|
||||
- `ContentServiceTests.cs:1832` - DeleteOfType exists but doesn't test descendant type handling
|
||||
|
||||
## Artifacts
|
||||
|
||||
- `docs/plans/2025-12-20-contentservice-refactor-phase0-implementation.md` - Plan to be updated
|
||||
- `tests/Umbraco.Tests.Integration/Testing/ContentServiceBenchmarkBase.cs` - Already exists (referenced in plan)
|
||||
|
||||
## Action Items & Next Steps
|
||||
|
||||
### Fixes to Apply to the Plan (User requested 1,2,4,5,6,7,8,9)
|
||||
|
||||
1. **[1] API Signatures** - Verified correct, add confirmation note to plan
|
||||
2. **[2] Remove incorrect using directive** - Task 6 instructs adding `using Umbraco.Cms.Infrastructure.Scoping;` but this is wrong. `ScopeProvider` is already available via base class. Remove this instruction.
|
||||
3. **[4] Add [NonParallelizable]** - Add `[NonParallelizable]` attribute to `ContentServiceRefactoringTests` class (Task 1 skeleton, line 43-48)
|
||||
4. **[5] DeleteOfType verified** - Add note confirming behavior is correct
|
||||
5. **[6] Add benchmark warmup** - Update `MeasureAndRecord` in `ContentServiceBenchmarkBase.cs` to include warmup iteration
|
||||
6. **[7] Explicit scope creation** - Add note about rollback semantics (verified working as expected)
|
||||
7. **[8] Add null-checks for template** - Change `FileService.GetTemplate("defaultTemplate")!` to include explicit assertion
|
||||
8. **[9] Portable JSON extraction** - Replace grep -oP with portable Python script or simpler extraction in Task 10
|
||||
|
||||
### Additional Items to Add
|
||||
- Add note about duplicate test analysis (none found)
|
||||
- Add note about CI behavior - benchmarks skip on PR builds due to `[LongRunning]` category
|
||||
- Consider if Phase Gate should run locally before PR or if CI coverage is sufficient
|
||||
|
||||
## Other Notes
|
||||
|
||||
### Key File Locations
|
||||
- **ContentService implementation:** `src/Umbraco.Core/Services/ContentService.cs` (~3800 lines)
|
||||
- **IContentService interface:** `src/Umbraco.Core/Services/IContentService.cs`
|
||||
- **IScopeProvider:** `src/Umbraco.Infrastructure/Scoping/IScopeProvider.cs`
|
||||
- **Existing ContentService tests:** `tests/Umbraco.Tests.Integration/Umbraco.Core/Services/ContentServiceTests.cs`
|
||||
- **ContentEventsTests (sort tests):** `tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentEventsTests.cs`
|
||||
- **ScopeTests:** `tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Scoping/ScopeTests.cs`
|
||||
- **LongRunning attribute:** `tests/Umbraco.Tests.Common/Attributes/LongRunning.cs`
|
||||
|
||||
### CI Phase Gate Question (User Asked)
|
||||
The CI runs ALL integration tests, not just ContentService tests. Tests are split by namespace for parallelization. The new tests will run in "Part 2 of 3" (Umbraco.Infrastructure.Service namespace).
|
||||
|
||||
**Important:** Benchmarks marked `[LongRunning]` will be **skipped on PR builds** and only run on release builds. This means:
|
||||
- The 15 integration tests WILL run on every PR
|
||||
- The 33 benchmarks will NOT run on PRs (only on releases)
|
||||
- For local Phase Gate verification, run: `dotnet test --filter "FullyQualifiedName~ContentServiceRefactoring"`
|
||||
@@ -0,0 +1,111 @@
|
||||
---
|
||||
date: 2025-12-20T18:26:11+00:00
|
||||
researcher: Claude
|
||||
git_commit: 86b0d3d803d1b53cb34f750b3145fcf64f7a8fb9
|
||||
branch: refactor/ContentService
|
||||
repository: Umbraco-CMS
|
||||
topic: "ContentService Refactoring Phase 0 Implementation"
|
||||
tags: [implementation, testing, benchmarks, contentservice, refactoring]
|
||||
status: in_progress
|
||||
last_updated: 2025-12-20
|
||||
last_updated_by: Claude
|
||||
type: implementation_strategy
|
||||
---
|
||||
|
||||
# Handoff: ContentService Refactoring Phase 0 - Test Infrastructure
|
||||
|
||||
## Task(s)
|
||||
|
||||
Executing Phase 0 of ContentService refactoring using **Subagent-Driven Development** workflow. Phase 0 creates test and benchmark infrastructure to establish baseline metrics before refactoring begins.
|
||||
|
||||
**Implementation Plan:** `docs/plans/2025-12-20-contentservice-refactor-phase0-implementation.md`
|
||||
|
||||
### Task Status (12 total tasks):
|
||||
|
||||
| Task | Description | Status |
|
||||
|------|-------------|--------|
|
||||
| Task 0 | Commit ContentServiceBenchmarkBase.cs | ✅ Completed (was already committed) |
|
||||
| Task 1 | Create ContentServiceRefactoringTests.cs skeleton | ✅ Completed (was already committed) |
|
||||
| Task 2 | Add notification ordering tests (Tests 1-2) | ✅ Completed (both reviews passed) |
|
||||
| Task 3 | Add sort operation tests (Tests 3-5) | ✅ Completed (both reviews passed) |
|
||||
| Task 4 | Add DeleteOfType tests (Tests 6-8) | 🔲 Pending |
|
||||
| Task 5 | Add permission tests (Tests 9-12) | 🔲 Pending |
|
||||
| Task 6 | Add transaction boundary tests (Tests 13-15) | 🔲 Pending |
|
||||
| Task 7 | Create ContentServiceRefactoringBenchmarks.cs | 🔲 Pending |
|
||||
| Task 8 | Create ContentServiceBaseTests.cs | 🔲 Pending |
|
||||
| Task 9 | Run all tests and verify | 🔲 Pending |
|
||||
| Task 10 | Capture baseline benchmarks | 🔲 Pending |
|
||||
| Task 11 | Final verification and summary | 🔲 Pending |
|
||||
|
||||
## Critical References
|
||||
|
||||
1. **Implementation Plan:** `docs/plans/2025-12-20-contentservice-refactor-phase0-implementation.md` - Contains exact test code to add for each task
|
||||
2. **Subagent-Driven Development Skill:** `~/.claude/plugins/cache/superpowers-marketplace/superpowers/4.0.0/skills/subagent-driven-development/` - Workflow being followed
|
||||
|
||||
## Recent changes
|
||||
|
||||
- `tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentServiceRefactoringTests.cs` - Added 5 tests (2 notification ordering, 3 sort operation)
|
||||
- Commits made: `09cc4b022e` (Task 2 initial), amended with fixes, `86b0d3d803` (Task 3)
|
||||
|
||||
## Learnings
|
||||
|
||||
1. **Subagent-Driven Development Workflow:**
|
||||
- Dispatch implementer subagent with FULL task text from plan (don't make subagent read files)
|
||||
- Dispatch spec compliance reviewer to verify implementation matches spec exactly
|
||||
- If issues found, dispatch fix subagent, then re-review
|
||||
- Dispatch code quality reviewer only AFTER spec compliance passes
|
||||
- Mark task complete only when both reviews approve
|
||||
|
||||
2. **Test Patterns in Umbraco:**
|
||||
- Base class `UmbracoIntegrationTestWithContent` provides `Textpage`, `Subpage`, `Subpage2`, `Subpage3`
|
||||
- `Textpage` is NOT published by default - tests may need to publish parent before creating child content
|
||||
- Use `ContentBuilder.CreateSimpleContent()` to create fresh test content
|
||||
- Use `RefactoringTestNotificationHandler.Reset()` before testing notifications
|
||||
|
||||
3. **Spec Compliance:**
|
||||
- First implementation of Task 2 deviated from spec (used fixtures instead of creating content)
|
||||
- Reviewer caught this and fix was applied successfully
|
||||
- Lesson: Spec reviewer is critical for catching deviations
|
||||
|
||||
## Artifacts
|
||||
|
||||
- `tests/Umbraco.Tests.Integration/Testing/ContentServiceBenchmarkBase.cs` - Benchmark base class (committed in Task 0)
|
||||
- `tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentServiceRefactoringTests.cs` - Integration tests (Tasks 1-3)
|
||||
- `docs/plans/2025-12-20-contentservice-refactor-phase0-implementation.md` - Full implementation plan with code
|
||||
|
||||
## Action Items & Next Steps
|
||||
|
||||
Resume using subagent-driven development workflow:
|
||||
|
||||
1. **Task 4: Add DeleteOfType tests (Tests 6-8)**
|
||||
- Dispatch implementer subagent with Task 4 from plan (lines 684-863)
|
||||
- After implementation, dispatch spec reviewer
|
||||
- After spec approval, dispatch code quality reviewer
|
||||
- Mark complete when approved
|
||||
|
||||
2. **Task 5: Add permission tests (Tests 9-12)**
|
||||
- Same workflow as Task 4
|
||||
- Plan lines 866-1059
|
||||
|
||||
3. **Task 6: Add transaction boundary tests (Tests 13-15)**
|
||||
- Same workflow
|
||||
- Plan lines 1063-1228
|
||||
|
||||
4. **Task 7: Create ContentServiceRefactoringBenchmarks.cs**
|
||||
- Large file (33 benchmarks) - may take longer
|
||||
- Plan lines 1231-2386
|
||||
|
||||
5. **Task 8: Create ContentServiceBaseTests.cs**
|
||||
- Unit tests (skeleton with tracking test)
|
||||
- Plan lines 2389-2657
|
||||
|
||||
6. **Tasks 9-11: Verification and baseline capture**
|
||||
- Run all tests, capture benchmarks, create git tag
|
||||
|
||||
## Other Notes
|
||||
|
||||
- The implementation plan has gone through 3 critical reviews (v1.1, v1.2, v1.3) - all feedback has been incorporated
|
||||
- Key revision notes are at the top of the plan document
|
||||
- Benchmark data sizes are standardized to 10/100/1000 pattern (v1.2)
|
||||
- Warmup logic was corrected for both destructive and non-destructive benchmarks
|
||||
- `ContentServiceBase` doesn't exist yet - Task 8 creates tracking test that fails when it's created in Phase 1
|
||||
@@ -0,0 +1,110 @@
|
||||
---
|
||||
date: 2025-12-20T18:58:13+00:00
|
||||
researcher: Claude
|
||||
git_commit: 3239a4534ecc588b3115187926e8dad80698a25f
|
||||
branch: refactor/ContentService
|
||||
repository: Umbraco-CMS
|
||||
topic: "ContentService Refactoring Phase 0 Implementation"
|
||||
tags: [implementation, testing, benchmarks, contentservice, refactoring]
|
||||
status: in_progress
|
||||
last_updated: 2025-12-20
|
||||
last_updated_by: Claude
|
||||
type: implementation_strategy
|
||||
---
|
||||
|
||||
# Handoff: ContentService Refactoring Phase 0 - Test Infrastructure (Task 7+)
|
||||
|
||||
## Task(s)
|
||||
|
||||
Executing Phase 0 of ContentService refactoring using **Subagent-Driven Development** workflow. Phase 0 creates test and benchmark infrastructure to establish baseline metrics before refactoring begins.
|
||||
|
||||
**Implementation Plan:** `docs/plans/2025-12-20-contentservice-refactor-phase0-implementation.md`
|
||||
|
||||
### Task Status (12 total tasks):
|
||||
|
||||
| Task | Description | Status |
|
||||
|------|-------------|--------|
|
||||
| Task 0 | Commit ContentServiceBenchmarkBase.cs | ✅ Completed |
|
||||
| Task 1 | Create ContentServiceRefactoringTests.cs skeleton | ✅ Completed |
|
||||
| Task 2 | Add notification ordering tests (Tests 1-2) | ✅ Completed |
|
||||
| Task 3 | Add sort operation tests (Tests 3-5) | ✅ Completed |
|
||||
| Task 4 | Add DeleteOfType tests (Tests 6-8) | ✅ Completed (this session) |
|
||||
| Task 5 | Add permission tests (Tests 9-12) | ✅ Completed (this session) |
|
||||
| Task 6 | Add transaction boundary tests (Tests 13-15) | ✅ Completed (this session) |
|
||||
| Task 7 | Create ContentServiceRefactoringBenchmarks.cs | 🔲 **IN PROGRESS** (next task) |
|
||||
| Task 8 | Create ContentServiceBaseTests.cs | 🔲 Pending |
|
||||
| Task 9 | Run all tests and verify | 🔲 Pending |
|
||||
| Task 10 | Capture baseline benchmarks | 🔲 Pending |
|
||||
| Task 11 | Final verification and summary | 🔲 Pending |
|
||||
|
||||
## Critical References
|
||||
|
||||
1. **Implementation Plan:** `docs/plans/2025-12-20-contentservice-refactor-phase0-implementation.md` - Contains exact code for all tasks. Task 7 is lines 1231-2386.
|
||||
2. **Subagent-Driven Development Skill:** `~/.claude/plugins/cache/superpowers-marketplace/superpowers/4.0.0/skills/subagent-driven-development/` - Workflow being followed
|
||||
|
||||
## Recent changes
|
||||
|
||||
- `tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentServiceRefactoringTests.cs` - Added 12 tests total (15 now in file):
|
||||
- Tasks 4-6 added: DeleteOfType tests (3), Permission tests (4), Transaction boundary tests (3)
|
||||
- Commits made this session:
|
||||
- `cf74f7850e` - Task 4: DeleteOfType tests
|
||||
- `7e989c0f8c` - Task 5: Permission tests
|
||||
- `3239a4534e` - Task 6: Transaction boundary tests
|
||||
|
||||
## Learnings
|
||||
|
||||
1. **Subagent-Driven Development Workflow:**
|
||||
- Dispatch implementer subagent with FULL task text from plan (don't make subagent read files)
|
||||
- Dispatch spec compliance reviewer to verify implementation matches spec exactly
|
||||
- If issues found, dispatch fix subagent, then re-review
|
||||
- Dispatch code quality reviewer only AFTER spec compliance passes
|
||||
- Mark task complete only when both reviews approve
|
||||
|
||||
2. **Test Patterns in Umbraco:**
|
||||
- Base class `UmbracoIntegrationTestWithContent` provides `Textpage`, `Subpage`, `Subpage2`, `Subpage3`
|
||||
- `Textpage` is NOT published by default - tests may need to publish parent before creating child content
|
||||
- Use `ContentBuilder.CreateSimpleContent()` to create fresh test content
|
||||
- Use `RefactoringTestNotificationHandler.Reset()` before testing notifications
|
||||
|
||||
3. **API Deviations from Plan (discovered in Task 5):**
|
||||
- `IUserGroupService` is async-only - tests must use `async Task` pattern
|
||||
- Use `Constants.Security.EditorGroupKey` (Guid) not `EditorGroupAlias`
|
||||
- `EntityPermission` constructor requires `ISet<string>` (HashSet), not array
|
||||
|
||||
4. **Spec Compliance:**
|
||||
- First implementation of Task 2 deviated from spec (used fixtures instead of creating content)
|
||||
- Reviewer caught this and fix was applied successfully
|
||||
- Lesson: Spec reviewer is critical for catching deviations
|
||||
|
||||
## Artifacts
|
||||
|
||||
- `tests/Umbraco.Tests.Integration/Testing/ContentServiceBenchmarkBase.cs` - Benchmark base class
|
||||
- `tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentServiceRefactoringTests.cs` - 15 integration tests (Tasks 1-6)
|
||||
- `docs/plans/2025-12-20-contentservice-refactor-phase0-implementation.md` - Full implementation plan with code
|
||||
|
||||
## Action Items & Next Steps
|
||||
|
||||
Resume using subagent-driven development workflow starting with **Task 7**:
|
||||
|
||||
1. **Task 7: Create ContentServiceRefactoringBenchmarks.cs** (NEXT)
|
||||
- Large file with 33 benchmarks (~1100 lines)
|
||||
- Plan lines 1231-2386 contain the full file content
|
||||
- Dispatch implementer subagent with Task 7 context
|
||||
- After implementation, dispatch spec reviewer, then code quality reviewer
|
||||
- This file creates a NEW file, not modifying existing
|
||||
|
||||
2. **Task 8: Create ContentServiceBaseTests.cs**
|
||||
- Unit tests (skeleton with tracking test)
|
||||
- Plan lines 2389-2657
|
||||
|
||||
3. **Tasks 9-11: Verification and baseline capture**
|
||||
- Run all tests, capture benchmarks, create git tag
|
||||
|
||||
## Other Notes
|
||||
|
||||
- The implementation plan has gone through 3 critical reviews (v1.1, v1.2, v1.3) - all feedback has been incorporated
|
||||
- Key revision notes are at the top of the plan document
|
||||
- Benchmark data sizes are standardized to 10/100/1000 pattern (v1.2)
|
||||
- Warmup logic was corrected for both destructive and non-destructive benchmarks
|
||||
- `ContentServiceBase` doesn't exist yet - Task 8 creates tracking test that fails when it's created in Phase 1
|
||||
- All 15 tests currently in ContentServiceRefactoringTests.cs are passing
|
||||
@@ -0,0 +1,113 @@
|
||||
---
|
||||
date: 2025-12-20T19:30:29+00:00
|
||||
researcher: Claude
|
||||
git_commit: 3239a4534ecc588b3115187926e8dad80698a25f
|
||||
branch: refactor/ContentService
|
||||
repository: Umbraco-CMS
|
||||
topic: "ContentService Refactoring Phase 0 - Task 7 Benchmarks Implementation"
|
||||
tags: [implementation, testing, benchmarks, contentservice, refactoring]
|
||||
status: in_progress
|
||||
last_updated: 2025-12-20
|
||||
last_updated_by: Claude
|
||||
type: implementation_strategy
|
||||
---
|
||||
|
||||
# Handoff: ContentService Phase 0 Task 7 - Benchmark File (32/33 complete)
|
||||
|
||||
## Task(s)
|
||||
|
||||
Executing **Task 7** of Phase 0 ContentService refactoring using Subagent-Driven Development workflow.
|
||||
|
||||
**Task 7 Goal:** Create `ContentServiceRefactoringBenchmarks.cs` with 33 performance benchmarks.
|
||||
|
||||
**Status:** 32 of 33 benchmarks implemented, build passing. Only B33 (Benchmark_BaselineComparison) and commit remain.
|
||||
|
||||
| Subtask | Description | Status |
|
||||
|---------|-------------|--------|
|
||||
| B1 | File skeleton + Benchmark_Save_SingleItem | ✅ Completed |
|
||||
| B2 | Benchmark_Save_BatchOf100 | ✅ Completed |
|
||||
| B3-B7 | Remaining CRUD benchmarks (5) | ✅ Completed |
|
||||
| B8-B13 | Query benchmarks (6) | ✅ Completed |
|
||||
| B14-B20 | Publish benchmarks (7) | ✅ Completed |
|
||||
| B21-B28 | Move benchmarks (8) | ✅ Completed |
|
||||
| B29-B32 | Version benchmarks (4) | ✅ Completed |
|
||||
| B33 | Benchmark_BaselineComparison + commit | 🔲 **NEXT** |
|
||||
|
||||
**Implementation Plan:** `docs/plans/2025-12-20-contentservice-refactor-phase0-implementation.md` (Task 7 is lines 1231-2386)
|
||||
|
||||
## Critical References
|
||||
|
||||
1. **Implementation Plan:** `docs/plans/2025-12-20-contentservice-refactor-phase0-implementation.md` - Contains exact code for all benchmarks
|
||||
2. **Previous Handoff:** `thoughts/shared/handoffs/general/2025-12-20_18-58-13_contentservice-phase0-subagent-driven-task7.md` - Context from prior session
|
||||
|
||||
## Recent changes
|
||||
|
||||
- Created new file: `tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentServiceRefactoringBenchmarks.cs`
|
||||
- 32 benchmarks implemented across 5 regions (CRUD, Query, Publish, Move, Version)
|
||||
- Baseline Comparison region has placeholder for B33
|
||||
|
||||
**Important Fix Applied:** Removed redundant `ContentTypeService` property (line 50) that was shadowing the base class property. The spec had this error; code quality reviewer caught it.
|
||||
|
||||
## Learnings
|
||||
|
||||
1. **Property Shadowing Issue:** The implementation plan spec included `private IContentTypeService ContentTypeService => GetRequiredService<IContentTypeService>();` but this shadows the same property already available from base class `UmbracoIntegrationTestWithContent`. The code quality reviewer caught this. **The line was removed.**
|
||||
|
||||
2. **Warmup Patterns (v1.2):**
|
||||
- Mutation operations (Save, Publish, Move, Copy): Manual warmup with throwaway data, then fresh data for measurement
|
||||
- Read-only operations (GetById, GetVersions, etc.): Use `MeasureAndRecord()` with default warmup
|
||||
- Destructive operations (Delete, EmptyRecycleBin): Use `MeasureAndRecord(skipWarmup: true)`
|
||||
|
||||
3. **Batch Efficiency:** Breaking Task 7 into 33 individual steps was reorganized into region-based batches (B1, B2, B3-B7, B8-B13, etc.) for efficiency while maintaining granular tracking.
|
||||
|
||||
## Artifacts
|
||||
|
||||
- `tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentServiceRefactoringBenchmarks.cs` - **UNCOMMITTED** benchmark file with 32/33 benchmarks
|
||||
- `docs/plans/2025-12-20-contentservice-refactor-phase0-implementation.md` - Implementation plan (lines 1231-2386 for Task 7)
|
||||
|
||||
## Action Items & Next Steps
|
||||
|
||||
1. **Complete B33: Add Benchmark_BaselineComparison**
|
||||
- Find the `#region Baseline Comparison (1 test)` region (currently empty)
|
||||
- Add the Benchmark_BaselineComparison method (spec in plan lines 2299-2355)
|
||||
- This is a meta-benchmark that runs a composite sequence (save, publish, query, trash, empty)
|
||||
|
||||
2. **Verify Build:**
|
||||
```bash
|
||||
dotnet build tests/Umbraco.Tests.Integration --no-restore -v q
|
||||
```
|
||||
|
||||
3. **Commit the file:**
|
||||
```bash
|
||||
git add tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentServiceRefactoringBenchmarks.cs
|
||||
git commit -m "$(cat <<'EOF'
|
||||
test: add ContentServiceRefactoringBenchmarks for Phase 0 baseline
|
||||
|
||||
Adds 33 performance benchmarks organized by operation type:
|
||||
- 7 CRUD operation benchmarks
|
||||
- 6 query operation benchmarks
|
||||
- 7 publish operation benchmarks
|
||||
- 8 move operation benchmarks
|
||||
- 4 version operation benchmarks
|
||||
- 1 baseline comparison meta-benchmark
|
||||
|
||||
Benchmarks output JSON for automated comparison between phases.
|
||||
|
||||
🤖 Generated with [Claude Code](https://claude.com/claude-code)
|
||||
|
||||
Co-Authored-By: Claude <noreply@anthropic.com>
|
||||
EOF
|
||||
)"
|
||||
```
|
||||
|
||||
4. **After Task 7, continue with Tasks 8-11:**
|
||||
- Task 8: Create ContentServiceBaseTests.cs (unit tests skeleton)
|
||||
- Task 9: Run all tests and verify
|
||||
- Task 10: Capture baseline benchmarks
|
||||
- Task 11: Final verification and summary
|
||||
|
||||
## Other Notes
|
||||
|
||||
- The file currently has 32 benchmarks verified by: `grep -c "public void Benchmark_" <file>` returns 32
|
||||
- All benchmarks follow standardized item counts (10/100/1000 pattern per v1.2)
|
||||
- Pre-existing build warnings in the codebase are unrelated to this work
|
||||
- The benchmark file extends `ContentServiceBenchmarkBase` which provides `ContentService`, `ContentType`, `ContentBuilder`, `RecordBenchmark()`, `MeasureAndRecord()`
|
||||
@@ -0,0 +1,130 @@
|
||||
---
|
||||
date: 2025-12-20T20:21:01+00:00
|
||||
researcher: Claude
|
||||
git_commit: a079c44afb7b49d0c8ab6fa891b9b82257d4cbf8
|
||||
branch: refactor/ContentService
|
||||
repository: Umbraco-CMS
|
||||
topic: "ContentService Refactoring Phase 0 - Test Infrastructure Complete"
|
||||
tags: [implementation, testing, benchmarks, contentservice, refactoring]
|
||||
status: complete
|
||||
last_updated: 2025-12-20
|
||||
last_updated_by: Claude
|
||||
type: implementation_strategy
|
||||
---
|
||||
|
||||
# Handoff: ContentService Refactoring Phase 0 Complete
|
||||
|
||||
## Task(s)
|
||||
|
||||
**Phase 0 Implementation - COMPLETED**
|
||||
|
||||
Executed Tasks 9-11 from the Phase 0 implementation plan (Tasks 0-8 were completed in a prior session):
|
||||
|
||||
| Task | Status | Description |
|
||||
|------|--------|-------------|
|
||||
| Task 9 | Completed | Run All Tests and Verify - all 15 integration tests pass |
|
||||
| Task 10 | Completed | Capture Baseline Benchmarks - 32 benchmark entries captured to JSON |
|
||||
| Task 11 | Completed | Final Verification and Summary - git tag created, all files verified |
|
||||
|
||||
Working from plan: `docs/plans/2025-12-20-contentservice-refactor-phase0-implementation.md`
|
||||
|
||||
## Critical References
|
||||
|
||||
- `docs/plans/2025-12-20-contentservice-refactor-phase0-implementation.md` - The Phase 0 implementation plan (v1.3)
|
||||
- `src/Umbraco.Core/CLAUDE.md` - Core architecture patterns (notification system, scoping pattern)
|
||||
- `src/Umbraco.Infrastructure/Services/ContentService.cs` - The service being refactored (target of future phases)
|
||||
|
||||
## Recent changes
|
||||
|
||||
Made by this session:
|
||||
- No code changes - Tasks 9-11 were verification and benchmark capture tasks
|
||||
- Ran benchmarks and captured output to `docs/plans/baseline-phase0.json`
|
||||
- Created git tag `phase-0-baseline`
|
||||
- Committed benchmark data: `a079c44afb` "chore: capture Phase 0 baseline benchmarks"
|
||||
|
||||
Made in prior session (Tasks 0-8):
|
||||
- `tests/Umbraco.Tests.Integration/Testing/ContentServiceBenchmarkBase.cs` - Benchmark infrastructure
|
||||
- `tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentServiceRefactoringTests.cs` - 15 integration tests
|
||||
- `tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentServiceRefactoringBenchmarks.cs` - 33 benchmarks
|
||||
- `tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Services/ContentServiceBaseTests.cs` - Tracking test skeleton
|
||||
|
||||
## Learnings
|
||||
|
||||
1. **Benchmark test failures are test implementation issues, not ContentService bugs:**
|
||||
- 4 benchmarks fail (GetVersions, GetVersionsSlim, HasChildren, Rollback)
|
||||
- Root cause: Test assumes `Save()` creates new versions, but it updates existing version
|
||||
- Root cause: `MeasureAndRecord` warmup causes double-counting in HasChildren test
|
||||
- These do not block refactoring work
|
||||
|
||||
2. **MeasureAndRecord warmup pattern:**
|
||||
- `ContentServiceBenchmarkBase.cs:63-84` - Action overload with `skipWarmup` parameter
|
||||
- `ContentServiceBenchmarkBase.cs:93-103` - Func<T> overload always includes warmup
|
||||
- Use `skipWarmup: true` for destructive operations (Delete, EmptyRecycleBin)
|
||||
|
||||
3. **Notification behavior for MoveToRecycleBin:**
|
||||
- MoveToRecycleBin does NOT fire unpublish notifications - content is "masked" not unpublished
|
||||
- Tests 1-2 validate this behavior (`ContentServiceRefactoringTests.cs:389-476`)
|
||||
|
||||
## Artifacts
|
||||
|
||||
**Test Infrastructure:**
|
||||
- `tests/Umbraco.Tests.Integration/Testing/ContentServiceBenchmarkBase.cs` - Benchmark base class with timing infrastructure
|
||||
- `tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentServiceRefactoringTests.cs` - 15 integration tests (all pass)
|
||||
- `tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentServiceRefactoringBenchmarks.cs` - 33 benchmarks (29 pass, 4 fail)
|
||||
- `tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Services/ContentServiceBaseTests.cs` - Tracking test for Phase 1
|
||||
|
||||
**Baseline Data:**
|
||||
- `docs/plans/baseline-phase0.json` - 32 benchmark timing entries in JSON format
|
||||
- `benchmark-6db0554b1e.txt` - Raw benchmark output (838 lines)
|
||||
|
||||
**Git Tag:**
|
||||
- `phase-0-baseline` - Marks the commit before baseline data was captured
|
||||
|
||||
## Action Items & Next Steps
|
||||
|
||||
1. **Phase 0 is complete** - Ready to proceed to Phase 1
|
||||
2. **Branch decision needed:** User was presented with finishing options:
|
||||
- Merge back to main locally
|
||||
- Push and create a Pull Request
|
||||
- Keep the branch as-is
|
||||
- Discard this work
|
||||
3. **Optional: Fix 4 failing benchmark tests** (low priority, does not block refactoring):
|
||||
- Version creation tests need different approach (publish between saves)
|
||||
- HasChildren test needs counter reset before measurement
|
||||
|
||||
## Other Notes
|
||||
|
||||
**Commit History (12 commits on branch):**
|
||||
```
|
||||
f4a01ed50d docs: add ContentService refactoring design plan
|
||||
bf054e9d62 docs: add performance benchmarks to ContentService refactor design
|
||||
336adef2c2 test: add ContentServiceBenchmarkBase infrastructure class
|
||||
0f408dd299 test: add ContentServiceRefactoringTests skeleton for Phase 0
|
||||
0c22afa3cf test: add notification ordering tests for MoveToRecycleBin
|
||||
86b0d3d803 test: add sort operation tests for ContentService refactoring
|
||||
cf74f7850e test: add DeleteOfType tests for ContentService refactoring
|
||||
7e989c0f8c test: add permission tests for ContentService refactoring
|
||||
3239a4534e test: add transaction boundary tests for ContentService refactoring
|
||||
0ef17bb1fc test: add ContentServiceRefactoringBenchmarks for Phase 0 baseline
|
||||
6db0554b1e test: add ContentServiceBaseTests skeleton for Phase 0
|
||||
a079c44afb chore: capture Phase 0 baseline benchmarks
|
||||
```
|
||||
|
||||
**Key Performance Baselines (from baseline-phase0.json):**
|
||||
- `Save_SingleItem`: 7ms
|
||||
- `Save_BatchOf1000`: 7.65ms/item
|
||||
- `Publish_BatchOf100`: 24.56ms/item
|
||||
- `MoveToRecycleBin_LargeTree`: 8.95ms/item (1001 items)
|
||||
- `Copy_Recursive_100Items`: 27.81ms/item
|
||||
|
||||
**Test Commands:**
|
||||
```bash
|
||||
# Run integration tests
|
||||
dotnet test tests/Umbraco.Tests.Integration --filter "FullyQualifiedName~ContentServiceRefactoringTests" -v n
|
||||
|
||||
# Run single benchmark
|
||||
dotnet test tests/Umbraco.Tests.Integration --filter "FullyQualifiedName~ContentServiceRefactoringBenchmarks.Benchmark_Save_SingleItem" -v n
|
||||
|
||||
# Run all benchmarks (10+ minutes)
|
||||
dotnet test tests/Umbraco.Tests.Integration --filter "Category=Benchmark&FullyQualifiedName~ContentServiceRefactoringBenchmarks"
|
||||
```
|
||||
@@ -0,0 +1,94 @@
|
||||
---
|
||||
date: 2025-12-21T00:33:07+00:00
|
||||
researcher: Claude
|
||||
git_commit: b72db599575b7f9ccf701c1a754bbbcd9a597a33
|
||||
branch: refactor/ContentService
|
||||
repository: Umbraco-CMS
|
||||
topic: "ContentService Phase 1 CRUD Extraction - Subagent-Driven Development"
|
||||
tags: [implementation, refactoring, contentservice, subagent-driven-development]
|
||||
status: in_progress
|
||||
last_updated: 2025-12-21
|
||||
last_updated_by: Claude
|
||||
type: implementation_strategy
|
||||
---
|
||||
|
||||
# Handoff: ContentService Phase 1 CRUD Extraction
|
||||
|
||||
## Task(s)
|
||||
|
||||
**Primary Task**: Execute Phase 1 of ContentService refactoring using subagent-driven development methodology.
|
||||
|
||||
**Phase 1 Goal**: Extract CRUD operations (Create, Get, Save, Delete) from the monolithic ContentService (3823 lines) into a dedicated `IContentCrudService` interface and `ContentCrudService` implementation.
|
||||
|
||||
### Task Status (8 total):
|
||||
|
||||
| # | Task | Status |
|
||||
|---|------|--------|
|
||||
| 1 | Create ContentServiceBase Abstract Class | **COMPLETED** |
|
||||
| 2 | Create IContentCrudService Interface | **COMPLETED** |
|
||||
| 3 | Create ContentCrudService Implementation | **IN PROGRESS** (not started) |
|
||||
| 4 | Register ContentCrudService in DI | Pending |
|
||||
| 5 | Update ContentService to Delegate CRUD Operations | Pending |
|
||||
| 6 | Add Benchmark Regression Enforcement | Pending |
|
||||
| 7 | Run Phase 1 Gate Tests | Pending |
|
||||
| 8 | Update Phase Tracking Documentation | Pending |
|
||||
|
||||
## Critical References
|
||||
|
||||
1. **Implementation Plan**: `docs/plans/2025-12-20-contentservice-refactor-phase1-implementation.md` - Contains complete task specifications including code to implement
|
||||
2. **Design Document**: `docs/plans/2025-12-19-contentservice-refactor-design.md` - Overall refactoring architecture
|
||||
3. **Skill Being Used**: `superpowers:subagent-driven-development` - Dispatch fresh subagent per task with two-stage review
|
||||
|
||||
## Recent changes
|
||||
|
||||
1. `src/Umbraco.Core/Services/ContentServiceBase.cs` - NEW: Abstract base class with shared infrastructure (DocumentRepository, AuditService, UserIdKeyResolver), Audit/AuditAsync helper methods
|
||||
2. `src/Umbraco.Core/Services/ContentServiceConstants.cs` - NEW: Static class with `DefaultBatchPageSize = 500`
|
||||
3. `src/Umbraco.Core/Services/IContentCrudService.cs` - NEW: Interface with 23 methods (Create x6, Read x8, Tree Traversal x5, Save x2, Delete x1)
|
||||
4. `tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Services/ContentServiceBaseTests.cs:226` - Updated type lookup to `Umbraco.Cms.Core.Services.ContentServiceBase, Umbraco.Core`
|
||||
|
||||
## Learnings
|
||||
|
||||
1. **Subagent Workflow**: Each task requires three subagents: implementer, spec reviewer, code quality reviewer. Only proceed after both reviews pass.
|
||||
|
||||
2. **Test File Discrepancy**: The tracking test in `ContentServiceBaseTests.cs` was written before the final plan. The plan is authoritative - had to update the test to look for the class in `Umbraco.Core` instead of `Umbraco.Infrastructure`.
|
||||
|
||||
3. **Implicit Usings**: .NET 10 has `using System;` implicit, so the code quality reviewer's suggestion to add it was not necessary (build succeeded without it).
|
||||
|
||||
4. **Spec Accuracy**: The spec's code sample for `ContentServiceBase.cs` was missing `using Umbraco.Cms.Core.Models;` which is required for `UmbracoObjectTypes.Document.GetName()`. Implementation correctly added it.
|
||||
|
||||
5. **Commit Hashes**:
|
||||
- Task 1: `c9ff758aca` - ContentServiceBase + ContentServiceConstants
|
||||
- Task 2: `b72db59957` - IContentCrudService interface
|
||||
|
||||
## Artifacts
|
||||
|
||||
- `docs/plans/2025-12-20-contentservice-refactor-phase1-implementation.md` - Complete implementation plan (2396 lines) with all 8 tasks
|
||||
- `src/Umbraco.Core/Services/ContentServiceBase.cs` - Abstract base class (69 lines)
|
||||
- `src/Umbraco.Core/Services/ContentServiceConstants.cs` - Constants class (12 lines)
|
||||
- `src/Umbraco.Core/Services/IContentCrudService.cs` - Interface (251 lines)
|
||||
|
||||
## Action Items & Next Steps
|
||||
|
||||
1. **Resume Task 3**: Create ContentCrudService Implementation
|
||||
- Dispatch implementer subagent with Task 3 content from the plan
|
||||
- This is the largest task (~750 lines of implementation code)
|
||||
- Includes unit tests in `tests/Umbraco.Tests.UnitTests/Umbraco.Core/Services/ContentCrudServiceTests.cs`
|
||||
|
||||
2. **Continue subagent-driven pattern**:
|
||||
- For each task: dispatch implementer → spec reviewer → code quality reviewer
|
||||
- Mark task complete only after both reviews pass
|
||||
- Update TodoWrite after each task completion
|
||||
|
||||
3. **Remaining Tasks 4-8**: Follow the plan exactly as specified
|
||||
|
||||
4. **Final Steps** (after Task 8):
|
||||
- Dispatch final code reviewer for entire implementation
|
||||
- Use `superpowers:finishing-a-development-branch` skill
|
||||
|
||||
## Other Notes
|
||||
|
||||
- **Methodology**: Using `superpowers:subagent-driven-development` skill - fresh subagent per task with two-stage review (spec compliance, then code quality)
|
||||
- **Prompt Templates Location**: `/home/yv01p/.claude/plugins/cache/superpowers-marketplace/superpowers/4.0.0/skills/subagent-driven-development/`
|
||||
- **Build Command**: `dotnet build src/Umbraco.Core/Umbraco.Core.csproj`
|
||||
- **Test Command Pattern**: `dotnet test tests/Umbraco.Tests.Integration --filter "FullyQualifiedName~ContentService"`
|
||||
- **The plan has been through 5 critical reviews** - see "Critical Review Changes Applied" sections at bottom of plan document
|
||||
@@ -0,0 +1,102 @@
|
||||
---
|
||||
date: 2025-12-21T01:09:28+00:00
|
||||
researcher: Claude
|
||||
git_commit: 0351dc06b4161640bab8e46c5ca20457a6b554fb
|
||||
branch: refactor/ContentService
|
||||
repository: Umbraco-CMS
|
||||
topic: "ContentService Phase 1 CRUD Extraction - Subagent-Driven Development"
|
||||
tags: [implementation, refactoring, contentservice, subagent-driven-development]
|
||||
status: in_progress
|
||||
last_updated: 2025-12-21
|
||||
last_updated_by: Claude
|
||||
type: implementation_strategy
|
||||
---
|
||||
|
||||
# Handoff: ContentService Phase 1 CRUD Extraction - Resume at Task 4
|
||||
|
||||
## Task(s)
|
||||
|
||||
**Primary Task**: Execute Phase 1 of ContentService refactoring using subagent-driven development methodology.
|
||||
|
||||
**Phase 1 Goal**: Extract CRUD operations (Create, Get, Save, Delete) from the monolithic ContentService (3823 lines) into a dedicated `IContentCrudService` interface and `ContentCrudService` implementation.
|
||||
|
||||
### Task Status (8 total):
|
||||
|
||||
| # | Task | Status |
|
||||
|---|------|--------|
|
||||
| 1 | Create ContentServiceBase Abstract Class | **COMPLETED** |
|
||||
| 2 | Create IContentCrudService Interface | **COMPLETED** |
|
||||
| 3 | Create ContentCrudService Implementation | **COMPLETED** |
|
||||
| 4 | Register ContentCrudService in DI | **IN PROGRESS** (not started) |
|
||||
| 5 | Update ContentService to Delegate CRUD Operations | Pending |
|
||||
| 6 | Add Benchmark Regression Enforcement | Pending |
|
||||
| 7 | Run Phase 1 Gate Tests | Pending |
|
||||
| 8 | Update Phase Tracking Documentation | Pending |
|
||||
|
||||
## Critical References
|
||||
|
||||
1. **Implementation Plan**: `docs/plans/2025-12-20-contentservice-refactor-phase1-implementation.md` - Contains complete task specifications including code to implement
|
||||
2. **Design Document**: `docs/plans/2025-12-19-contentservice-refactor-design.md` - Overall refactoring architecture
|
||||
3. **Skill Being Used**: `superpowers:subagent-driven-development` - Dispatch fresh subagent per task with two-stage review
|
||||
|
||||
## Recent changes
|
||||
|
||||
1. `src/Umbraco.Core/Services/ContentCrudService.cs` - NEW: Full CRUD service implementation (~750 lines)
|
||||
- 23 public methods (6 Create, 9 Read, 5 Tree Traversal, 2 Save, 1 Delete)
|
||||
- 7 private helpers (SaveLocked, DeleteLocked, GetContentTypeLocked, etc.)
|
||||
- Fixed all 5 issues from code quality review (batch audit bug, RecycleBinContent check, null checks, trashed parent validation, notification publishing)
|
||||
2. `tests/Umbraco.Tests.UnitTests/Umbraco.Core/Services/ContentCrudServiceTests.cs` - NEW: 8 unit tests, all passing
|
||||
- Fixed mocking issue with ContentCultureInfos (used real instance instead of mock)
|
||||
|
||||
## Learnings
|
||||
|
||||
1. **Subagent Workflow**: Each task requires three subagents: implementer, spec reviewer, code quality reviewer. Only proceed after both reviews pass.
|
||||
|
||||
2. **Test Mocking Limitation**: `ContentCultureInfos.Culture` is a non-virtual property and cannot be mocked. Use real instances: `new ContentCultureInfos("en-US")`.
|
||||
|
||||
3. **Lock Ordering**: Always acquire locks in order: ContentTree (write) → ContentTypes (read) → Languages (read). SaveLocked requires both ContentTree and Languages locks.
|
||||
|
||||
4. **Validation Placement**: Save validation (PublishedState, name length) MUST be inside SaveLocked, not in public Save method, to prevent race conditions.
|
||||
|
||||
5. **GetParent Special Cases**: Must check for both `Constants.System.Root` AND `Constants.System.RecycleBinContent` as parent IDs that should return null.
|
||||
|
||||
6. **Commit Hashes**:
|
||||
- Task 1: `c9ff758aca` - ContentServiceBase + ContentServiceConstants
|
||||
- Task 2: `b72db59957` - IContentCrudService interface
|
||||
- Task 3: `0351dc06b4` - ContentCrudService implementation (after all fixes)
|
||||
|
||||
## Artifacts
|
||||
|
||||
- `docs/plans/2025-12-20-contentservice-refactor-phase1-implementation.md` - Complete implementation plan (2396 lines) with all 8 tasks
|
||||
- `src/Umbraco.Core/Services/ContentServiceBase.cs` - Abstract base class (69 lines)
|
||||
- `src/Umbraco.Core/Services/ContentServiceConstants.cs` - Constants class (12 lines)
|
||||
- `src/Umbraco.Core/Services/IContentCrudService.cs` - Interface (251 lines)
|
||||
- `src/Umbraco.Core/Services/ContentCrudService.cs` - Implementation (~750 lines)
|
||||
- `tests/Umbraco.Tests.UnitTests/Umbraco.Core/Services/ContentCrudServiceTests.cs` - Unit tests (8 tests)
|
||||
|
||||
## Action Items & Next Steps
|
||||
|
||||
1. **Resume Task 4**: Register ContentCrudService in DI
|
||||
- Dispatch implementer subagent with Task 4 content from the plan
|
||||
- Add `Services.AddUnique<IContentCrudService, ContentCrudService>();` to `src/Umbraco.Core/DependencyInjection/UmbracoBuilder.cs` around line 300 (before IContentService registration)
|
||||
- Add integration test to verify DI resolution
|
||||
- Run: spec reviewer → code quality reviewer → mark complete
|
||||
|
||||
2. **Continue with Tasks 5-8**: Follow the plan exactly as specified
|
||||
- Task 5: Update ContentService to delegate CRUD to ContentCrudService (largest remaining task)
|
||||
- Task 6: Add benchmark regression enforcement
|
||||
- Task 7: Run Phase 1 gate tests
|
||||
- Task 8: Update documentation
|
||||
|
||||
3. **Final Steps** (after Task 8):
|
||||
- Dispatch final code reviewer for entire implementation
|
||||
- Use `superpowers:finishing-a-development-branch` skill
|
||||
|
||||
## Other Notes
|
||||
|
||||
- **Methodology**: Using `superpowers:subagent-driven-development` skill - fresh subagent per task with two-stage review (spec compliance, then code quality)
|
||||
- **Prompt Templates Location**: `/home/yv01p/.claude/plugins/cache/superpowers-marketplace/superpowers/4.0.0/skills/subagent-driven-development/`
|
||||
- **Build Command**: `dotnet build src/Umbraco.Core/Umbraco.Core.csproj`
|
||||
- **Test Command**: `dotnet test tests/Umbraco.Tests.UnitTests --filter "FullyQualifiedName~ContentCrudServiceTests"`
|
||||
- **The plan has been through 5 critical reviews** - see "Critical Review Changes Applied" sections at bottom of plan document
|
||||
- **Task 4 is small**: Just one line addition to UmbracoBuilder.cs + integration test
|
||||
Reference in New Issue
Block a user