docs: #322 preventing parallel same data update-related-sections (model+code/ no db migrations)
This commit is contained in:
parent
583b7c86ed
commit
0f49151d67
@ -487,5 +487,11 @@ namespace RMuseum.DbContext
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public DbSet<GanjoorPoemSectionCorrection> GanjoorPoemSectionCorrections { get; set; }
|
public DbSet<GanjoorPoemSectionCorrection> GanjoorPoemSectionCorrections { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Updating related sections logs
|
||||||
|
/// </summary>
|
||||||
|
public DbSet<UpdatingRelSectsLog> UpdatingRelSectsLogs{ get; set; }
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
30
RMuseum/Models/Ganjoor/UpdatingRelSectsLog.cs
Normal file
30
RMuseum/Models/Ganjoor/UpdatingRelSectsLog.cs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace RMuseum.Models.Ganjoor
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Updating related sections logs
|
||||||
|
/// </summary>
|
||||||
|
public class UpdatingRelSectsLog
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// id
|
||||||
|
/// </summary>
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// meter id
|
||||||
|
/// </summary>
|
||||||
|
public int MeterId { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// rhyme letters
|
||||||
|
/// </summary>
|
||||||
|
public string RhymeLettes { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// date/time
|
||||||
|
/// </summary>
|
||||||
|
public DateTime DateTime { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -2978,6 +2978,11 @@
|
|||||||
section correctons
|
section correctons
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="P:RMuseum.DbContext.RMuseumDbContext.UpdatingRelSectsLogs">
|
||||||
|
<summary>
|
||||||
|
Updating related sections logs
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
<member name="T:RMuseum.Models.Accounting.DonationExpenditure">
|
<member name="T:RMuseum.Models.Accounting.DonationExpenditure">
|
||||||
<summary>
|
<summary>
|
||||||
donation expenditures
|
donation expenditures
|
||||||
@ -8096,6 +8101,31 @@
|
|||||||
couplets (virtual) for Masnavi
|
couplets (virtual) for Masnavi
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="T:RMuseum.Models.Ganjoor.UpdatingRelSectsLog">
|
||||||
|
<summary>
|
||||||
|
Updating related sections logs
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:RMuseum.Models.Ganjoor.UpdatingRelSectsLog.Id">
|
||||||
|
<summary>
|
||||||
|
id
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:RMuseum.Models.Ganjoor.UpdatingRelSectsLog.MeterId">
|
||||||
|
<summary>
|
||||||
|
meter id
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:RMuseum.Models.Ganjoor.UpdatingRelSectsLog.RhymeLettes">
|
||||||
|
<summary>
|
||||||
|
rhyme letters
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:RMuseum.Models.Ganjoor.UpdatingRelSectsLog.DateTime">
|
||||||
|
<summary>
|
||||||
|
date/time
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
<member name="T:RMuseum.Models.Ganjoor.VersePoemSectionType">
|
<member name="T:RMuseum.Models.Ganjoor.VersePoemSectionType">
|
||||||
<summary>
|
<summary>
|
||||||
how GanjoorPoemSection is linked to GanjoorVerse
|
how GanjoorPoemSection is linked to GanjoorVerse
|
||||||
|
|||||||
@ -53,6 +53,19 @@ namespace RMuseum.Services.Implementation
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
if (await context.UpdatingRelSectsLogs.AsNoTracking()
|
||||||
|
.Where(l => l.MeterId == metreId && l.RhymeLettes == rhyme && l.DateTime > DateTime.Now.AddMinutes(-10)).AnyAsync())
|
||||||
|
return new RServiceResult<bool>(true);//prevent parallel updates for same data
|
||||||
|
|
||||||
|
var log = new UpdatingRelSectsLog()
|
||||||
|
{
|
||||||
|
MeterId = metreId,
|
||||||
|
RhymeLettes = rhyme,
|
||||||
|
DateTime = DateTime.Now
|
||||||
|
};
|
||||||
|
context.Add(log);
|
||||||
|
await context.SaveChangesAsync();
|
||||||
|
|
||||||
var sections = await context.GanjoorPoemSections.AsNoTracking()
|
var sections = await context.GanjoorPoemSections.AsNoTracking()
|
||||||
.Where(section => section.GanjoorMetreId == metreId && section.RhymeLetters == rhyme && section.SectionType == PoemSectionType.WholePoem)
|
.Where(section => section.GanjoorMetreId == metreId && section.RhymeLetters == rhyme && section.SectionType == PoemSectionType.WholePoem)
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
@ -61,11 +74,18 @@ namespace RMuseum.Services.Implementation
|
|||||||
{
|
{
|
||||||
await _UpdateSectionRelatedSectionsInfoNoSaveChanges(context, section, poetsImagesUrls, true);
|
await _UpdateSectionRelatedSectionsInfoNoSaveChanges(context, section, poetsImagesUrls, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var logs = await context.UpdatingRelSectsLogs
|
||||||
|
.Where(l => l.MeterId == metreId && l.RhymeLettes == rhyme).ToListAsync();
|
||||||
|
context.RemoveRange(logs);
|
||||||
await context.SaveChangesAsync();
|
await context.SaveChangesAsync();
|
||||||
return new RServiceResult<bool>(true);
|
return new RServiceResult<bool>(true);
|
||||||
}
|
}
|
||||||
catch (Exception exp)
|
catch (Exception exp)
|
||||||
{
|
{
|
||||||
|
var logs = await context.UpdatingRelSectsLogs
|
||||||
|
.Where(l => l.MeterId == metreId && l.RhymeLettes == rhyme).ToListAsync();
|
||||||
|
context.RemoveRange(logs);
|
||||||
return new RServiceResult<bool>(false, exp.ToString());
|
return new RServiceResult<bool>(false, exp.ToString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user