Browse Source

optimize first run (#2516)

* do not accept ui requests until database is ready

* add empty database to greatly speed up initial startup

* remove middleware
pull/2517/head
Jason Dove 3 months ago committed by GitHub
parent
commit
48310e044b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 1
      CHANGELOG.md
  2. 1
      ErsatzTV/ErsatzTV.csproj
  3. BIN
      ErsatzTV/Resources/empty.sqlite3
  4. 20
      ErsatzTV/Services/RunOnce/DatabaseMigratorService.cs

1
CHANGELOG.md

@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). @@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Add `get_directory_name` and `get_filename_without_extension` functions for path processing
- Add `Block Playout Troubleshooting` tool to help investigate block playout history
- Add sequential schedule file and scripted schedule file names to playouts table
- Add empty (but already up-to-date) sqlite3 database to greatly speed up initial startup for fresh installs
### Fixed
- Fix NVIDIA startup errors on arm64

1
ErsatzTV/ErsatzTV.csproj

@ -101,6 +101,7 @@ @@ -101,6 +101,7 @@
<EmbeddedResource Include="Resources\Templates\_song.sbntxt" />
<EmbeddedResource Include="Resources\sequential-schedule-import.schema.json" />
<EmbeddedResource Include="Resources\sequential-schedule.schema.json" />
<EmbeddedResource Include="Resources\empty.sqlite3" />
</ItemGroup>
<ItemGroup>

BIN
ErsatzTV/Resources/empty.sqlite3

Binary file not shown.

20
ErsatzTV/Services/RunOnce/DatabaseMigratorService.cs

@ -1,4 +1,5 @@ @@ -1,4 +1,5 @@
using Dapper;
using System.Reflection;
using Dapper;
using ErsatzTV.Core;
using ErsatzTV.Infrastructure.Data;
using Microsoft.Data.Sqlite;
@ -26,11 +27,24 @@ public class DatabaseMigratorService : BackgroundService @@ -26,11 +27,24 @@ public class DatabaseMigratorService : BackgroundService
{
await Task.Yield();
_logger.LogInformation("Applying database migrations");
using IServiceScope scope = _serviceScopeFactory.CreateScope();
await using TvContext dbContext = scope.ServiceProvider.GetRequiredService<TvContext>();
// extract empty database to speed up initial startup
if (TvContext.IsSqlite && !File.Exists(FileSystemLayout.DatabasePath))
{
_logger.LogInformation("Extracting empty database to {DatabasePath}", FileSystemLayout.DatabasePath);
await using Stream resource = typeof(ResourceExtractorService).GetTypeInfo().Assembly
.GetManifestResourceStream("ErsatzTV.Resources.empty.sqlite3");
if (resource != null)
{
await using FileStream fs = File.Create(FileSystemLayout.DatabasePath);
await resource.CopyToAsync(fs, stoppingToken);
}
}
_logger.LogInformation("Applying database migrations");
if (TvContext.IsSqlite)
{
int count = await dbContext.Connection.ExecuteScalarAsync<int>(

Loading…
Cancel
Save