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

Introduce resource model pool to replace UniversalFactory #13302

Merged
merged 9 commits into from
Feb 16, 2019
Merged

Introduce resource model pool to replace UniversalFactory #13302

merged 9 commits into from
Feb 16, 2019

Conversation

schmengler
Copy link
Contributor

@schmengler schmengler commented Jan 21, 2018

Description

I was digging a bit for unnecessary object instantiations and one thing I found was the good old _init method in collections where the class name of the resource model is passed. resource models are usually shared instances, but collections misuse a "Magento\Framework\Validator\UniversalFactory" (which has a TODO comment that it should be eliminated) to create a new instance every time.

As discussed with @antonkril I introduced a ResourceModelPool as replacement.

For BC, the universalFactory argument stays in place, and the resourceModelPool argument has been added at the end with null default. The protected _universalFactory property is not used by the core anymore and is now marked as @deprecated

Contribution checklist

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)

* @param string $resourceClassName
* @return AbstractResource
*/
public function get($resourceClassName): AbstractResource;
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add string type hinting, as 2.3 supports PHP 7.0+

@schmengler
Copy link
Contributor Author

@buskamuza right, I updated the PR!

@sivaschenko
Copy link
Member

@schmengler sorry for slow response, can you please update your branch and resolve the conflicts

@schmengler
Copy link
Contributor Author

Will do

@sivaschenko
Copy link
Member

@schmengler see my messages in slack as well, there is a rebased branch with this pull request that you can use https://github.com/sivaschenko/magento2/tree/resource-model-pool-rebased (but I didn't want to force push to your branch)

@schmengler
Copy link
Contributor Author

@sivaschenko So I did it now :)

@sivaschenko
Copy link
Member

Hi @schmengler running bin/magento setup:di:compile results in the following error:

Invalid ExtensionInterface for nonexistent class Interface in file app/code/Magento/TestModuleExtensionAttributes/Api/Data/FakeExtensibleTwoInterface.php

@okorshenko okorshenko removed this from the Release: 2.3.1 milestone Jan 28, 2019
@magento-engcom-team magento-engcom-team merged commit e21f53b into magento:2.3-develop Feb 16, 2019
@ghost
Copy link

ghost commented Feb 16, 2019

Hi @schmengler, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

* See COPYING.txt for license details.
*/

namespace Magento\Framework\Model\ResourceModel;
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we have strict_types=1 there?

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

Successfully merging this pull request may close these issues.

10 participants