mirror of
https://github.com/aaru-dps/Aaru.Server.git
synced 2025-12-16 19:24:27 +00:00
Fix charts crashing on initialization.
This commit is contained in:
@@ -15,6 +15,7 @@ public partial class Devices
|
||||
List<long> _devicesByManufacturerCounts = [];
|
||||
string[] _devicesByManufacturerLabels = [];
|
||||
Carousel? _devicesCarousel;
|
||||
bool _isAlreadyInitialized;
|
||||
List<DeviceItem> DevicesList { get; set; } = [];
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -29,6 +30,15 @@ public partial class Devices
|
||||
.ThenBy(static device => device.Revision)
|
||||
.ThenBy(static device => device.Bus)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if(_isAlreadyInitialized) return;
|
||||
|
||||
_isAlreadyInitialized = true;
|
||||
await using DbContext ctx = await DbContextFactory.CreateDbContextAsync();
|
||||
|
||||
var data = await ctx.DeviceStats.Select(static d => d.Bus)
|
||||
.Distinct()
|
||||
|
||||
@@ -10,6 +10,7 @@ public partial class Filesystems
|
||||
PieChart<long>? _filesystemsChart;
|
||||
List<long> _filesystemsCounts = [];
|
||||
string[] _filesystemsLabels = [];
|
||||
bool _isAlreadyInitialized;
|
||||
List<Filesystem> FilesystemsList { get; set; } = [];
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -20,6 +21,15 @@ public partial class Filesystems
|
||||
await using DbContext ctx = await DbContextFactory.CreateDbContextAsync();
|
||||
|
||||
FilesystemsList = await ctx.Filesystems.OrderBy(static filesystem => filesystem.Name).ToListAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if(_isAlreadyInitialized) return;
|
||||
|
||||
_isAlreadyInitialized = true;
|
||||
await using DbContext ctx = await DbContextFactory.CreateDbContextAsync();
|
||||
|
||||
_filesystemsLabels = await ctx.Filesystems.OrderByDescending(static o => o.Count)
|
||||
.Take(10)
|
||||
|
||||
@@ -10,6 +10,7 @@ public partial class Filters
|
||||
PieChart<long>? _filtersChart;
|
||||
List<long> _filtersCounts = [];
|
||||
string[] _filtersLabels = [];
|
||||
bool _isAlreadyInitialized;
|
||||
List<Filter> FiltersList { get; set; } = [];
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -20,6 +21,15 @@ public partial class Filters
|
||||
await using DbContext ctx = await DbContextFactory.CreateDbContextAsync();
|
||||
|
||||
FiltersList = await ctx.Filters.OrderBy(static filter => filter.Name).ToListAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if(_isAlreadyInitialized) return;
|
||||
|
||||
_isAlreadyInitialized = true;
|
||||
await using DbContext ctx = await DbContextFactory.CreateDbContextAsync();
|
||||
|
||||
_filtersLabels = await ctx.Filters.OrderByDescending(static o => o.Count)
|
||||
.Take(10)
|
||||
|
||||
@@ -10,6 +10,7 @@ public partial class Formats
|
||||
PieChart<long>? _formatsChart;
|
||||
List<long> _formatsCounts = [];
|
||||
string[] _formatsLabels = [];
|
||||
bool _isAlreadyInitialized;
|
||||
List<MediaFormat> MediaImages { get; set; } = [];
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -18,7 +19,15 @@ public partial class Formats
|
||||
await base.OnInitializedAsync();
|
||||
|
||||
await using DbContext ctx = await DbContextFactory.CreateDbContextAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if(_isAlreadyInitialized) return;
|
||||
|
||||
_isAlreadyInitialized = true;
|
||||
await using DbContext ctx = await DbContextFactory.CreateDbContextAsync();
|
||||
|
||||
MediaImages = await ctx.MediaFormats.OrderBy(static format => format.Name).ToListAsync();
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ namespace Aaru.Server.Components.Pages.Statistics;
|
||||
|
||||
public partial class OperatingSystems
|
||||
{
|
||||
bool _isAlreadyInitialized;
|
||||
PieChart<long>? _linuxChart;
|
||||
List<long> _linuxCounts = [];
|
||||
string[] _linuxLabels = [];
|
||||
@@ -43,6 +44,17 @@ public partial class OperatingSystems
|
||||
})
|
||||
.ToListAsync()).OrderBy(static os => os.name)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if(_isAlreadyInitialized) return;
|
||||
|
||||
_isAlreadyInitialized = true;
|
||||
|
||||
// TODO: Cache real OS name in database, lookups would be much faster
|
||||
await using DbContext ctx = await DbContextFactory.CreateDbContextAsync();
|
||||
|
||||
var osQuery = ctx.OperatingSystems.GroupBy(static x => new
|
||||
{
|
||||
|
||||
@@ -7,6 +7,7 @@ namespace Aaru.Server.Components.Pages.Statistics;
|
||||
|
||||
public partial class Partitions
|
||||
{
|
||||
bool _isAlreadyInitialized;
|
||||
PieChart<long>? _partitionsChart;
|
||||
List<long> _partitionsCounts = [];
|
||||
string[] _partitionsLabels = [];
|
||||
@@ -18,6 +19,15 @@ public partial class Partitions
|
||||
await base.OnInitializedAsync();
|
||||
|
||||
await using DbContext ctx = await DbContextFactory.CreateDbContextAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if(_isAlreadyInitialized) return;
|
||||
|
||||
_isAlreadyInitialized = true;
|
||||
await using DbContext ctx = await DbContextFactory.CreateDbContextAsync();
|
||||
|
||||
PartitionsList = await ctx.Partitions.OrderBy(static partition => partition.Name).ToListAsync();
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ namespace Aaru.Server.Components.Pages.Statistics;
|
||||
|
||||
public partial class RealMedias
|
||||
{
|
||||
bool _isAlreadyInitialized;
|
||||
PieChart<long>? _realMediaChart;
|
||||
List<long> _realMediaCounts = [];
|
||||
string[] _realMediaLabels = [];
|
||||
@@ -20,6 +21,15 @@ public partial class RealMedias
|
||||
await base.OnInitializedAsync();
|
||||
|
||||
await using DbContext ctx = await DbContextFactory.CreateDbContextAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if(_isAlreadyInitialized) return;
|
||||
|
||||
_isAlreadyInitialized = true;
|
||||
await using DbContext ctx = await DbContextFactory.CreateDbContextAsync();
|
||||
|
||||
Media[] realMedias = await ctx.Medias.Where(static o => o.Real)
|
||||
.OrderByDescending(static o => o.Count)
|
||||
|
||||
@@ -7,6 +7,7 @@ namespace Aaru.Server.Components.Pages.Statistics;
|
||||
|
||||
public partial class Versions
|
||||
{
|
||||
bool _isAlreadyInitialized;
|
||||
PieChart<long>? _versionsChart;
|
||||
List<long> _versionsCounts = [];
|
||||
string[] _versionsLabels = [];
|
||||
@@ -26,6 +27,15 @@ public partial class Versions
|
||||
})
|
||||
.ToListAsync()).OrderBy(static version => version.name)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if(_isAlreadyInitialized) return;
|
||||
|
||||
_isAlreadyInitialized = true;
|
||||
await using DbContext ctx = await DbContextFactory.CreateDbContextAsync();
|
||||
|
||||
_versionsLabels = await ctx.Versions.OrderByDescending(static o => o.Count)
|
||||
.Take(10)
|
||||
|
||||
@@ -9,6 +9,7 @@ namespace Aaru.Server.Components.Pages.Statistics;
|
||||
|
||||
public partial class VirtualMedias
|
||||
{
|
||||
bool _isAlreadyInitialized;
|
||||
PieChart<long>? _virtualMediaChart;
|
||||
List<long> _virtualMediaCounts = [];
|
||||
string[] _virtualMediaLabels = [];
|
||||
@@ -20,6 +21,15 @@ public partial class VirtualMedias
|
||||
await base.OnInitializedAsync();
|
||||
|
||||
await using DbContext ctx = await DbContextFactory.CreateDbContextAsync();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if(_isAlreadyInitialized) return;
|
||||
|
||||
_isAlreadyInitialized = true;
|
||||
await using DbContext ctx = await DbContextFactory.CreateDbContextAsync();
|
||||
|
||||
Media[] virtualMedias = await ctx.Medias.Where(static o => !o.Real)
|
||||
.OrderByDescending(static o => o.Count)
|
||||
|
||||
Reference in New Issue
Block a user