-
-
Notifications
You must be signed in to change notification settings - Fork 139
Conversation
What is the issue? How does your patch fix it? |
@@ -101,10 +101,9 @@ public function getProductCount(CategoryInterface $category, $limit = 1000) | |||
AND (c.enabled = :categoryEnabled OR c.enabled IS NULL) | |||
AND p.parent_id IS NULL | |||
AND pc.category_id = :categoryId | |||
LIMIT %d |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you seen the comment on line 87? Also, what are the consequences of removing this LIMIT
for other RDBMSs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I update RP description.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO, we should try to leverage the DBAL as much as possible in order to avoid dealing with specific RDBMSs by our own responsibility. This way, we could build the subquery using DQL or a query builder, and then if it is really required, get the raw SQL query to be used with the main query.
In the worst case, if that is not possible, we should build the different syntaxes by hand.
Even if this query is just intended to return the counted results, I guess leaving the limit open in the persistence layer is not good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh right, I read to fast it seems… sorry!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@phansys have you seen the comment on line 87? @wbloszyk what about you?
Yes. What I mean is something like this:
$dql = 'SELECT DISTINCT(pc.product_id) FROM %s pc ... LIMIT %d'; $sql = 'SELECT count(cnt.product_id) AS "cntId" FROM('.$dql->getSQL().');';
- Subqueris is not allowed.
- Generating SQL crash (DQL look the same)
- Modify SQL for each platform is to mest
ProductCategoryManager::getProductCount()
is only use in ProductMenuBuilder::getCategoryTitle()
to display counts in menu.
We can inject ProductManager and use:
public function getCategoryActiveProductsQueryBuilder(?CategoryInterface $category = null, $filter = null, $option = null) |
This change will also limit products count when filters will be set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK, the syntax SELECT COUNT(DISTINCT pc.product_id)
is supported by DQL, even by query builder with Expr::countDistinct()
. Why we need a subquery then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know doctrine to much. Anyway we should get the same result from ProductCategoryManager::getProductCount()
and ProductManager::getProductCountInCategory
Names are example. We should reuse query as much as possible. It is also yours words. I will add some core example in Monday.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! 👍
Just let me know if you need help. I'm not using this bundle, but I can provide support with the ORM if required.
@@ -101,10 +101,9 @@ public function getProductCount(CategoryInterface $category, $limit = 1000) | |||
AND (c.enabled = :categoryEnabled OR c.enabled IS NULL) | |||
AND p.parent_id IS NULL | |||
AND pc.category_id = :categoryId | |||
LIMIT %d |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO, we should try to leverage the DBAL as much as possible in order to avoid dealing with specific RDBMSs by our own responsibility. This way, we could build the subquery using DQL or a query builder, and then if it is really required, get the raw SQL query to be used with the main query.
In the worst case, if that is not possible, we should build the different syntaxes by hand.
Even if this query is just intended to return the counted results, I guess leaving the limit open in the persistence layer is not good.
This PR has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Subject
This PR replace limit from database to php. This will resolve problem with diffrence usages of limit function in some sql.
SQL Server / MS Access Syntax:
MySQL Syntax:
Oracle Syntax:
I am targeting this branch, because it is PATCH.
Part of sonata-project/dev-kit#689