docs: regenerate poem full titles to fix an old bug
This commit is contained in:
parent
4bef987736
commit
276baa932f
@ -2299,6 +2299,24 @@ namespace RMuseum.Controllers
|
||||
return BadRequest(res.ExceptionString);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// regenerate poem full titles to fix an old bug
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Route("maintenance/regenfulltitles")]
|
||||
[Authorize(Policy = RMuseumSecurableItem.GanjoorEntityShortName + ":" + RMuseumSecurableItem.ImportOperationShortName)]
|
||||
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(bool))]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
|
||||
public IActionResult RegeneratePoemsFullTitles()
|
||||
{
|
||||
RServiceResult<bool> res =
|
||||
_ganjoorService.RegeneratePoemsFullTitles();
|
||||
if (res.Result)
|
||||
return Ok();
|
||||
return BadRequest(res.ExceptionString);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// separate verses in poem.PlainText with Environment.NewLine instead of SPACE
|
||||
/// </summary>
|
||||
|
||||
@ -561,6 +561,12 @@ namespace RMuseum.Services
|
||||
/// <returns></returns>
|
||||
RServiceResult<bool> StartFillingPoemsCoupletIndices();
|
||||
|
||||
/// <summary>
|
||||
/// regenerate poem full titles to fix an old bug
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
RServiceResult<bool> RegeneratePoemsFullTitles();
|
||||
|
||||
/// <summary>
|
||||
/// separate verses in poem.PlainText with Environment.NewLine instead of SPACE
|
||||
/// </summary>
|
||||
|
||||
@ -651,5 +651,55 @@ namespace RMuseum.Services.Implementation
|
||||
|
||||
return new RServiceResult<bool>(true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// regenerate poem full titles to fix an old bug
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public RServiceResult<bool> RegeneratePoemsFullTitles()
|
||||
{
|
||||
_backgroundTaskQueue.QueueBackgroundWorkItem
|
||||
(
|
||||
async token =>
|
||||
{
|
||||
using (RMuseumDbContext context = new RMuseumDbContext(new DbContextOptions<RMuseumDbContext>())) //this is long running job, so _context might be already been freed/collected by GC
|
||||
{
|
||||
LongRunningJobProgressServiceEF jobProgressServiceEF = new LongRunningJobProgressServiceEF(context);
|
||||
var job = (await jobProgressServiceEF.NewJob("RegenratePoemsFullTitles", "Query data")).Result;
|
||||
int percent = 0;
|
||||
try
|
||||
{
|
||||
var poemIds = await context.GanjoorPoems.AsNoTracking().Select(p => p.Id).ToListAsync();
|
||||
|
||||
for (int i = 0; i < poemIds.Count; i++)
|
||||
{
|
||||
if (i * 100 / poemIds.Count > percent)
|
||||
{
|
||||
percent++;
|
||||
await jobProgressServiceEF.UpdateJob(job.Id, percent);
|
||||
}
|
||||
|
||||
var poem = await context.GanjoorPoems.Where(p => p.Id == poemIds[i]).SingleOrDefaultAsync();
|
||||
var catPage = await context.GanjoorPages.AsNoTracking().Where(p => p.GanjoorPageType == GanjoorPageType.CatPage && p.CatId == poem.CatId).SingleOrDefaultAsync();
|
||||
poem.FullTitle = $"{catPage.FullTitle} » {poem.Title}";
|
||||
context.Update(poem);
|
||||
var page = await context.GanjoorPages.Where(p => p.Id == poem.Id).SingleOrDefaultAsync();
|
||||
page.FullTitle = poem.FullTitle;
|
||||
context.Update(page);
|
||||
}
|
||||
|
||||
await jobProgressServiceEF.UpdateJob(job.Id, 100, "", true);
|
||||
}
|
||||
catch (Exception exp)
|
||||
{
|
||||
await jobProgressServiceEF.UpdateJob(job.Id, percent, "", false, exp.ToString());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
return new RServiceResult<bool>(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user