A
A
Anton2019-07-19 12:16:02
ASP.NET
Anton, 2019-07-19 12:16:02

How to speed up a request in a controller?

There is such a controller

[HttpGet("StockOnHand")]
        public IActionResult GetStockOnHand()
        {
            var storeList = context.Stores
           .Where(x => x.GeomarketName.StartsWith("RCA"))
           .Where(x => x.SubSubSegmentName.StartsWith("WS"))
           .Where(x => x.SegmentId == "WSV");

            var tempList = storeList.Select(x => x.StoreId);

            var StockList = context.StockOnHands
            .Where(x => x.PartType.Contains("Inventory"))
            .Where(x => tempList.Contains(x.StoreId))
            .ToList();

            var stockItems = StockList
              .Select(x =>
              {
                 Store store = storeList
                  .Where(s => s.StoreId == x.StoreId)
                  .FirstOrDefault();

                  return new StockOnHandList()
                  {
                      StockId = x.StockId,
                      Store = new StoreListDto(store),
                      StoreId = x.StoreId,
                      PartNumber = x.PartNumber,
                      PartDescription = x.PartDescription,
                      LastPurchasePrice = x.LastPurchasePrice,
                      StockOnHandQuantity = x.StockOnHandQuantity,
                      U = x.U,
                      LotNumber = x.LotNumber,
                      ExpirationDate = x.ExpirationDate,
                      ReportUpdateDate = x.ReportUpdateDate,
                  };
              })
              .ToList();

            return Json(stockItems);
        }

This is what makes the controller very slow.
Store store = storeList
.Where(s => s.StoreId == x.StoreId)
.FirstOrDefault();
I have such a structure and there must be a store field.
5d31898b199ab875726437.png
But how to speed up the request so that I don't have to wait 30 seconds?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Planet_93, 2019-07-19
@Planet_93

Try without Where

Store store = storeList
.FirstOrDefault(s => s.StoreId == x.StoreId);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question