docs: #306 updating poem sections when updating page
This commit is contained in:
parent
ebc680b9c5
commit
7b51dbc15e
@ -57,6 +57,16 @@
|
||||
/// </summary>
|
||||
public string HtmlExcerpt { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// target poem id
|
||||
/// </summary>
|
||||
public int TargetPoemId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// target section index
|
||||
/// </summary>
|
||||
public int TargetSectionIndex { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// other poems
|
||||
/// </summary>
|
||||
|
||||
@ -5821,6 +5821,16 @@
|
||||
excerpt
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:RMuseum.Models.Ganjoor.GanjoorCachedRelatedSection.TargetPoemId">
|
||||
<summary>
|
||||
target poem id
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:RMuseum.Models.Ganjoor.GanjoorCachedRelatedSection.TargetSectionIndex">
|
||||
<summary>
|
||||
target section index
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:RMuseum.Models.Ganjoor.GanjoorCachedRelatedSection.PoetMorePoemsLikeThisCount">
|
||||
<summary>
|
||||
other poems
|
||||
|
||||
@ -127,7 +127,9 @@ namespace RMuseum.Services.Implementation
|
||||
FullTitle = relatedSection.Poem.FullTitle,
|
||||
FullUrl = fullUrl,
|
||||
PoetMorePoemsLikeThisCount = 0,
|
||||
HtmlExcerpt = GetPoemHtmlExcerpt(relatedSection.HtmlText)
|
||||
HtmlExcerpt = GetPoemHtmlExcerpt(relatedSection.HtmlText),
|
||||
TargetPoemId = relatedSection.PoemId,
|
||||
TargetSectionIndex = relatedSection.Index,
|
||||
};
|
||||
|
||||
GanjoorCachedRelatedSections.Add(newRelatedPoem);
|
||||
|
||||
@ -198,9 +198,6 @@ namespace RMuseum.Services.Implementation
|
||||
dbPoem.SourceUrlSlug = pageData.SourceUrlSlug;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
dbPoem.OldTag = pageData.OldTag;
|
||||
dbPoem.OldTagPageUrl = pageData.OldTagPageUrl;
|
||||
dbPoem.MixedModeOrder = pageData.MixedModeOrder;
|
||||
@ -219,12 +216,10 @@ namespace RMuseum.Services.Implementation
|
||||
dbPoem.PlainText = PreparePlainText(verses);
|
||||
|
||||
context.GanjoorPoems.Update(dbPoem);
|
||||
|
||||
|
||||
|
||||
var sections = await context.GanjoorPoemSections.Where(s => s.PoemId == dbPoem.Id && s.SectionType == PoemSectionType.WholePoem).OrderBy(s => s.VerseType).ToListAsync();
|
||||
GanjoorPoemSection mainSection = sections.Count > 0 ? sections[0] : null;
|
||||
|
||||
|
||||
var oldVerses = await context.GanjoorVerses.Where(v => v.PoemId == id).ToListAsync();
|
||||
|
||||
if (oldVerses.Count <= verses.Count)
|
||||
@ -265,18 +260,6 @@ namespace RMuseum.Services.Implementation
|
||||
await context.SaveChangesAsync();
|
||||
|
||||
await _FillPoemCoupletIndices(context, id);
|
||||
|
||||
var excerptsInRelatedCaches = await context.GanjoorCachedRelatedPoems.Where(p => p.FullUrl == dbPoem.FullUrl).ToListAsync();
|
||||
if (excerptsInRelatedCaches.Count > 0)
|
||||
{
|
||||
var newExcerpt = GetPoemHtmlExcerpt(dbPoem.HtmlText);
|
||||
foreach (var excerptsInRelatedCache in excerptsInRelatedCaches)
|
||||
{
|
||||
excerptsInRelatedCache.HtmlExcerpt = newExcerpt;
|
||||
}
|
||||
context.GanjoorCachedRelatedPoems.UpdateRange(excerptsInRelatedCaches);
|
||||
}
|
||||
|
||||
|
||||
if (mainSection != null)
|
||||
{
|
||||
@ -316,13 +299,13 @@ namespace RMuseum.Services.Implementation
|
||||
{
|
||||
if (oldMetreId != null && !string.IsNullOrEmpty(oldRhymeLetters))
|
||||
{
|
||||
await _UpdateRelatedPoems(inlineContext, (int)oldMetreId, oldRhymeLetters);
|
||||
await _UpdateRelatedSections(inlineContext, (int)oldMetreId, oldRhymeLetters);
|
||||
await inlineContext.SaveChangesAsync();
|
||||
}
|
||||
|
||||
if (mainSection.GanjoorMetreId != null && !string.IsNullOrEmpty(mainSection.RhymeLetters))
|
||||
{
|
||||
await _UpdateRelatedPoems(inlineContext, (int)mainSection.GanjoorMetreId, mainSection.RhymeLetters);
|
||||
await _UpdateRelatedSections(inlineContext, (int)mainSection.GanjoorMetreId, mainSection.RhymeLetters);
|
||||
await inlineContext.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
@ -415,13 +398,13 @@ namespace RMuseum.Services.Implementation
|
||||
{
|
||||
if (oldMetreId != null && !string.IsNullOrEmpty(oldRhymeLetters))
|
||||
{
|
||||
await _UpdateRelatedPoems(inlineContext, (int)oldMetreId, oldRhymeLetters);
|
||||
await _UpdateRelatedSections(inlineContext, (int)oldMetreId, oldRhymeLetters);
|
||||
await inlineContext.SaveChangesAsync();
|
||||
}
|
||||
|
||||
if (secondSection.GanjoorMetreId != null && !string.IsNullOrEmpty(secondSection.RhymeLetters))
|
||||
{
|
||||
await _UpdateRelatedPoems(inlineContext, (int)secondSection.GanjoorMetreId, secondSection.RhymeLetters);
|
||||
await _UpdateRelatedSections(inlineContext, (int)secondSection.GanjoorMetreId, secondSection.RhymeLetters);
|
||||
await inlineContext.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
@ -513,13 +496,13 @@ namespace RMuseum.Services.Implementation
|
||||
{
|
||||
if (oldMetreId != null && !string.IsNullOrEmpty(oldRhymeLetters))
|
||||
{
|
||||
await _UpdateRelatedPoems(inlineContext, (int)oldMetreId, oldRhymeLetters);
|
||||
await _UpdateRelatedSections(inlineContext, (int)oldMetreId, oldRhymeLetters);
|
||||
await inlineContext.SaveChangesAsync();
|
||||
}
|
||||
|
||||
if (thirdSection.GanjoorMetreId != null && !string.IsNullOrEmpty(thirdSection.RhymeLetters))
|
||||
{
|
||||
await _UpdateRelatedPoems(inlineContext, (int)thirdSection.GanjoorMetreId, thirdSection.RhymeLetters);
|
||||
await _UpdateRelatedSections(inlineContext, (int)thirdSection.GanjoorMetreId, thirdSection.RhymeLetters);
|
||||
await inlineContext.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
@ -559,7 +542,7 @@ namespace RMuseum.Services.Implementation
|
||||
{
|
||||
if (oldCoupletSection.GanjoorMetreId != null && !string.IsNullOrEmpty(oldCoupletSection.RhymeLetters))
|
||||
{
|
||||
await _UpdateRelatedPoems(inlineContext, (int)oldCoupletSection.GanjoorMetreId, oldCoupletSection.RhymeLetters);
|
||||
await _UpdateRelatedSections(inlineContext, (int)oldCoupletSection.GanjoorMetreId, oldCoupletSection.RhymeLetters);
|
||||
await inlineContext.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
@ -683,7 +666,7 @@ namespace RMuseum.Services.Implementation
|
||||
{
|
||||
if (newCoupletSection.GanjoorMetreId != null && !string.IsNullOrEmpty(newCoupletSection.RhymeLetters))
|
||||
{
|
||||
await _UpdateRelatedPoems(inlineContext, (int)newCoupletSection.GanjoorMetreId, newCoupletSection.RhymeLetters);
|
||||
await _UpdateRelatedSections(inlineContext, (int)newCoupletSection.GanjoorMetreId, newCoupletSection.RhymeLetters);
|
||||
await inlineContext.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
@ -696,6 +679,43 @@ namespace RMuseum.Services.Implementation
|
||||
|
||||
}
|
||||
|
||||
var mySections = await context.GanjoorPoemSections.Where(s => s.PoemId == id).ToListAsync();
|
||||
foreach (var section in mySections)
|
||||
{
|
||||
var verseSections = await context.GanjoorVerses.AsNoTracking().Where(v => v.PoemId == id
|
||||
&&
|
||||
(
|
||||
(section.VerseType == VersePoemSectionType.First && v.SectionIndex == section.Index)
|
||||
||
|
||||
(section.VerseType == VersePoemSectionType.Second && v.SecondSectionIndex == section.Index)
|
||||
||
|
||||
(section.VerseType == VersePoemSectionType.Third && v.ThirdSectionIndex == section.Index)
|
||||
||
|
||||
(section.VerseType == VersePoemSectionType.Forth && v.ForthSectionIndex == section.Index)
|
||||
)
|
||||
).OrderBy(v => v.VOrder).ToListAsync();
|
||||
section.HtmlText = PrepareHtmlText(verseSections);
|
||||
section.PlainText = PreparePlainText(verseSections);
|
||||
}
|
||||
context.UpdateRange(mySections);
|
||||
await context.SaveChangesAsync();
|
||||
|
||||
|
||||
|
||||
var excerptsInRelatedCaches = await context.GanjoorCachedRelatedSections.Where(p => p.TargetPoemId == id).ToListAsync();
|
||||
if (excerptsInRelatedCaches.Count > 0)
|
||||
{
|
||||
foreach (var excerptsInRelatedCache in excerptsInRelatedCaches)
|
||||
{
|
||||
var targetSection = mySections.Where(s => s.Index == excerptsInRelatedCache.TargetSectionIndex).SingleOrDefault();
|
||||
if(targetSection != null)
|
||||
{
|
||||
excerptsInRelatedCache.HtmlExcerpt = GetPoemHtmlExcerpt(targetSection.HtmlText);
|
||||
}
|
||||
}
|
||||
context.GanjoorCachedRelatedSections.UpdateRange(excerptsInRelatedCaches);
|
||||
}
|
||||
|
||||
}
|
||||
await context.SaveChangesAsync();
|
||||
CacheCleanForPageByUrl(dbPage.FullUrl);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user