Renvoit du rôle au frontend avec Get Login (UPDATE-DATABASE)
This commit is contained in:
@@ -19,7 +19,7 @@ public class DatabaseCacheService {
|
||||
#endregion
|
||||
|
||||
#region Fields
|
||||
private Product[] _cache = new Product[1];
|
||||
private ProductModel[] _cache = new ProductModel[1];
|
||||
private Dictionary<uint, uint> _hits = new();
|
||||
private bool _ok = false, _needUpd = true;
|
||||
private PeriodicTimer _timer = new PeriodicTimer(TimeSpan.FromSeconds(10));
|
||||
@@ -51,7 +51,7 @@ public class DatabaseCacheService {
|
||||
}
|
||||
private bool UpdateCache() {
|
||||
try {
|
||||
Product[] prods;
|
||||
ProductModel[] prods;
|
||||
using (var scope = _contextFactory.CreateScope()) {
|
||||
var db = scope.ServiceProvider.GetRequiredService<InventoryContext>();
|
||||
prods = db.Products.ToArray();
|
||||
@@ -75,7 +75,7 @@ public class DatabaseCacheService {
|
||||
List<uint> ids = hits.Keys.ToList();
|
||||
using (var scope = _contextFactory.CreateScope()) {
|
||||
var db = scope.ServiceProvider.GetRequiredService<InventoryContext>();
|
||||
List<Product> lst = db.Products.Where(x => ids.Contains((uint)x.Id)).ToList();
|
||||
List<ProductModel> lst = db.Products.Where(x => ids.Contains((uint)x.Id)).ToList();
|
||||
foreach (var x in hits)
|
||||
lst.First(x => x.Id == x.Id).Hits += x.Value;
|
||||
db.UpdateRange(lst);
|
||||
@@ -101,13 +101,13 @@ public class DatabaseCacheService {
|
||||
}
|
||||
}
|
||||
|
||||
public Product[]? GetCacheCopy() {
|
||||
public ProductModel[]? GetCacheCopy() {
|
||||
if (!_ok)
|
||||
return null;
|
||||
Product[] copy;
|
||||
ProductModel[] copy;
|
||||
try {
|
||||
lock (_cache) {
|
||||
copy = new Product[_cache.Length];
|
||||
copy = new ProductModel[_cache.Length];
|
||||
_cache.CopyTo(copy, 0);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@@ -116,7 +116,7 @@ public class DatabaseCacheService {
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
public IQueryable<Product> queryCache() {
|
||||
public IQueryable<ProductModel> queryCache() {
|
||||
if (!_ok)
|
||||
return null;
|
||||
try {
|
||||
|
Reference in New Issue
Block a user