Skip to content

Fix distinct count in SelectModifierListener#22

Merged
heimrich-hannot merged 1 commit into
mainfrom
fix/counting-query
Jun 2, 2026
Merged

Fix distinct count in SelectModifierListener#22
heimrich-hannot merged 1 commit into
mainfrom
fix/counting-query

Conversation

@ericges

@ericges ericges commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

This pull request primarily refactors the way counting queries are handled in the query struct modifiers. The most important changes involve removing the now-unnecessary GroupByModifierListener and simplifying the logic for counting queries in the SelectModifierListener. This results in cleaner and more maintainable code.

Refactoring and Simplification of Counting Query Logic:

  • Removed the GroupByModifierListener class entirely, consolidating its logic into the SelectModifierListener. This reduces redundancy and centralizes counting query modifications.
  • In SelectModifierListener, the counting query now always uses COUNT(DISTINCT(main.id)) (instead of switching between COUNT(*) and COUNT(DISTINCT ...) depending on joins), and explicitly sets groupBy to null for counting queries.

Exception Handling and Documentation:

  • Updated the exception thrown by SelectModifierListener::__invoke from a custom AbortFilteringException to the more general Doctrine\DBAL\Exception, and updated the docblock to reflect this. [1] [2]

@koertho koertho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Beautiful 🐤

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors how “counting” list queries are built by centralizing the count/group-by behavior in SelectModifierListener and removing the dedicated GroupByModifierListener. The goal is to make count queries consistently use a distinct count of the main record ID and avoid grouping during counts.

Changes:

  • Simplifies counting select generation to always use COUNT(DISTINCT(main.id)) in SelectModifierListener.
  • Ensures counting queries explicitly clear GROUP BY via SelectModifierListener.
  • Removes the now-redundant GroupByModifierListener.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/EventListener/QueryStructModifier/SelectModifierListener.php Centralizes counting-query select and group-by clearing logic; updates PHPDoc/exception import.
src/EventListener/QueryStructModifier/GroupByModifierListener.php Removes the separate listener that previously nulled GROUP BY for count queries.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/EventListener/QueryStructModifier/SelectModifierListener.php
Comment thread src/EventListener/QueryStructModifier/SelectModifierListener.php
@heimrich-hannot heimrich-hannot merged commit c572a8f into main Jun 2, 2026
16 checks passed
@heimrich-hannot heimrich-hannot deleted the fix/counting-query branch June 2, 2026 10:16
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.

4 participants