parent
1efb4f38fb
commit
185d55c1e1
@ -2616,6 +2616,25 @@ namespace RMuseum.Controllers
|
||||
return BadRequest(res.ExceptionString);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// fill section couplet counts
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
|
||||
[HttpPost]
|
||||
[Route("fillsectioncoupletcounts")]
|
||||
[Authorize(Policy = RMuseumSecurableItem.GanjoorEntityShortName + ":" + RMuseumSecurableItem.ImportOperationShortName)]
|
||||
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(bool))]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
|
||||
public IActionResult StartFillingSectionCoupletCounts()
|
||||
{
|
||||
RServiceResult<bool> res =
|
||||
_ganjoorService.StartFillingSectionCoupletCounts();
|
||||
if (res.Result)
|
||||
return Ok();
|
||||
return BadRequest(res.ExceptionString);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// regenerate poem full titles to fix an old bug
|
||||
/// </summary>
|
||||
|
||||
@ -1746,6 +1746,12 @@
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.GanjoorController.StartFillingSectionCoupletCounts">
|
||||
<summary>
|
||||
fill section couplet counts
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.GanjoorController.RegeneratePoemsFullTitles">
|
||||
<summary>
|
||||
regenerate poem full titles to fix an old bug
|
||||
@ -16298,6 +16304,12 @@
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.IGanjoorService.StartFillingSectionCoupletCounts">
|
||||
<summary>
|
||||
fill section couplets count
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.IGanjoorService.RegeneratePoemsFullTitles">
|
||||
<summary>
|
||||
regenerate poem full titles to fix an old bug
|
||||
@ -19026,6 +19038,12 @@
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.GanjoorService.StartFillingSectionCoupletCounts">
|
||||
<summary>
|
||||
fill section couplets count
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.GanjoorService.RegeneratePoemsFullTitles">
|
||||
<summary>
|
||||
regenerate poem full titles to fix an old bug
|
||||
|
||||
@ -628,6 +628,13 @@ namespace RMuseum.Services
|
||||
/// <returns></returns>
|
||||
RServiceResult<bool> StartFillingPoemsCoupletIndices();
|
||||
|
||||
/// <summary>
|
||||
/// fill section couplets count
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
RServiceResult<bool> StartFillingSectionCoupletCounts();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// regenerate poem full titles to fix an old bug
|
||||
/// </summary>
|
||||
|
||||
@ -692,6 +692,73 @@ namespace RMuseum.Services.Implementation
|
||||
return new RServiceResult<bool>(true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// fill section couplets count
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public RServiceResult<bool> StartFillingSectionCoupletCounts()
|
||||
{
|
||||
_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("FillingSectionCoupletCounts", "Query data")).Result;
|
||||
|
||||
try
|
||||
{
|
||||
var sectionIds = await context.GanjoorPoemSections.AsNoTracking().Select(p => p.Id).ToListAsync();
|
||||
|
||||
|
||||
int percent = 0;
|
||||
for (int i = 0; i < sectionIds.Count; i++)
|
||||
{
|
||||
if (i * 100 / sectionIds.Count > percent)
|
||||
{
|
||||
percent++;
|
||||
await jobProgressServiceEF.UpdateJob(job.Id, percent);
|
||||
}
|
||||
|
||||
await _FillSectionCoupletCountsAsync(context, sectionIds[i]);
|
||||
}
|
||||
|
||||
await jobProgressServiceEF.UpdateJob(job.Id, 100, "", true);
|
||||
}
|
||||
catch (Exception exp)
|
||||
{
|
||||
await jobProgressServiceEF.UpdateJob(job.Id, 100, "", false, exp.ToString());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
return new RServiceResult<bool>(true);
|
||||
}
|
||||
|
||||
private async Task _FillSectionCoupletCountsAsync(RMuseumDbContext context, int sectionId)
|
||||
{
|
||||
var section = await context.GanjoorPoemSections.Where(s => s.Id == sectionId).SingleAsync();
|
||||
|
||||
section.CoupletsCount = await context.GanjoorVerses.Where(
|
||||
v => v.PoemId == section.PoemId
|
||||
&&
|
||||
(
|
||||
v.SectionIndex1 == section.Index ||
|
||||
v.SectionIndex2 == section.Index ||
|
||||
v.SectionIndex3 == section.Index ||
|
||||
v.SectionIndex4 == section.Index
|
||||
)
|
||||
&&
|
||||
(v.VersePosition == VersePosition.Left || v.VersePosition == VersePosition.CenteredVerse1)
|
||||
).CountAsync();
|
||||
|
||||
context.Update(section);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// regenerate poem full titles to fix an old bug
|
||||
/// </summary>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user