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

🐛 Fix label & method countResults to display good things with simple pager #8183

Draft
wants to merge 1 commit into
base: 4.x
Choose a base branch
from

Conversation

elyanory
Copy link

Subject

Using SimplePager renders wrong statement on batch actions.
For example: selecting 50 elements (on a table containing >1000 elements) the batch action checkbox "all_elements" would result in "all elements (51)".

Now with this PR, the display will change. A second basic query will be used to count the total number of results.
Using the example above, this would give: "all elements (1000)".

Closes #8164.

Changelog

### Added
- `SimplePager::getTotalResults()` This method actually calculates the number of lines.

### Changed
- `SimplePager::countResults()` The "countResults" method now returns the true total number of lines ;
- `SimplePager::init()` The "init" method also calculates the total number of lines.

### Deprecated

### Removed

### Fixed

### Security

@zyberspace
Copy link

But doesn't this make the simple pager super slow on huge datasets? I thought the whole reason to use the simple pager is because the count of the normal pager would take too long for certain entities?

Copy link
Member

@VincentLanglet VincentLanglet left a comment

Choose a reason for hiding this comment

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

But doesn't this make the simple pager super slow on huge datasets? I thought the whole reason to use the simple pager is because the count of the normal pager would take too long for certain entities?

Cf the doc,
https://docs.sonata-project.org/projects/SonataAdminBundle/en/4.x/cookbook/recipe_improve_performance_large_datasets/#change-default-pager-to-simplepager

This is exactly the purpose of the SimplePager. You lost every benefit with such implementation.

Comment on lines 83 to 95
/** @var ProxyQuery $query */
$query = $this->getQuery();

if (null === $query) {
throw new \LogicException('Uninitialized query.');
}

$query->select(sprintf('COUNT(%s.id)', $query->getRootAlias()));
$query->setFirstResult(0);
$query->setMaxResults(1);


return $query->getDoctrineQuery()->getSingleScalarResult();
Copy link
Member

Choose a reason for hiding this comment

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

This is wrong, you're introducing a dependy on Sonata\DoctrineORMAdminBundle but SonataAdmin is supposed to work with any other database bundle like https://github.com/sonata-project/SonataDoctrineMongoDBAdminBundle or a custom one.

You can only use method from the ProxyQueryInterface API.

@elyanory
Copy link
Author

But doesn't this make the simple pager super slow on huge datasets? I thought the whole reason to use the simple pager is because the count of the normal pager would take too long for certain entities?

This is exactly the purpose of the SimplePager. You lost every benefit with such implementation.

You're right, I'm going to lean more towards the idea of displaying something like this: "25+".
I thought that adding a simple query to get the total number of results would be interesting 😉

@elyanory elyanory force-pushed the fix/simple-pager-count-results branch from 4346a40 to 63db464 Compare May 21, 2024 14:45
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.

Batch actions all_elements on SimplePager
3 participants