docs: #307 improvizing similars api

This commit is contained in:
Hamid Reza Mohammadi 2022-04-25 20:10:10 +04:30
parent 1669726fff
commit 39f819135b
6 changed files with 33 additions and 35 deletions

View File

@ -2754,13 +2754,13 @@ namespace RMuseum.Controllers
/// sectionizing poems
/// </summary>
/// <returns></returns>
[HttpPost("sections/onetime/startextracting")]
[HttpPost("sections/onetime/fillcouplets")]
[Authorize(Policy = RMuseumSecurableItem.GanjoorEntityShortName + ":" + SecurableItem.ModifyOperationShortName)]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
public IActionResult StartSectionizingPoems()
public IActionResult StartFillingPoemSectionsCoupletIndex()
{
var res = _ganjoorService.StartSectionizingPoems();
var res = _ganjoorService.StartFillingPoemSectionsCoupletIndex();
if (!string.IsNullOrEmpty(res.ExceptionString))
return BadRequest(res.ExceptionString);
return Ok();

View File

@ -1690,7 +1690,7 @@
<param name="destCatId"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Controllers.GanjoorController.StartSectionizingPoems">
<member name="M:RMuseum.Controllers.GanjoorController.StartFillingPoemSectionsCoupletIndex">
<summary>
sectionizing poems
</summary>
@ -11992,7 +11992,7 @@
<param name="destCatId"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Services.IGanjoorService.StartSectionizingPoems">
<member name="M:RMuseum.Services.IGanjoorService.StartFillingPoemSectionsCoupletIndex">
<summary>
sectionizing poems
</summary>
@ -13598,7 +13598,7 @@
<param name="rejectionCause"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Services.Implementation.GanjoorService.StartSectionizingPoems">
<member name="M:RMuseum.Services.Implementation.GanjoorService.StartFillingPoemSectionsCoupletIndex">
<summary>
sectionizing poems
</summary>

View File

@ -917,6 +917,6 @@ namespace RMuseum.Services
/// sectionizing poems
/// </summary>
/// <returns></returns>
RServiceResult<bool> StartSectionizingPoems();
RServiceResult<bool> StartFillingPoemSectionsCoupletIndex();
}
}

View File

@ -21,7 +21,7 @@ namespace RMuseum.Services.Implementation
/// sectionizing poems
/// </summary>
/// <returns></returns>
public RServiceResult<bool> StartSectionizingPoems()
public RServiceResult<bool> StartFillingPoemSectionsCoupletIndex()
{
try
{
@ -33,20 +33,36 @@ namespace RMuseum.Services.Implementation
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("SectionizingPoems", "Query data")).Result;
var job = (await jobProgressServiceEF.NewJob("StartFillingPoemSectionsCoupletIndex", "Query data")).Result;
int progress = 0;
try
{
var poems = await context.GanjoorPoems.Include(p => p.Cat).AsNoTracking().ToListAsync();
int count = poems.Count;
var sections = await context.GanjoorPoemSections.OrderBy(s => s.SectionType).ToListAsync();
int count = sections.Count;
for (int i = 0; i < count; i++)
{
var poem = poems[i];
var section = sections[i];
if(false == await _SectionizePoem(context, poem, jobProgressServiceEF, job))
var firstSectionVerse = await context.GanjoorVerses.AsNoTracking()
.Where
(v =>
v.PoemId == section.PoemId
&&
(
(section.VerseType == VersePoemSectionType.Second && v.SectionIndex2 == section.Index)
||
(section.VerseType == VersePoemSectionType.Third && v.SectionIndex3 == section.Index)
||
(section.VerseType == VersePoemSectionType.Forth && v.SectionIndex4 == section.Index)
)
)
.OrderBy(v => v.VOrder)
.FirstOrDefaultAsync();
if (firstSectionVerse != null && firstSectionVerse.CoupletIndex != null)
{
return;
section.CachedFirstCoupletIndex = (int)firstSectionVerse.CoupletIndex;
context.Update(section);
}
if ((i * 100 / count) > progress)

View File

@ -99,27 +99,9 @@ namespace RMuseum.Services.Implementation
r++;
var fullUrl = relatedSection.Poem.FullUrl;
if(relatedSection.SectionType == PoemSectionType.Couplet)
if(relatedSection.CachedFirstCoupletIndex > 0)
{
var firstSectionVerse = await context.GanjoorVerses.AsNoTracking()
.Where
(v =>
v.PoemId == relatedSection.PoemId
&&
(
(relatedSection.VerseType == VersePoemSectionType.Second && v.SectionIndex2 == relatedSection.Index)
||
(relatedSection.VerseType == VersePoemSectionType.Third && v.SectionIndex3 == relatedSection.Index)
||
(relatedSection.VerseType == VersePoemSectionType.Forth && v.SectionIndex4 == relatedSection.Index)
)
)
.OrderBy(v => v.VOrder)
.FirstOrDefaultAsync();
if(firstSectionVerse != null)
{
fullUrl += $"#bn{firstSectionVerse.CoupletIndex + 1}";
}
fullUrl += $"#bn{relatedSection.CachedFirstCoupletIndex + 1}";
}
GanjoorCachedRelatedSection newRelatedPoem = new GanjoorCachedRelatedSection()

View File

@ -2161,7 +2161,7 @@ namespace RMuseum.Services.Implementation
Id = section.Poem.Id,
Title = section.Poem.Title,
FullTitle = section.Poem.FullTitle,
FullUrl = section.Poem.FullUrl,
FullUrl = section.CachedFirstCoupletIndex == 0 ? section.Poem.FullUrl : section.Poem.FullUrl + "#bn" + (section.CachedFirstCoupletIndex + 1).ToString(),
UrlSlug = section.Poem.UrlSlug,
HtmlText = section.HtmlText,
PlainText = section.PlainText,