diff --git a/RMuseum/Controllers/GanjoorController.cs b/RMuseum/Controllers/GanjoorController.cs
index e2803999..7e648972 100644
--- a/RMuseum/Controllers/GanjoorController.cs
+++ b/RMuseum/Controllers/GanjoorController.cs
@@ -2754,13 +2754,13 @@ namespace RMuseum.Controllers
/// sectionizing poems
///
///
- [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();
diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml
index 7345b022..05da81b2 100644
--- a/RMuseum/RMuseum.xml
+++ b/RMuseum/RMuseum.xml
@@ -1690,7 +1690,7 @@
-
+
sectionizing poems
@@ -11992,7 +11992,7 @@
-
+
sectionizing poems
@@ -13598,7 +13598,7 @@
-
+
sectionizing poems
diff --git a/RMuseum/Services/IGanjoorService.cs b/RMuseum/Services/IGanjoorService.cs
index 3de94015..b3bed160 100644
--- a/RMuseum/Services/IGanjoorService.cs
+++ b/RMuseum/Services/IGanjoorService.cs
@@ -917,6 +917,6 @@ namespace RMuseum.Services
/// sectionizing poems
///
///
- RServiceResult StartSectionizingPoems();
+ RServiceResult StartFillingPoemSectionsCoupletIndex();
}
}
diff --git a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-PoemSections.cs b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-PoemSections.cs
index 95b707b1..92103ce9 100644
--- a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-PoemSections.cs
+++ b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-PoemSections.cs
@@ -21,7 +21,7 @@ namespace RMuseum.Services.Implementation
/// sectionizing poems
///
///
- public RServiceResult StartSectionizingPoems()
+ public RServiceResult StartFillingPoemSectionsCoupletIndex()
{
try
{
@@ -33,20 +33,36 @@ namespace RMuseum.Services.Implementation
using (RMuseumDbContext context = new RMuseumDbContext(new DbContextOptions())) //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)
diff --git a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-RelatedSections.cs b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-RelatedSections.cs
index 83643b22..3e4f886f 100644
--- a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-RelatedSections.cs
+++ b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-RelatedSections.cs
@@ -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()
diff --git a/RMuseum/Services/Implementation/GanjoorService.cs b/RMuseum/Services/Implementation/GanjoorService.cs
index 28a34819..72b5abcd 100644
--- a/RMuseum/Services/Implementation/GanjoorService.cs
+++ b/RMuseum/Services/Implementation/GanjoorService.cs
@@ -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,