From c5265943f50c57aaae884135fc36500b23c768e9 Mon Sep 17 00:00:00 2001 From: Jason Dove <1695733+jasongdove@users.noreply.github.com> Date: Fri, 12 Sep 2025 22:42:54 -0500 Subject: [PATCH] fix inefficient database migration (#2411) --- CHANGELOG.md | 1 + ...25155751_Populate_PlayoutHistory_Finish.cs | 29 +++++++++++------ ...25155536_Populate_PlayoutHistory_Finish.cs | 31 +++++++++++++------ ErsatzTV/appsettings.json | 2 +- 4 files changed, 44 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0116736a2..b366e8d5f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,6 +47,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Fix watermarks and graphics elements when `Scaling Behavior` is `Crop` - Fix hardware acceleration health check message on mobile - Fix deco selection logic +- Fix inefficient database migration that would cause database initialization to get stuck ### Changed - **BREAKING CHANGE**: change how `Scripted Schedule` system works diff --git a/ErsatzTV.Infrastructure.MySql/Migrations/20250825155751_Populate_PlayoutHistory_Finish.cs b/ErsatzTV.Infrastructure.MySql/Migrations/20250825155751_Populate_PlayoutHistory_Finish.cs index a1ace9b80..703d94098 100644 --- a/ErsatzTV.Infrastructure.MySql/Migrations/20250825155751_Populate_PlayoutHistory_Finish.cs +++ b/ErsatzTV.Infrastructure.MySql/Migrations/20250825155751_Populate_PlayoutHistory_Finish.cs @@ -10,17 +10,28 @@ namespace ErsatzTV.Infrastructure.MySql.Migrations /// protected override void Up(MigrationBuilder migrationBuilder) { + migrationBuilder.CreateIndex( + name: "IX_PlayoutItem_PlayoutId_Start", + table: "PlayoutItem", + columns: new[] { "PlayoutId", "Start" }); + + migrationBuilder.CreateIndex( + name: "IX_PlayoutHistory_PlayoutId_When", + table: "PlayoutHistory", + columns: new[] { "PlayoutId", "When" }); + migrationBuilder.Sql( @"UPDATE PlayoutHistory - SET Finish = - (SELECT PlayoutItem.Finish - FROM PlayoutItem - WHERE PlayoutItem.PlayoutId = PlayoutHistory.PlayoutId - AND PlayoutItem.Start = PlayoutHistory.`When`) - WHERE EXISTS (SELECT 1 - FROM PlayoutItem - WHERE PlayoutItem.PlayoutId = PlayoutHistory.PlayoutId - AND PlayoutItem.Start = PlayoutHistory.`When`);"); + JOIN PlayoutItem ON PlayoutHistory.PlayoutId = PlayoutItem.PlayoutId AND PlayoutHistory.`When` = PlayoutItem.Start + SET PlayoutHistory.Finish = PlayoutItem.Finish"); + + migrationBuilder.DropIndex( + name: "IX_PlayoutItem_PlayoutId_Start", + table: "PlayoutItem"); + + migrationBuilder.DropIndex( + name: "IX_PlayoutHistory_PlayoutId_When", + table: "PlayoutHistory"); } /// diff --git a/ErsatzTV.Infrastructure.Sqlite/Migrations/20250825155536_Populate_PlayoutHistory_Finish.cs b/ErsatzTV.Infrastructure.Sqlite/Migrations/20250825155536_Populate_PlayoutHistory_Finish.cs index b7e6dc1eb..505ba808e 100644 --- a/ErsatzTV.Infrastructure.Sqlite/Migrations/20250825155536_Populate_PlayoutHistory_Finish.cs +++ b/ErsatzTV.Infrastructure.Sqlite/Migrations/20250825155536_Populate_PlayoutHistory_Finish.cs @@ -10,17 +10,30 @@ namespace ErsatzTV.Infrastructure.Sqlite.Migrations /// protected override void Up(MigrationBuilder migrationBuilder) { + migrationBuilder.CreateIndex( + name: "IX_PlayoutItem_PlayoutId_Start", + table: "PlayoutItem", + columns: new[] { "PlayoutId", "Start" }); + + migrationBuilder.CreateIndex( + name: "IX_PlayoutHistory_PlayoutId_When", + table: "PlayoutHistory", + columns: new[] { "PlayoutId", "When" }); + migrationBuilder.Sql( @"UPDATE PlayoutHistory - SET Finish = - (SELECT PlayoutItem.Finish - FROM PlayoutItem - WHERE PlayoutItem.PlayoutId = PlayoutHistory.PlayoutId - AND PlayoutItem.Start = PlayoutHistory.`When`) - WHERE EXISTS (SELECT 1 - FROM PlayoutItem - WHERE PlayoutItem.PlayoutId = PlayoutHistory.PlayoutId - AND PlayoutItem.Start = PlayoutHistory.`When`);"); + SET Finish = PlayoutItem.Finish + FROM PlayoutItem + WHERE PlayoutHistory.PlayoutId = PlayoutItem.PlayoutId + AND PlayoutHistory.`When` = PlayoutItem.Start;"); + + migrationBuilder.DropIndex( + name: "IX_PlayoutItem_PlayoutId_Start", + table: "PlayoutItem"); + + migrationBuilder.DropIndex( + name: "IX_PlayoutHistory_PlayoutId_When", + table: "PlayoutHistory"); } /// diff --git a/ErsatzTV/appsettings.json b/ErsatzTV/appsettings.json index 85bcf34ea..695e2fc37 100644 --- a/ErsatzTV/appsettings.json +++ b/ErsatzTV/appsettings.json @@ -23,4 +23,4 @@ "ApiKey": "f59f3cc93cce91210a5c0f047eb2047c", "Enable": true } -} \ No newline at end of file +}