Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VP-4972: Fix SearchPrices with GroupByProducts=true flag #102

Merged
merged 4 commits into from
Oct 12, 2020
Merged

Conversation

eMazeika
Copy link

@eMazeika eMazeika commented Sep 17, 2020

The resulting SQL:
Count:

SELECT COUNT(*)
FROM (
    SELECT [p].[ProductId]
    FROM [Price] AS [p]
    GROUP BY [p].[ProductId]
) AS [t]

Skip and take (ProductId):

exec sp_executesql N'SELECT [p].[ProductId]
FROM [Price] AS [p]
GROUP BY [p].[ProductId]
ORDER BY (SELECT 1)
OFFSET @__p_0 ROWS FETCH NEXT @__p_1 ROWS ONLY',N'@__p_0 int,@__p_1 int',@__p_0=20,@__p_1=10

Select Prices by PriductId:

exec sp_executesql N'SELECT [t].[Id]
FROM (
    SELECT [p].[Id], [p].[CreatedBy], [p].[CreatedDate], [p].[EndDate], [p].[List], [p].[MinQuantity], [p].[ModifiedBy], [p].[ModifiedDate], [p].[OuterId], [p].[PricelistId], [p].[ProductId], [p].[ProductName], [p].[Sale], [p].[StartDate]
    FROM [Price] AS [p]
    WHERE [p].[ProductId] IN (N''198d4ad4d5be42aea8d9546885a3bd99'', N''1ab7b7533787472bb13415a633791bef'', N''1af7b54780fb452eb0e8ca7d5e73d7bf'', N''1c2eaea0a391492ca1045a42d598692e'', N''217be9f3d9064075821f6785dca658b9'', N''2228545259524745b99875bb51111e97'', N''2252519abec64a4ea8585c8af971c6d9'', N''228ffc2dcdfd4ec58e4487d180199d01'', N''24234aafeb0f4dbda72ffd977b32befb'', N''24cd1f338dfc4d89ad68633932a4225e'')
    ORDER BY (SELECT 1)
    OFFSET @__p_1 ROWS FETCH NEXT @__p_2 ROWS ONLY
) AS [t]
ORDER BY [t].[List], [t].[Id]',N'@__p_1 int,@__p_2 int',@__p_1=0,@__p_2=2147483647

{
if (criteria.ProductIds.IsNullOrEmpty())
{
criteria.ProductIds = await groupedQuery.OrderBy(x => x).Skip(criteria.Skip).Take(criteria.Take).ToArrayAsync();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need to change criteria.ProductIds because it already handled in BuildQueryAsync
thus, you can replace the if/else statement with only single line

query = query.Where(x => groupedQueryids.Contains(x.ProductId));

@akak1977 akak1977 merged commit 15b33c6 into dev Oct 12, 2020
@akak1977 akak1977 deleted the fix/VP-4972 branch October 12, 2020 14:38
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities (and Security Hotspot 0 Security Hotspots to review)
Code Smell A 0 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

warning The version of Java (1.8.0_265) you have used to run this analysis is deprecated and we will stop accepting it from October 2020. Please update to at least Java 11.
Read more here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants