Skip to content

Commit

Permalink
Cleanup Warnings (ChilliCream#4529)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib authored Dec 10, 2021
1 parent f7951b6 commit 447bf4f
Show file tree
Hide file tree
Showing 75 changed files with 240,731 additions and 235 deletions.
37 changes: 27 additions & 10 deletions .build/Build.PublicApiAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using static Nuke.Common.Tools.DotNet.DotNetTasks;
using static Nuke.Common.Tools.Git.GitTasks;
using static Helpers;
using Nuke.Common.ProjectModel;

partial class Build
{
Expand All @@ -28,11 +29,19 @@ partial class Build
{
TryDelete(PublicApiSolutionFile);

DotNetBuildSonarSolution(
PublicApiSolutionFile,
include: file =>
!Path.GetFileNameWithoutExtension(file)
.EndsWith("tests", StringComparison.OrdinalIgnoreCase));
DotNetBuildSonarSolution(AllSolutionFile);

var projectFiles = ProjectModelTasks.ParseSolution(AllSolutionFile)
.AllProjects
.Where(t => t.GetProperty<string>("AddPublicApiAnalyzers") != "false")
.Where(t => !Path.GetDirectoryName(t.Path)
.EndsWith("tests", StringComparison.OrdinalIgnoreCase))
.Where(t => !Path.GetDirectoryName(t.Path)
.EndsWith("test", StringComparison.OrdinalIgnoreCase))
.Select(t => Path.GetDirectoryName(t.Path)!)
.ToArray();

DotNetBuildSonarSolution(PublicApiSolutionFile, projectFiles);

DotNetBuild(c => c
.SetProjectFile(PublicApiSolutionFile)
Expand All @@ -47,11 +56,19 @@ partial class Build
{
TryDelete(PublicApiSolutionFile);

DotNetBuildSonarSolution(
PublicApiSolutionFile,
include: file =>
!Path.GetFileNameWithoutExtension(file)
.EndsWith("tests", StringComparison.OrdinalIgnoreCase));
DotNetBuildSonarSolution(AllSolutionFile);

var projectFiles = ProjectModelTasks.ParseSolution(AllSolutionFile)
.AllProjects
.Where(t => t.GetProperty<string>("AddPublicApiAnalyzers") != "false")
.Where(t => !Path.GetDirectoryName(t.Path)
.EndsWith("tests", StringComparison.OrdinalIgnoreCase))
.Where(t => !Path.GetDirectoryName(t.Path)
.EndsWith("test", StringComparison.OrdinalIgnoreCase))
.Select(t => Path.GetDirectoryName(t.Path)!)
.ToArray();

DotNetBuildSonarSolution(PublicApiSolutionFile, projectFiles);

// last we run the actual dotnet format command.
DotNet($@"format ""{PublicApiSolutionFile}"" analyzers --diagnostics=RS0016", workingDirectory: RootDirectory);
Expand Down
1 change: 1 addition & 0 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@

<!-- PublicApiAnalyzers -->
<PropertyGroup>
<AddPublicApiAnalyzers>false</AddPublicApiAnalyzers>
<AddPublicApiAnalyzers Condition=" '$(AddPublicApiAnalyzers)' == '' AND !$(MSBuildProjectName.Contains('.Tests')) AND !$(MSBuildProjectName.Contains('.Resources')) ">true</AddPublicApiAnalyzers>
<AddPublicApiAnalyzers Condition=" '$(AddPublicApiAnalyzers)' == '' ">false</AddPublicApiAnalyzers>

Expand Down
4 changes: 4 additions & 0 deletions src/HotChocolate/Analyzers/src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>

<PropertyGroup>
<AddPublicApiAnalyzers>false</AddPublicApiAnalyzers>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
using System;
using System.Threading.Tasks;
using HotChocolate;
using HotChocolate.AspNetCore;
using HotChocolate.AspNetCore.Extensions;
using Microsoft.AspNetCore.Http;
Expand Down Expand Up @@ -75,6 +72,7 @@ public static GraphQLEndpointConventionBuilder MapGraphQL(
IFileProvider fileProvider = CreateFileProvider();

requestPipeline
.UseCancellation()
.UseMiddleware<WebSocketSubscriptionMiddleware>(schemaNameOrDefault)
.UseMiddleware<HttpPostMiddleware>(schemaNameOrDefault)
.UseMiddleware<HttpMultipartMiddleware>(schemaNameOrDefault)
Expand Down Expand Up @@ -157,6 +155,7 @@ public static GraphQLHttpEndpointConventionBuilder MapGraphQLHttp(
NameString schemaNameOrDefault = schemaName.HasValue ? schemaName : Schema.DefaultName;

requestPipeline
.UseCancellation()
.UseMiddleware<HttpPostMiddleware>(schemaNameOrDefault)
.UseMiddleware<HttpMultipartMiddleware>(schemaNameOrDefault)
.UseMiddleware<HttpGetMiddleware>(schemaNameOrDefault)
Expand Down Expand Up @@ -232,6 +231,7 @@ public static IEndpointConventionBuilder MapGraphQLWebSocket(
NameString schemaNameOrDefault = schemaName.HasValue ? schemaName : Schema.DefaultName;

requestPipeline
.UseCancellation()
.UseMiddleware<WebSocketSubscriptionMiddleware>(schemaNameOrDefault)
.Use(_ => context =>
{
Expand Down Expand Up @@ -305,6 +305,7 @@ public static IEndpointConventionBuilder MapGraphQLSchema(
NameString schemaNameOrDefault = schemaName.HasValue ? schemaName : Schema.DefaultName;

requestPipeline
.UseCancellation()
.UseMiddleware<HttpGetSchemaMiddleware>(
schemaNameOrDefault,
MiddlewareRoutingType.Explicit)
Expand Down Expand Up @@ -354,6 +355,7 @@ public static BananaCakePopEndpointConventionBuilder MapBananaCakePop(
IFileProvider fileProvider = CreateFileProvider();

requestPipeline
.UseCancellation()
.UseMiddleware<ToolDefaultFileMiddleware>(fileProvider, toolPath)
.UseMiddleware<ToolOptionsFileMiddleware>(toolPath)
.UseMiddleware<ToolStaticFileMiddleware>(fileProvider, toolPath)
Expand Down Expand Up @@ -436,4 +438,17 @@ private static IFileProvider CreateFileProvider()
var resourceNamespace = typeof(MiddlewareBase).Namespace + ".Resources";
return new EmbeddedFileProvider(type.Assembly, resourceNamespace);
}

private static IApplicationBuilder UseCancellation(this IApplicationBuilder builder)
=> builder.Use(next => async context =>
{
try
{
await next(context);
}
catch (OperationCanceledException)
{
// we just catch cancellations here and do nothing.
}
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ private async Task HandleRequestAsync(HttpContext context)
// in any case we will have a valid GraphQL result at this point that can be written
// to the HTTP response stream.
Debug.Assert(result is not null, "No GraphQL result was created.");
await WriteResultAsync(context.Response, result, statusCode,
context.RequestAborted);
await WriteResultAsync(context.Response, result, statusCode, context.RequestAborted);
}
finally
{
Expand All @@ -105,10 +104,7 @@ await WriteResultAsync(context.Response, result, statusCode,
await asyncDisposable.DisposeAsync();
}

if (result is IDisposable disposable)
{
disposable.Dispose();
}
result?.Dispose();
}
}
}
3 changes: 1 addition & 2 deletions src/HotChocolate/AspNetCore/src/AspNetCore/MiddlewareBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ protected async ValueTask WriteResultAsync(
{
response.ContentType = _resultSerializer.GetContentType(result);
response.StatusCode = (int)(statusCode ?? _resultSerializer.GetStatusCode(result));

await _resultSerializer.SerializeAsync(result, response.Body, cancellationToken);
}

Expand All @@ -77,7 +76,7 @@ protected async Task<IExecutionResult> ExecuteSingleAsync(
GraphQLRequest request,
OperationType[]? allowedOperations = null)
{
QueryRequestBuilder requestBuilder = QueryRequestBuilder.From(request);
var requestBuilder = QueryRequestBuilder.From(request);
requestBuilder.SetAllowedOperations(allowedOperations);

await requestInterceptor.OnCreateAsync(
Expand Down
13 changes: 8 additions & 5 deletions src/HotChocolate/Benchmarks/execution.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#!/bin/sh

BASEDIR=$(dirname "$0")
src=$BASEDIR/src

rm -rf BenchmarkDotNet.Artifacts
rm -rf src/Benchmarks.Execution/bin
rm -rf src/Benchmarks.Execution/obj
rm -rf $src/Benchmarks.Execution/bin
rm -rf $src/Benchmarks.Execution/obj

dotnet run --project src/Benchmarks.Execution/ -c release --filter HotChocolate.Benchmarks.*
dotnet run --project $src/Benchmarks.Execution/ -c release --filter HotChocolate.Benchmarks.Extension*

rm -rf src/Benchmarks.Execution/bin
rm -rf src/Benchmarks.Execution/obj
rm -rf $src/Benchmarks.Execution/bin
rm -rf $src/Benchmarks.Execution/obj
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@

using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics.CodeAnalysis;
using BenchmarkDotNet.Attributes;

namespace HotChocolate.Benchmarks;

[RPlotExporter, CategoriesColumn, RankColumn, MeanColumn, MedianColumn, MemoryDiagnoser]
public class ExtensionDataBenchmarks
{
private readonly ExtensionData data1 = new ExtensionData { ["abc"] = "abc" };
private readonly ExtensionData2 data2 = new ExtensionData2 { ["abc"] = "abc" };

[Benchmark]
public ExtensionData Create_ExtensionData()
=> new();

[Benchmark]
public ExtensionData2 Create_ExtensionData_2()
=> new();

[Benchmark]
public ExtensionData Create_ExtensionData_Set_1()
{
var data = new ExtensionData();
data["1"] = "1";
return data;
}

[Benchmark]
public ExtensionData2 Create_ExtensionData_2_Set_1()
{
var data = new ExtensionData2();
data["1"] = "1";
return data;
}

[Benchmark]
public ExtensionData Create_ExtensionData_Set_2()
{
var data = new ExtensionData();
for (int i = 0; i < 2; i++)
{
data[i.ToString()] = i;
}
return data;
}

[Benchmark]
public ExtensionData2 Create_ExtensionData_2_Set_2()
{
var data = new ExtensionData2();
for (int i = 0; i < 2; i++)
{
data[i.ToString()] = i;
}
return data;
}

[Benchmark]
public ExtensionData Create_ExtensionData_Set_10()
{
var data = new ExtensionData();
for (int i = 0; i < 10; i++)
{
data[i.ToString()] = i;
}
return data;
}

[Benchmark]
public ExtensionData2 Create_ExtensionData_2_Set_10()
{
var data = new ExtensionData2();
for (int i = 0; i < 10; i++)
{
data[i.ToString()] = i;
}
return data;
}

[Benchmark]
public object? Create_ExtensionData_Get_1()
{
return data1["abc"];
}

[Benchmark]
public object? Create_ExtensionData_2_Get_1()
{
return data2["abc"];
}
}


public class ExtensionData2 : IDictionary<string, object?>
{
private IDictionary<string, object?>? _;

private IDictionary<string, object?> Dict()
=> _ ??= new Dictionary<string, object?>();

public object? this[string key]
{
get => Dict()[key];
set => Dict()[key] = value;
}

public ICollection<string> Keys => throw new NotImplementedException();

public ICollection<object?> Values => throw new NotImplementedException();

public int Count => throw new NotImplementedException();

public bool IsReadOnly => throw new NotImplementedException();

public void Add(string key, object? value)
{
throw new NotImplementedException();
}

public void Add(KeyValuePair<string, object?> item)
{
throw new NotImplementedException();
}

public void Clear()
{
throw new NotImplementedException();
}

public bool Contains(KeyValuePair<string, object?> item)
{
throw new NotImplementedException();
}

public bool ContainsKey(string key)
{
throw new NotImplementedException();
}

public void CopyTo(KeyValuePair<string, object?>[] array, int arrayIndex)
{
throw new NotImplementedException();
}

public IEnumerator<KeyValuePair<string, object?>> GetEnumerator()
{
throw new NotImplementedException();
}

public bool Remove(string key)
{
throw new NotImplementedException();
}

public bool Remove(KeyValuePair<string, object?> item)
{
throw new NotImplementedException();
}

public bool TryGetValue(string key, [MaybeNullWhen(false)] out object? value)
{
throw new NotImplementedException();
}

IEnumerator IEnumerable.GetEnumerator()
{
throw new NotImplementedException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using HotChocolate.Benchmarks;
using HotChocolate.ConferencePlanner;
using HotChocolate.ConferencePlanner.DataLoader;
using HotChocolate.Types.Descriptors.Definitions;

public static class Program
{
Expand All @@ -19,6 +20,10 @@ public static class Program

private static async Task Run()
{
var schemaBench = new SchemaBuildingBenchmarks();
await schemaBench.CreateSchema_SchemaFirst_Large();
Console.ReadLine();

Console.WriteLine("Initialize");
var queryBench = new QueryBenchmarks();

Expand Down
Loading

0 comments on commit 447bf4f

Please sign in to comment.