Skip to content

Commit 151e107

Browse files
authored
Not using Task.Result in async context. (#8307)
1 parent 96ee321 commit 151e107

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

src/NuGetGallery/Services/SqlAggregateStatsService.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ public SqlAggregateStatsService(IAppConfiguration configuration, ISqlConnectionF
2626
_connectionFactory = galleryDbConnectionFactory;
2727
}
2828

29-
public Task<AggregateStats> GetAggregateStats()
29+
public async Task<AggregateStats> GetAggregateStats()
3030
{
31-
var connection = Task.Run(() => _connectionFactory.CreateAsync()).Result;
31+
var connection = await _connectionFactory.CreateAsync();
3232
using (var dbContext = new EntitiesContext(connection, readOnly: true)) // true - set readonly but it is ignored anyway, as this class doesn't call EntitiesContext.SaveChanges()
3333
{
3434
var database = dbContext.Database;
@@ -41,15 +41,15 @@ public Task<AggregateStats> GetAggregateStats()
4141
bool hasData = reader.Read();
4242
if (!hasData)
4343
{
44-
return Task.FromResult(new AggregateStats());
44+
return new AggregateStats();
4545
}
4646

47-
return Task.FromResult(new AggregateStats
47+
return new AggregateStats
4848
{
4949
Downloads = reader.IsDBNull(0) ? 0 : reader.GetInt32(0),
5050
UniquePackages = reader.IsDBNull(1) ? 0 : reader.GetInt32(1),
5151
TotalPackages = reader.IsDBNull(2) ? 0 : reader.GetInt32(2)
52-
});
52+
};
5353
}
5454
}
5555
}

0 commit comments

Comments
 (0)