Skip to content

Disable eager loading partial fetch by default #1069 #1100

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

Merged
merged 1 commit into from
May 18, 2017

Conversation

soyuka
Copy link
Member

@soyuka soyuka commented May 4, 2017

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #1069
License MIT
Doc PR na

As discussed in #1069 sometimes you still want to fetch a property, even though it will not be serialized. This new metadata attribute adds a flag that will prevent the eager loader to check the readable state.
ping @bwegrzyn

@teohhanhui
Copy link
Contributor

I think we should just use an attribute, since this is a "hint" for the eager loading extension. We do not want to be adding metadata fields that are not well thought out.

@soyuka
Copy link
Member Author

soyuka commented May 4, 2017

hmm yeah you're right, I'm changing this thanks! To me this is not a bug though, more a feature.

@soyuka soyuka force-pushed the fix/1069 branch 4 times, most recently from 44ae45c to e2aadf6 Compare May 4, 2017 12:11
@soyuka soyuka changed the title Add fetchable Property metadata #1069 Add fetchable attribute on Property metadata #1069 May 4, 2017
@soyuka soyuka changed the title Add fetchable attribute on Property metadata #1069 Enable fetchable attribute on Property metadata #1069 May 4, 2017
@bwegrzyn
Copy link
Contributor

bwegrzyn commented May 4, 2017

Looks good to me! 👍

@soyuka
Copy link
Member Author

soyuka commented May 4, 2017

Wow about the tests, as @meyerbaptiste said master is broken. At about 14h gmt + 1 it was okay 😛

@teohhanhui
Copy link
Contributor

Partial loading is dangerous because it breaks entities. It must definitely be opt-in. Having partial loading on by default is thus a bug.

@teohhanhui
Copy link
Contributor

teohhanhui commented May 5, 2017

I don't believe that this needs to be configurable, not in this way. We should instead make sure that partial loading is only activated on an opt-in basis.

@soyuka soyuka changed the title Enable fetchable attribute on Property metadata #1069 Disable eager loading partial fetch by default #1069 May 5, 2017
@soyuka soyuka force-pushed the fix/1069 branch 2 times, most recently from 6ae4991 to 752455d Compare May 5, 2017 15:18
{
$this->propertyNameCollectionFactory = $propertyNameCollectionFactory;
$this->propertyMetadataFactory = $propertyMetadataFactory;
$this->resourceMetadataFactory = $resourceMetadataFactory;
$this->maxJoins = $maxJoins;
$this->forceEager = $forceEager;
$this->fetchPartial = $fetchPartial;
Copy link
Member Author

Choose a reason for hiding this comment

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

name is fine @teohhanhui 😛 ?

@@ -50,6 +50,7 @@ public function getConfigTreeBuilder()
->addDefaultsIfNotSet()
->children()
->booleanNode('enabled')->defaultTrue()->info('To enable or disable eager loading')->end()
->booleanNode('fetch_partial')->defaultFalse()->info('Fetch only partial data according to serialization groups')->end()
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should add:

"If enabled, Doctrine ORM entities will NOT work as expected if any of the other fields are used."

😝

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@soyuka soyuka force-pushed the fix/1069 branch 4 times, most recently from 298cd49 to cf4831b Compare May 16, 2017 07:45
@soyuka
Copy link
Member Author

soyuka commented May 16, 2017

ping @api-platform/core-team this one should be good to go.

Should we merge this on 2.0 instead? It's not a breaking change but it removes a feature that was enabled by default before. Results won't change but performances may be impacted.

@teohhanhui
Copy link
Contributor

This is a bugfix so it should go into 2.0.

@soyuka soyuka changed the base branch from master to 2.0 May 17, 2017 07:30
@@ -44,13 +44,14 @@
private $serializerContextBuilder;
private $requestStack;

public function __construct(PropertyNameCollectionFactoryInterface $propertyNameCollectionFactory, PropertyMetadataFactoryInterface $propertyMetadataFactory, ResourceMetadataFactoryInterface $resourceMetadataFactory, int $maxJoins = 30, bool $forceEager = true, RequestStack $requestStack = null, SerializerContextBuilderInterface $serializerContextBuilder = null)
public function __construct(PropertyNameCollectionFactoryInterface $propertyNameCollectionFactory, PropertyMetadataFactoryInterface $propertyMetadataFactory, ResourceMetadataFactoryInterface $resourceMetadataFactory, int $maxJoins = 30, bool $forceEager = true, bool $fetchPartial = false, RequestStack $requestStack = null, SerializerContextBuilderInterface $serializerContextBuilder = null)
Copy link
Member

Choose a reason for hiding this comment

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

Isn't this a BC break?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oops... Another ugly hack required?

p/s: When can we actually break things again? In the Symfony model (deprecations only), the answer seems to be "never, unless you create new interfaces / classes". \o/

Copy link
Member Author

Choose a reason for hiding this comment

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

Kinda yes. I'll try to handle backward compatibility! I thought about setting this new argument as last one, do you think it'd be a solution?

Copy link
Member Author

Choose a reason for hiding this comment

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

@teohhanhui I can also put this as last argument. Then, no ugly hacks nor BC break no?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, sure. But then there's still the underlying problem of piling on layers upon layers of bad design (because we don't really have a choice).

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah sure, when we can break again we will refactor those don't worry :).

@soyuka soyuka force-pushed the fix/1069 branch 2 times, most recently from b35c20b to ce14652 Compare May 17, 2017 12:36
@soyuka
Copy link
Member Author

soyuka commented May 17, 2017

LGTM, can someone do a last review? Thanks!

@soyuka soyuka merged commit 84a402c into api-platform:2.0 May 18, 2017
@soyuka soyuka deleted the fix/1069 branch January 29, 2018 09:38
hoangnd25 pushed a commit to hoangnd25/core that referenced this pull request Feb 23, 2018
Disable eager loading partial fetch by default api-platform#1069
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.

4 participants