symfony / demo

Symfony Demo Application
https://symfony.com/
MIT License
2.47k stars 1.61k forks source link

Remove unnecessary SQL queries #1454

Open mindaugasvcs opened 11 months ago

mindaugasvcs commented 11 months ago

https://github.com/symfony/demo/blob/206f0c9aab07cdc9f7437640b12947d35e9d5e72/src/Controller/BlogController.php#L55 Hi, I think a reference application should not promote unnecessary SQL queries. You fetch a tag object from DB then execute another SQL call, why not just passing a tag as a string to the PostRepository instead? Can I offer PR to fix this line to use just one SQL call?

GromNaN commented 11 months ago

This query return null if the tag is not found. So the subsequent query has not filter on the tag. This is not an ideal behavior for users. It would be better to return a 404 when no article are found with the given tag (that's what news websites does of SEO).