Skip to content

Disable eager loading partial fetch by default #1069#1100

Merged
soyuka merged 1 commit into
api-platform:2.0from
soyuka:fix/1069
May 18, 2017
Merged

Disable eager loading partial fetch by default #1069#1100
soyuka merged 1 commit into
api-platform:2.0from
soyuka:fix/1069

Conversation

@soyuka

@soyuka soyuka commented May 4, 2017

Copy link
Copy Markdown
Member
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
Copy Markdown
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

soyuka commented May 4, 2017

Copy link
Copy Markdown
Member Author

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

bwegrzyn commented May 4, 2017

Copy link
Copy Markdown
Contributor

Looks good to me! 👍

@soyuka

soyuka commented May 4, 2017

Copy link
Copy Markdown
Member Author

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

@teohhanhui

Copy link
Copy Markdown
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

teohhanhui commented May 5, 2017

Copy link
Copy Markdown
Contributor

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->resourceMetadataFactory = $resourceMetadataFactory;
$this->maxJoins = $maxJoins;
$this->forceEager = $forceEager;
$this->fetchPartial = $fetchPartial;

Copy link
Copy Markdown
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 😛 ?

->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
Copy Markdown
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
Copy Markdown
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

soyuka commented May 16, 2017

Copy link
Copy Markdown
Member Author

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
Copy Markdown
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
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

soyuka commented May 17, 2017

Copy link
Copy Markdown
Member Author

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.

5 participants