Skip to content

Commit 4cd76c3

Browse files
authored
Added debug exp date
1 parent a38c1dd commit 4cd76c3

File tree

4 files changed

+51
-13
lines changed

4 files changed

+51
-13
lines changed

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"type": "blazorwasm",
77
"request": "launch",
88
"hosted": true,
9-
"preLaunchTask": "build",
9+
"preLaunchTask": "build dotnet",
1010
"program": "${workspaceFolder}/Jellyfin.HardwareVisualizer/Server/bin/Debug/net8.0/Jellyfin.HardwareVisualizer.Server.dll",
1111
"cwd": "${workspaceFolder}/Jellyfin.HardwareVisualizer",
1212
"internalConsoleOptions": "openOnSessionStart",

Jellyfin.HardwareVisualizer/Server/Controllers/SubmissionApiController.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,21 @@ public async Task<IActionResult> GetData([FromQuery, Required]string deviceId)
129129
var data = await _submissionService.GetSubmissions(deviceId);
130130
return Ok(_mapperService.ViewModelMapper.Map<IEnumerable<HardwareDisplayModel>>(data));
131131
}
132+
133+
134+
#if DEBUG
135+
/// <summary>
136+
/// Gets a set of aggregated data points of all submissions for the given <see cref="deviceId"/>
137+
/// </summary>
138+
/// <param name="deviceId"></param>
139+
/// <returns></returns>
140+
[HttpGet("Recalc")]
141+
//[EnableRateLimiting("fixed_metadata")]
142+
public IActionResult Recalc([FromQuery, Required]Guid groupId)
143+
{
144+
_submissionService.BeginRecalcHardwareStats(groupId);
145+
return Ok();
146+
}
147+
#endif
148+
132149
}

Jellyfin.HardwareVisualizer/Server/Services/HangfireServices/RecalculateHardwareInfoJob.cs

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,48 @@ public async Task RecalcHardwareStats(Guid deviceId)
2020
try
2121
{
2222
await using var db = await _dbContextFactory.CreateDbContextAsync();
23-
var submissionsByGpu =
24-
await db.HardwareSurveyEntries.Where(e => e.GpuType.Id == deviceId || e.CpuType.Id == deviceId).GroupBy(
25-
e => new
23+
var cpuDevice = await db.CpuTypes.FirstOrDefaultAsync(e => e.Id == deviceId);
24+
var gpuDevice = await db.GpuTypes.FirstOrDefaultAsync(e => e.Id == deviceId);
25+
26+
if(cpuDevice is null && gpuDevice is null)
27+
{
28+
throw new Exception("Cannot determine device type");
29+
}
30+
31+
IQueryable<HardwareSurveyEntry> query = db.HardwareSurveyEntries;
32+
33+
if(cpuDevice is not null)
34+
{
35+
query = query.Where(e => e.CpuType.Id == deviceId);
36+
}
37+
else
38+
{
39+
query = query.Where(e => e.GpuType.Id == deviceId);
40+
}
41+
42+
var submissions = await query
43+
.GroupBy(e => new
2644
{
27-
DeviceType = e.GpuType == null ? DeviceType.Cpu : DeviceType.Gpu,
28-
DeviceName = e.GpuType!.Name ?? e.CpuType!.Name,
2945
CodecName = e.HardwareCodec.Name,
3046
From = e.FromResolution.Name,
3147
To = e.ToResolution.Name,
3248
})
49+
.ToArrayAsync()
50+
.ConfigureAwait(true);
51+
52+
var submissionsByGpu =
53+
submissions
3354
.Select(e => new HardwareDisplay()
3455
{
3556
HardwareCodec = e.Key.CodecName,
3657
Diviation = 0,
3758
FromResolution = e.Key.From,
3859
ToResolution = e.Key.To,
39-
DeviceType = e.Key.DeviceType,
40-
DeviceName = e.Key.DeviceName,
60+
DeviceType = cpuDevice == null ? DeviceType.Gpu : DeviceType.Cpu,
61+
DeviceName = gpuDevice?.Name ?? cpuDevice!.Name,
4162
MaxStreams = e.Average(f => f.MaxStreams)
4263
})
43-
.ToArrayAsync()
44-
.ConfigureAwait(true);
64+
.ToArray();
4565

4666
var changedDevices = submissionsByGpu.Select(e => e.DeviceName).Distinct().ToArray();
4767

Jellyfin.HardwareVisualizer/Server/Services/SubmitToken/SubmitTokenService.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ public bool Validate(JwtPayload token, out TimeSpan? retryAfter)
7474
var ipAddress = _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString();
7575

7676
var cacheKey = "ip-token-" + ipAddress;
77-
if (_memoryCache.TryGetValue<TokenStore>(cacheKey, out var tokenStore) && tokenStore.JwtPayload.ValidTo > DateTime.UtcNow)
77+
if (_memoryCache.TryGetValue<TokenStore>(cacheKey, out var tokenStore)
78+
&& tokenStore.JwtPayload.ValidTo > DateTime.UtcNow)
7879
{
7980
if (tokenStore.Expired)
8081
{
@@ -84,12 +85,12 @@ public bool Validate(JwtPayload token, out TimeSpan? retryAfter)
8485
return (Encrypt(tokenStore.JwtPayload), null);
8586
}
8687

87-
var expiresAt = DateTime.UtcNow.AddHours(4);
88+
var expiresAt = DateTime.UtcNow.AddHours(10);
8889
tokenStore = new TokenStore();
8990
tokenStore.JwtPayload = new JwtPayload("jhwa/server", "jhwa/client", [new Claim("ip", ipAddress)],
9091
DateTime.UtcNow, expiresAt, DateTime.UtcNow);
9192

92-
_memoryCache.Set(cacheKey, tokenStore, expiresAt);
93+
_memoryCache.Set(cacheKey, tokenStore, DateTime.Now.AddMinutes(10));
9394
return (Encrypt(tokenStore.JwtPayload), null);
9495
}
9596

0 commit comments

Comments
 (0)