Skip to content

Commit

Permalink
Add cancellation tokens and improve null safety
Browse files Browse the repository at this point in the history
Enhanced `ProcessAsync` in `ContentQueryExecutor.cs` and `PageContentQueryExecutor.cs` to handle `cancellationToken` for better operation cancellation. Added `System.Diagnostics.CodeAnalysis` namespace and `[return: NotNull]` attribute in `PageContentQueryExecutor.cs` to improve nullability annotations. Modified return statement to return an empty list if `results` is null, preventing potential `NullReferenceException`.
  • Loading branch information
bluemodus-brandon committed Sep 22, 2024
1 parent 1f23540 commit 04b9d7d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/XperienceCommunity.DataContext/ContentQueryExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public async Task<IEnumerable<T>> ExecuteQueryAsync(ContentItemQueryBuilder quer
{
foreach (var processor in _processors.OrderBy(x=> x.Order))
{
await processor.ProcessAsync(result);
await processor.ProcessAsync(result, cancellationToken);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Immutable;
using System.Diagnostics.CodeAnalysis;
using CMS.ContentEngine;
using CMS.Websites;
using Microsoft.Extensions.Logging;
Expand All @@ -22,6 +23,7 @@ public PageContentQueryExecutor(ILogger<PageContentQueryExecutor<T>> logger,
_processors = processors?.ToImmutableList();
}

[return: NotNull]
public async Task<IEnumerable<T>> ExecuteQueryAsync(ContentItemQueryBuilder queryBuilder,
ContentQueryExecutionOptions queryOptions, CancellationToken cancellationToken)
{
Expand All @@ -39,11 +41,11 @@ public async Task<IEnumerable<T>> ExecuteQueryAsync(ContentItemQueryBuilder quer
{
foreach (var processor in _processors.OrderBy(x => x.Order))
{
await processor.ProcessAsync(result);
await processor.ProcessAsync(result, cancellationToken);
}
}

return results;
return results ?? [];
}
catch (Exception ex)
{
Expand Down

0 comments on commit 04b9d7d

Please sign in to comment.