Hi Frederic,
...model.NumberOfOrders = _orderService.SearchOrders...
...model.NumberOfCustomers = _customerService.GetAllCustomers...
These two methods cannot be the case because they do not load all records into memory. They load only one record and then use "TotalCount" property. Please see "pageSize" property (we pass 1)
LOL - Did you just say this?
These two methods cannot be the case because they do not load all records into memory. They load only one record and then use "TotalCount" property. Please see "pageSize" property (we pass 1)
Did you seriously just say that?
I debugged your search order query and wrote it the end of this message for reference.
It loads everything into memory. Of course it does - there is no magic - what the heck are you thinking?
Your page size property is only about how many record you want to return to the client. It has nothing to do with how many record are returned from the DB.
The query is then put it into a paged list - but the paged list is a simple glorified IList that you use to page the data before sending it to the client. It does nothing to reduce how much data is retrieved from the DB.
As soon as your pagedlist called source.count() - everything is loaded (Basic IEnumerable behavior)
Andrei - this is your code - I don't want to tell you how it works.
Jesus - your response is freaking me out.
If you guys do not understand this - then how can we hope that you will fix it?
I will make one more attempt at explaining the issue again -
All record are loaded in the DB.
All 125,000 orders and all 75,000 customers
Then you do a count on it! And all you need is the result of the count - so it is a mega waist of resources as you can imagine.
I re enabled your query to further debug it and show you sql statement below.
Guess what - my memory consumption is back 3,7 Giga byte right now :)
Oh - and the query takes a very long time to return.
When I apply the code chnages I did yesterday. It loads only 1 integer from the DB and the code returns very fast of course.
I suggested you guys test your code before becuase I think it will help the team understand much better how the code actually works.
I just spent 2 more hours to show you that what you just said in your last message was wrong - since we are both very busy please lets stop arguing.
If you do not want to believe what I am showing you. Then I simply cannot help you.
Here is query your code runs - it returns everything from that query and later on your code will do a count on the IEnumerable:
SELECT [Extent1].[Id] AS [Id],
[Extent1].[OrderGuid] AS [OrderGuid],
[Extent1].[StoreId] AS [StoreId],
[Extent1].[CustomerId] AS [CustomerId],
[Extent1].[BillingAddressId] AS [BillingAddressId],
[Extent1].[ShippingAddressId] AS [ShippingAddressId],
[Extent1].[PickupAddressId] AS [PickupAddressId],
[Extent1].[PickUpInStore] AS [PickUpInStore],
[Extent1].[OrderStatusId] AS [OrderStatusId],
[Extent1].[ShippingStatusId] AS [ShippingStatusId],
[Extent1].[PaymentStatusId] AS [PaymentStatusId],
[Extent1].[PaymentMethodSystemName] AS [PaymentMethodSystemName],
[Extent1].[CustomerCurrencyCode] AS [CustomerCurrencyCode],
[Extent1].[CurrencyRate] AS [CurrencyRate],
[Extent1].[CustomerTaxDisplayTypeId] AS [CustomerTaxDisplayTypeId],
[Extent1].[VatNumber] AS [VatNumber],
[Extent1].[OrderSubtotalInclTax] AS [OrderSubtotalInclTax],
[Extent1].[OrderSubtotalExclTax] AS [OrderSubtotalExclTax],
[Extent1].[OrderSubTotalDiscountInclTax] AS [OrderSubTotalDiscountInclTax],
[Extent1].[OrderSubTotalDiscountExclTax] AS [OrderSubTotalDiscountExclTax],
[Extent1].[OrderShippingInclTax] AS [OrderShippingInclTax],
[Extent1].[OrderShippingExclTax] AS [OrderShippingExclTax],
[Extent1].[PaymentMethodAdditionalFeeInclTax] AS [PaymentMethodAdditionalFeeInclTax],
[Extent1].[PaymentMethodAdditionalFeeExclTax] AS [PaymentMethodAdditionalFeeExclTax],
[Extent1].[TaxRates] AS [TaxRates],
[Extent1].[OrderTax] AS [OrderTax],
[Extent1].[OrderDiscount] AS [OrderDiscount],
[Extent1].[OrderTotal] AS [OrderTotal],
[Extent1].[RefundedAmount] AS [RefundedAmount],
[Extent1].[RewardPointsWereAdded] AS [RewardPointsWereAdded],
[Extent1].[CheckoutAttributeDescription] AS [CheckoutAttributeDescription],
[Extent1].[CheckoutAttributesXml] AS [CheckoutAttributesXml],
[Extent1].[CustomerLanguageId] AS [CustomerLanguageId],
[Extent1].[AffiliateId] AS [AffiliateId],
[Extent1].[CustomerIp] AS [CustomerIp],
[Extent1].[AllowStoringCreditCardNumber] AS [AllowStoringCreditCardNumber],
[Extent1].[CardType] AS [CardType],
[Extent1].[CardName] AS [CardName],
[Extent1].[CardNumber] AS [CardNumber],
[Extent1].[MaskedCreditCardNumber] AS [MaskedCreditCardNumber],
[Extent1].[CardCvv2] AS [CardCvv2],
[Extent1].[CardExpirationMonth] AS [CardExpirationMonth],
[Extent1].[CardExpirationYear] AS [CardExpirationYear],
[Extent1].[AuthorizationTransactionId] AS [AuthorizationTransactionId],
[Extent1].[AuthorizationTransactionCode] AS [AuthorizationTransactionCode],
[Extent1].[AuthorizationTransactionResult] AS [AuthorizationTransactionResult],
[Extent1].[CaptureTransactionId] AS [CaptureTransactionId],
[Extent1].[CaptureTransactionResult] AS [CaptureTransactionResult],
[Extent1].[SubscriptionTransactionId] AS [SubscriptionTransactionId],
[Extent1].[PaidDateUtc] AS [PaidDateUtc],
[Extent1].[ShippingMethod] AS [ShippingMethod],
[Extent1].[ShippingRateComputationMethodSystemName] AS [ShippingRateComputationMethodSystemName],
[Extent1].[CustomValuesXml] AS [CustomValuesXml],
[Extent1].[Deleted] AS [Deleted],
[Extent1].[CreatedOnUtc] AS [CreatedOnUtc],
[Extent2].[Id] AS [Id1]
FROM [dbo].[Order] AS [Extent1] LEFT OUTER JOIN [dbo].[RewardPointsHistory] AS [Extent2] ON ([Extent2].[UsedWithOrder_Id] IS NOT NULL) AND ([Extent1].[Id] = [Extent2].[UsedWithOrder_Id])
WHERE [Extent1].[Deleted] <> 1
ORDER BY [Extent1].[CreatedOnUtc] DESC
The fix is to simply run a query from the OrderService:
public virtual int GetOrderCountAll(int storeId = 0)
{
string sql = "SELECT Count(*) FROM [dbo].[Order]";
if (storeId != 0)
{
sql += " WHERE [StoreId] = @StoreId";
}
var nbOfOrders = _dbContext.SqlQuery<int>(sql, storeId);
return nbOfOrders.FirstOrDefault();
}
Of course I added it to the interface and made the same fix for the same issue with getting all the customers.
Please check your code - see what it really does -
Also - please - do not argue with people - this is not complicated.
It is very simple code - very easy to understand and debug.
There really is no place to argue - it is what it is -
If you believe the code does something else than what it does - simply debug it - test it with real data like I suggested before - if you follow the code and do some performance analysis and you will know the truth right away. There is absolutely nothing to argue about.