From eb452cb322250418860f4af8e2618d623b4a0e5f Mon Sep 17 00:00:00 2001 From: Hamid Reza Mohammadi Date: Sat, 8 Aug 2026 08:04:48 +0330 Subject: [PATCH] tajik backend fix --- RMuseum/Controllers/GanjoorController.cs | 8 ++--- RMuseum/Services/IGanjoorService.cs | 7 ++--- .../GanjoorService-Tajik.cs | 29 +++++++++++-------- 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/RMuseum/Controllers/GanjoorController.cs b/RMuseum/Controllers/GanjoorController.cs index 9b104cc9..57d1ff37 100644 --- a/RMuseum/Controllers/GanjoorController.cs +++ b/RMuseum/Controllers/GanjoorController.cs @@ -4547,10 +4547,10 @@ namespace RMuseum.Controllers } /// - /// recovery job: regenerates TajikHtmlText for every Tajik poem from its TajikVerses, - /// overwriting whatever is currently stored - use after RegenerateTajikCatAndPoetHtmlText - /// (or anything else) may have corrupted poem pages. Check the Admin area's - /// LongRunningJobs page for progress. + /// recovery job: regenerates TajikHtmlText for Tajik poems whose stored HTML currently + /// contains a link (the signature left by the CatPage id corruption bug) - use after + /// RegenerateTajikCatAndPoetHtmlText (or anything else) may have corrupted poem pages. + /// Check the Admin area's LongRunningJobs page for progress. /// /// [HttpPut] diff --git a/RMuseum/Services/IGanjoorService.cs b/RMuseum/Services/IGanjoorService.cs index 8e71d1ff..90b011e2 100644 --- a/RMuseum/Services/IGanjoorService.cs +++ b/RMuseum/Services/IGanjoorService.cs @@ -1592,10 +1592,9 @@ namespace RMuseum.Services RServiceResult RegenerateTajikCatAndPoetHtmlTextAsync(); /// - /// recovery job: regenerates TajikHtmlText for every Tajik poem from its TajikVerses, - /// overwriting whatever is currently stored. Safe to run on every poem regardless of - /// whether it was actually affected by anything - it recomputes each poem's correct - /// HTML from its real verse data every time. + /// recovery job: regenerates TajikHtmlText for Tajik poems whose stored HTML currently + /// contains a link (the signature left by the CatPage id corruption bug - correct poem + /// HTML never contains one), overwriting just those with correct verse markup. /// /// RServiceResult RestoreTajikPoemHtmlTextAsync(); diff --git a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-Tajik.cs b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-Tajik.cs index cf0c19c7..2ef58d00 100644 --- a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-Tajik.cs +++ b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-Tajik.cs @@ -335,10 +335,11 @@ namespace RMuseum.Services.Implementation /// overwriting whatever is currently stored. GanjoorTajikVerse rows carry no VersePosition /// of their own, so it's recovered by joining back to the original GanjoorVerses row with /// the same Id (the SQLite import sets GanjoorTajikVerse.Id = the original verse's Id). - /// Safe to run on every poem regardless of whether it was actually affected by the CatPage - /// id bug that RegenerateTajikCatAndPoetHtmlTextAsync had (see its cat-loop comment) - this - /// simply recomputes each poem's correct HTML from its real verse data every time, so poems - /// that were never touched come out unchanged. + /// Only processes poems whose stored TajikHtmlText currently contains a link - correct poem + /// HTML (from PrepareHtmlText) is pure verse markup (.b/.m1/.m2/.n/.l) and never contains an + /// <a href=...>, so a link inside it is the signature the CatPage id bug left behind + /// (it overwrote the affected poems with category-style link-list HTML). Scoping to that + /// signature instead of every poem cuts the run down to just the actually-corrupted ones. /// public RServiceResult RestoreTajikPoemHtmlTextAsync() { @@ -355,16 +356,20 @@ namespace RMuseum.Services.Implementation try { - var tajikPoems = await context.TajikPoems.AsNoTracking().ToListAsync(); - int done = 0; - foreach (var tajikPoem in tajikPoems) - { - await jobProgressServiceEF.UpdateJob(job.Id, done, $"poem: {tajikPoem.Id}"); + var corruptedPoemIds = await context.TajikPages + .Where(tp => tp.TajikHtmlText.Contains(" v.PoemId == poemId).ToListAsync(); if (tajikVerses.Count > 0) { - var originalVerses = await context.GanjoorVerses.AsNoTracking().Where(v => v.PoemId == tajikPoem.Id).ToListAsync(); + var originalVerses = await context.GanjoorVerses.AsNoTracking().Where(v => v.PoemId == poemId).ToListAsync(); var verses = tajikVerses .Select(tv => { @@ -381,7 +386,7 @@ namespace RMuseum.Services.Implementation // TajikPages.Id == the poem's own Id for poem pages (see // GanjoorService-TajikSQLiteImport.cs) - no GanjoorPages lookup needed here - var tajikPage = await context.TajikPages.Where(p => p.Id == tajikPoem.Id).SingleOrDefaultAsync(); + var tajikPage = await context.TajikPages.Where(p => p.Id == poemId).SingleOrDefaultAsync(); if (tajikPage != null) { tajikPage.TajikHtmlText = PrepareHtmlText(verses);