Skip to content

Commit

Permalink
Optimize json file deserialization
Browse files Browse the repository at this point in the history
  • Loading branch information
Lehats committed Dec 6, 2024
1 parent 796339f commit 4076c69
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/api/Controllers/UploadController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,11 @@ public async Task<ActionResult<int>> UploadJsonFileAsync(int workgroupId, IFormF

try
{
using var reader = new StreamReader(file.OpenReadStream());
List<BoreholeImport>? boreholes;

try
{
boreholes = JsonSerializer.Deserialize<List<BoreholeImport>>(await reader.ReadToEndAsync().ConfigureAwait(false), jsonImportOptions);
using var stream = file.OpenReadStream();
boreholes = JsonSerializer.Deserialize<List<BoreholeImport>>(stream, jsonImportOptions);

Check failure on line 74 in src/api/Controllers/UploadController.cs

View workflow job for this annotation

GitHub Actions / Build and run tests

'JsonSerializer.Deserialize<List<BoreholeImport>>(Stream, JsonSerializerOptions?)' synchronously blocks. Await 'JsonSerializer.DeserializeAsync<TValue>(Stream, JsonSerializerOptions?, CancellationToken)' instead. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1849)

Check failure on line 74 in src/api/Controllers/UploadController.cs

View workflow job for this annotation

GitHub Actions / Build and run tests

'JsonSerializer.Deserialize<List<BoreholeImport>>(Stream, JsonSerializerOptions?)' synchronously blocks. Await 'JsonSerializer.DeserializeAsync<TValue>(Stream, JsonSerializerOptions?, CancellationToken)' instead. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1849)

Check failure on line 74 in src/api/Controllers/UploadController.cs

View workflow job for this annotation

GitHub Actions / Run cypress tests (1)

'JsonSerializer.Deserialize<List<BoreholeImport>>(Stream, JsonSerializerOptions?)' synchronously blocks. Await 'JsonSerializer.DeserializeAsync<TValue>(Stream, JsonSerializerOptions?, CancellationToken)' instead. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1849)

Check failure on line 74 in src/api/Controllers/UploadController.cs

View workflow job for this annotation

GitHub Actions / Run cypress tests (1)

'JsonSerializer.Deserialize<List<BoreholeImport>>(Stream, JsonSerializerOptions?)' synchronously blocks. Await 'JsonSerializer.DeserializeAsync<TValue>(Stream, JsonSerializerOptions?, CancellationToken)' instead. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1849)

Check failure on line 74 in src/api/Controllers/UploadController.cs

View workflow job for this annotation

GitHub Actions / Run cypress tests (2)

'JsonSerializer.Deserialize<List<BoreholeImport>>(Stream, JsonSerializerOptions?)' synchronously blocks. Await 'JsonSerializer.DeserializeAsync<TValue>(Stream, JsonSerializerOptions?, CancellationToken)' instead. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1849)

Check failure on line 74 in src/api/Controllers/UploadController.cs

View workflow job for this annotation

GitHub Actions / Run cypress tests (2)

'JsonSerializer.Deserialize<List<BoreholeImport>>(Stream, JsonSerializerOptions?)' synchronously blocks. Await 'JsonSerializer.DeserializeAsync<TValue>(Stream, JsonSerializerOptions?, CancellationToken)' instead. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1849)

Check failure on line 74 in src/api/Controllers/UploadController.cs

View workflow job for this annotation

GitHub Actions / Run cypress tests (3)

'JsonSerializer.Deserialize<List<BoreholeImport>>(Stream, JsonSerializerOptions?)' synchronously blocks. Await 'JsonSerializer.DeserializeAsync<TValue>(Stream, JsonSerializerOptions?, CancellationToken)' instead. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1849)

Check failure on line 74 in src/api/Controllers/UploadController.cs

View workflow job for this annotation

GitHub Actions / Run cypress tests (3)

'JsonSerializer.Deserialize<List<BoreholeImport>>(Stream, JsonSerializerOptions?)' synchronously blocks. Await 'JsonSerializer.DeserializeAsync<TValue>(Stream, JsonSerializerOptions?, CancellationToken)' instead. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1849)

Check failure on line 74 in src/api/Controllers/UploadController.cs

View workflow job for this annotation

GitHub Actions / Run cypress tests (4)

'JsonSerializer.Deserialize<List<BoreholeImport>>(Stream, JsonSerializerOptions?)' synchronously blocks. Await 'JsonSerializer.DeserializeAsync<TValue>(Stream, JsonSerializerOptions?, CancellationToken)' instead. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1849)

Check failure on line 74 in src/api/Controllers/UploadController.cs

View workflow job for this annotation

GitHub Actions / Run cypress tests (4)

'JsonSerializer.Deserialize<List<BoreholeImport>>(Stream, JsonSerializerOptions?)' synchronously blocks. Await 'JsonSerializer.DeserializeAsync<TValue>(Stream, JsonSerializerOptions?, CancellationToken)' instead. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1849)

Check failure on line 74 in src/api/Controllers/UploadController.cs

View workflow job for this annotation

GitHub Actions / Run cypress tests (5)

'JsonSerializer.Deserialize<List<BoreholeImport>>(Stream, JsonSerializerOptions?)' synchronously blocks. Await 'JsonSerializer.DeserializeAsync<TValue>(Stream, JsonSerializerOptions?, CancellationToken)' instead. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1849)

Check failure on line 74 in src/api/Controllers/UploadController.cs

View workflow job for this annotation

GitHub Actions / Run cypress tests (5)

'JsonSerializer.Deserialize<List<BoreholeImport>>(Stream, JsonSerializerOptions?)' synchronously blocks. Await 'JsonSerializer.DeserializeAsync<TValue>(Stream, JsonSerializerOptions?, CancellationToken)' instead. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1849)
}
catch (JsonException ex)
{
Expand Down

0 comments on commit 4076c69

Please sign in to comment.