Skip to content

Commit

Permalink
Fix allocations in DefaultSubmitHandler
Browse files Browse the repository at this point in the history
Still more work that needs to be done to make this handler more consistent, but at least we fixed some unnecessary allocations.
  • Loading branch information
robertmclaws committed Jan 1, 2019
1 parent 85d0770 commit 0ec9b8c
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/Microsoft.Restier.Core/Submit/DefaultSubmitHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ private static async Task InvokeAuthorizers(SubmitContext context, IEnumerable<C
{
if (!await authorizer.AuthorizeAsync(context, item, cancellationToken).ConfigureAwait(false))
{
var message = GetAuthorizeFailedMessage(item);
throw new SecurityException(message);
throw new SecurityException(GetAuthorizeFailedMessage(item));
}
}
}
Expand Down Expand Up @@ -162,13 +161,17 @@ private static async Task InvokeValidators(SubmitContext context, IEnumerable<Ch

private static async Task PerformPreEvent(SubmitContext context, IEnumerable<ChangeSetItem> changeSetItems, CancellationToken cancellationToken)
{

var processor = context.GetApiService<IChangeSetItemFilter>();
//TODO: Should we error out if there is no ChangeSetFilter? No consistent pattern to follow.

foreach (var item in changeSetItems)
{
if (item.ChangeSetItemProcessingStage == ChangeSetItemProcessingStage.Validated)
{
item.ChangeSetItemProcessingStage = ChangeSetItemProcessingStage.PreEventing;

var processor = context.GetApiService<IChangeSetItemFilter>();

if (processor != null)
{
await processor.OnChangeSetItemProcessingAsync(context, item, cancellationToken).ConfigureAwait(false);
Expand Down Expand Up @@ -203,14 +206,16 @@ private static async Task PerformPersist(SubmitContext context, CancellationToke

private static async Task PerformPostEvent(SubmitContext context, IEnumerable<ChangeSetItem> changeSetItems, CancellationToken cancellationToken)
{
//TODO: Check this for unnecessary allocations.
var processor = context.GetApiService<IChangeSetItemFilter>();
if (processor == null)
{
//TODO: It feels like we should be following the same pattern as teh method above.
return;
}

foreach (var item in changeSetItems)
{
var processor = context.GetApiService<IChangeSetItemFilter>();
if (processor != null)
{
await processor.OnChangeSetItemProcessedAsync(context, item, cancellationToken).ConfigureAwait(false);
}
await processor.OnChangeSetItemProcessedAsync(context, item, cancellationToken).ConfigureAwait(false);
}
}
}
Expand Down

0 comments on commit 0ec9b8c

Please sign in to comment.