Skip to content

Commit 4e4a15d

Browse files
committed
Small optimizations
1 parent da63315 commit 4e4a15d

File tree

3 files changed

+6
-15
lines changed

3 files changed

+6
-15
lines changed

Common/OpenShockServiceHelper.cs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,8 @@ static bool HandleRankCheck(AuthorizationHandlerContext context, RankType requir
3434
{
3535
var ranks = context.User.Identities.SelectMany(ident => ident.Claims.Where(claim => claim.Type == ident.RoleClaimType)).Select(claim => Enum.Parse<RankType>(claim.Value)).ToList();
3636

37-
if (!ranks.Any())
38-
{
39-
return false;
40-
}
41-
42-
if (ranks.Max() < requiredRank)
43-
{
44-
return false;
45-
}
46-
47-
return true;
37+
// Has any rank that is higher than required rank
38+
return ranks.Count != 0 && ranks.Max() >= requiredRank;
4839
}
4940

5041
/// <summary>

Common/Swagger/SwaggerGenExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public static IServiceCollection AddSwaggerExt<TProgram>(this IServiceCollection
105105
public static IApplicationBuilder UseSwaggerExt(this WebApplication app)
106106
{
107107
var provider = app.Services.GetRequiredService<IApiVersionDescriptionProvider>();
108-
var groupNames = provider.ApiVersionDescriptions.Select(d => d.GroupName).ToList();
108+
var groupNames = provider.ApiVersionDescriptions.Select(d => d.GroupName);
109109

110110
return app
111111
.UseSwagger()

LiveControlGateway/LifetimeManager/HubLifetime.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,13 @@ public async Task UpdateDevice()
152152
private async Task UpdateShockers(OpenShockContext db)
153153
{
154154
_logger.LogDebug("Updating shockers for device [{DeviceId}]", HubController.Id);
155-
var ownShockers = await db.Shockers.Where(x => x.Device == HubController.Id).Select(x => new ShockerState()
155+
156+
_shockerStates = await db.Shockers.Where(x => x.Device == HubController.Id).Select(x => new ShockerState()
156157
{
157158
Id = x.Id,
158159
Model = x.Model,
159160
RfId = x.RfId
160-
}).ToListAsync(cancellationToken: _cancellationToken);
161-
_shockerStates = ownShockers.ToDictionary(x => x.Id, x => x);
161+
}).ToDictionaryAsync(x => x.Id, x => x, cancellationToken: _cancellationToken);
162162
}
163163

164164
/// <summary>

0 commit comments

Comments
 (0)