Update InventoryController.cs
This commit is contained in:
parent
d63cb15df1
commit
1180e404aa
@ -16,6 +16,8 @@ public class InventoryController : Controller {
|
|||||||
private readonly DatabaseCacheService _cache;
|
private readonly DatabaseCacheService _cache;
|
||||||
private static object _lock = new object();
|
private static object _lock = new object();
|
||||||
|
|
||||||
|
private const int AMOUNT_SCROLL = 5;
|
||||||
|
|
||||||
public InventoryController(ILogger<InventoryController> logger, InventoryContext context, DatabaseCacheService cache) {
|
public InventoryController(ILogger<InventoryController> logger, InventoryContext context, DatabaseCacheService cache) {
|
||||||
_context = context;
|
_context = context;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
@ -25,7 +27,6 @@ public class InventoryController : Controller {
|
|||||||
[EnableCors("_myAllowSpecificOrigins")]
|
[EnableCors("_myAllowSpecificOrigins")]
|
||||||
[HttpGet(Name = "Inventory")] // Pour faire des calls async par paquet de AMOUNT (5) (pour du loading en scrollant)
|
[HttpGet(Name = "Inventory")] // Pour faire des calls async par paquet de AMOUNT (5) (pour du loading en scrollant)
|
||||||
public IEnumerable<Product> Get(int? lastId, string? order, string? filterPrice, string? filterState, bool? all) {
|
public IEnumerable<Product> Get(int? lastId, string? order, string? filterPrice, string? filterState, bool? all) {
|
||||||
const int AMOUNT = 5;
|
|
||||||
bool islock = false;
|
bool islock = false;
|
||||||
IQueryable<Product> ret;
|
IQueryable<Product> ret;
|
||||||
|
|
||||||
@ -106,7 +107,7 @@ public class InventoryController : Controller {
|
|||||||
}
|
}
|
||||||
else prods = ret.ToList();
|
else prods = ret.ToList();
|
||||||
foreach (Product prod in prods) {
|
foreach (Product prod in prods) {
|
||||||
if (yup && add < AMOUNT) {
|
if (yup && add < AMOUNT_SCROLL) {
|
||||||
lst.Add(prod);
|
lst.Add(prod);
|
||||||
add++;
|
add++;
|
||||||
}
|
}
|
||||||
@ -121,9 +122,9 @@ public class InventoryController : Controller {
|
|||||||
else lst = ret.ToList();
|
else lst = ret.ToList();
|
||||||
} else if (islock)
|
} else if (islock)
|
||||||
lock (_lock) {
|
lock (_lock) {
|
||||||
lst = ret.Take(AMOUNT).ToList();
|
lst = ret.Take(AMOUNT_SCROLL).ToList();
|
||||||
}
|
}
|
||||||
else lst = ret.Take(AMOUNT).ToList();
|
else lst = ret.Take(AMOUNT_SCROLL).ToList();
|
||||||
|
|
||||||
return lst;
|
return lst;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
Loading…
Reference in New Issue
Block a user