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

Improve exception message at ModelManager::batchDelete() #1734

Merged
merged 1 commit into from
Apr 3, 2023

Conversation

phansys
Copy link
Member

@phansys phansys commented Apr 1, 2023

Subject

I am targeting this branch, because this change respects BC.

Related to sonata-project/SonataDoctrineMongoDBAdminBundle#811 (comment).

Closes #1735.

Changelog

### Changed
- Exception message at `ModelManager::batchDelete()` in order to provide more details about the failed batch operation

@phansys phansys force-pushed the batch_delete branch 6 times, most recently from f33f699 to ed03b55 Compare April 1, 2023 23:52
@phansys phansys marked this pull request as ready for review April 2, 2023 02:22
@phansys phansys force-pushed the batch_delete branch 6 times, most recently from 22bb576 to 4b66cc7 Compare April 2, 2023 14:48
@phansys phansys added the minor label Apr 2, 2023
@phansys phansys force-pushed the batch_delete branch 9 times, most recently from 15c3ae2 to 85fd814 Compare April 2, 2023 23:06
@@ -45,6 +45,8 @@ final class ModelManager implements ModelManagerInterface, LockInterface, ProxyR
{
public const ID_SEPARATOR = '~';

private const BATCH_SIZE = 20;
Copy link
Member

Choose a reason for hiding this comment

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

Could be useful to introduce the size as parameter

public function batchDelete(string $class, BaseProxyQueryInterface $query, int $batchSize = self::DEFAULT_BATCH_SIZE): void

@phansys phansys force-pushed the batch_delete branch 2 times, most recently from f0004fb to 1ec6d3b Compare April 3, 2023 12:28
{
if (!$query instanceof ProxyQueryInterface) {
throw new \TypeError(sprintf('The query MUST implement %s.', ProxyQueryInterface::class));
}

// NEXT_MAJOR: Remove this assignment.
Copy link
Member

Choose a reason for hiding this comment

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

You don't need to wait next major.

https://onlinephp.io/c/4b5209

Copy link
Member Author

Choose a reason for hiding this comment

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

I forgot our classes are (finally 😆) final now 🚀

Copy link
Member

@jordisala1991 jordisala1991 left a comment

Choose a reason for hiding this comment

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

Could you apply the same for mongoDB?

@@ -345,7 +347,7 @@ public function addIdentifiersToQuery(string $class, BaseProxyQueryInterface $qu
$qb->andWhere(sprintf('( %s )', implode(' OR ', $sqls)));
}

public function batchDelete(string $class, BaseProxyQueryInterface $query): void
public function batchDelete(string $class, BaseProxyQueryInterface $query, int $batchSize = self::BATCH_SIZE): void
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't we add this to the interface? or at least with a next major comment?

Copy link
Member

Choose a reason for hiding this comment

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

We cant add this to the interface since it wont be bc but yes we can add the next major constant and introduce the constant in the SonataAdminBundle instead

Copy link
Member Author

Choose a reason for hiding this comment

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

I was thinking about the constant in SonataAdmin, but I think this must be kept in the scope of each model manager (the behavior regarding the batch size, the way each driver handles the transactions and the cost it demands is specific and not a common concern).

Copy link
Member

Choose a reason for hiding this comment

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

If we can't add the constant to the SonataAdmin interface, we can't add the batchSize parameter to the interface too.
I'm fine with both solution.

Copy link
Member

Choose a reason for hiding this comment

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

Then what is the use case for adding this parameter on the function? How are you suposed to pass it on an admin?

Copy link
Member

Choose a reason for hiding this comment

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

It would be easier to add it to the interface, but even if we don't, people can still pass the batch size as third parameter after a instanceof check.

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

Successfully merging this pull request may close these issues.

Add tests for ModelManager::batchDelete()
3 participants