mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
Fix (?) issues related with concurrency
This commit is contained in:
@@ -1,28 +1,19 @@
|
||||
using System.Threading.Tasks;
|
||||
using Kruzya.TelegramBot.Core.EF;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Kruzya.TelegramBot.Core.Data
|
||||
{
|
||||
public class CoreContext : DbContext
|
||||
public class CoreContext : AutoSaveDbContext
|
||||
{
|
||||
/// <summary>
|
||||
/// The all known users.
|
||||
/// </summary>
|
||||
public DbSet<BotUser> Users { get; set; }
|
||||
|
||||
public DbSet<BotUserValue> UserValues { get; set; }
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
SaveChanges();
|
||||
base.Dispose();
|
||||
}
|
||||
|
||||
public override ValueTask DisposeAsync()
|
||||
{
|
||||
SaveChanges();
|
||||
return base.DisposeAsync();
|
||||
}
|
||||
/// <summary>
|
||||
/// The all knows user options and values.
|
||||
/// </summary>
|
||||
public DbSet<BotUserValue> UserValues { get; set; }
|
||||
|
||||
public CoreContext(DbContextOptions<CoreContext> ctx) : base(ctx)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
||||
|
||||
namespace Kruzya.TelegramBot.Core.EF;
|
||||
|
||||
public abstract partial class AutoSaveDbContext
|
||||
{
|
||||
public override EntityEntry Add(object entity)
|
||||
{
|
||||
var entry = base.Add(entity);
|
||||
SaveChanges();
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
public override EntityEntry<TEntity> Add<TEntity>(TEntity entity)
|
||||
{
|
||||
var entry = base.Add(entity);
|
||||
SaveChanges();
|
||||
|
||||
return entry;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
||||
|
||||
namespace Kruzya.TelegramBot.Core.EF;
|
||||
|
||||
public abstract partial class AutoSaveDbContext
|
||||
{
|
||||
public override EntityEntry Remove(object entity)
|
||||
{
|
||||
var entry = base.Remove(entity);
|
||||
SaveChanges();
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
public override EntityEntry<TEntity> Remove<TEntity>(TEntity entity)
|
||||
{
|
||||
var entry = base.Remove(entity);
|
||||
SaveChanges();
|
||||
|
||||
return entry;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
||||
|
||||
namespace Kruzya.TelegramBot.Core.EF;
|
||||
|
||||
public abstract partial class AutoSaveDbContext
|
||||
{
|
||||
public override EntityEntry Update(object entity)
|
||||
{
|
||||
var entry = base.Update(entity);
|
||||
SaveChanges();
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
public override EntityEntry<TEntity> Update<TEntity>(TEntity entity)
|
||||
{
|
||||
var entry = base.Update(entity);
|
||||
SaveChanges();
|
||||
|
||||
return entry;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Kruzya.TelegramBot.Core.EF;
|
||||
|
||||
/// <summary>
|
||||
/// EF database context with autosaving feature.
|
||||
/// </summary>
|
||||
public abstract partial class AutoSaveDbContext : DbContext
|
||||
{
|
||||
protected AutoSaveDbContext(DbContextOptions options) : base(options)
|
||||
{}
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Kruzya.TelegramBot.Core.EF;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Kruzya.TelegramBot.RichSiteSummary.Data
|
||||
{
|
||||
public class RichSiteSummaryContext : DbContext
|
||||
public class RichSiteSummaryContext : AutoSaveDbContext
|
||||
{
|
||||
/// <summary>
|
||||
/// Repository with all feeds in database.
|
||||
|
||||
Reference in New Issue
Block a user