Took us a while to figure out that logic in #2221577: Fix assumption that field settings is not a nested array.

Attached patch:
- makes the prototype logic explicit,
- makes it clearer what the "prototype cache keys" are composed of,
- uses different var names for "the DataDefinition of the root object, used for prototype cache key", and "the DataDefinition of the object we want to create".
- changes Crypt::hashBase64() to crc32() for hashing the serialized settings, as per the discussion in #2346763: Improve views field rendering performance by caching entity display objects (see #10 & #13 over there)

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Task - clarifies & unifies some complex code
Issue priority Normal
Unfrozen changes Unfrozen because it doesn't change any external behavior
Prioritized changes The main goal of this issue is improve maintainability. This is not a prioritized change for the beta phase.
Disruption None
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

yched’s picture

Status: Active » Needs review
FileSize
3.93 KB

Patch

yched’s picture

Issue summary: View changes
andypost’s picture

Status: Needs review » Reviewed & tested by the community

Looks great

alexpott’s picture

Status: Reviewed & tested by the community » Needs review

This issue is a normal task that intends to reduce fragility, and per #2350615: [policy, no patch] What changes can be accepted during the Drupal 8 beta phase?, we should discuss whether the benefit outweighs disruption. I would like to see a +1 from @fago or @berdir here as entity system maintainers (of which I assume typed data to be a part).

Personally I'm in favour of this issue because the discussions in #2221577: Fix assumption that field settings is not a nested array did reveal that this code is confusing.

Setting back to needs review to have said discussion.

yched’s picture

@alexpott : I don't understand - this patch does not change the outside behavior of the method in any way.
Are we supposed to justify any internal code refactoring now ?

alexpott’s picture

@yched yep - see #2350615: [policy, no patch] What changes can be accepted during the Drupal 8 beta phase? for the allowed changes. There's a really good flowchart that explains it.

yched’s picture

OK - well I guess the definition of an internal refactor is "disruption = 0", so the "impact > disruption" criteria should be manageable :-)

Berdir’s picture

Assigned: Unassigned » fago

I have to defer to @fago on this, he knows this part better and currently only have very limited core time, so I can't go into depth here.

But I see nothing with changing this in general.

yched’s picture

Changed Crypt::hashBase64() to crc32() for hashing the serialized settings, as per the discussion in #2346763: Improve views field rendering performance by caching entity display objects (see #10 & #13 over there)

yched’s picture

Issue summary: View changes
andypost’s picture

+1 to unify that kind of hashing

fago’s picture

Assigned: fago » Unassigned
Status: Needs review » Needs work

In general, +1 on the change. It makes the code clearer and easier to follow, but has no impact to the outside. Well unless people run into crc32 collisions now, but I think that's unlikely enough. ;-)

Here a review:

  1. +++ b/core/lib/Drupal/Core/TypedData/TypedDataManager.php
    @@ -248,26 +247,31 @@ public function getInstance(array $options) {
    +      $parts[] = crc32(serialize($settings));
    

    I cannot tell on which hashing algo to use, but looks like this has been discussed already. However, as it was something worth a discussion I think it also deserves a comment explaining our thinking.

  2. +++ b/core/lib/Drupal/Core/TypedData/TypedDataManager.php
    @@ -277,17 +281,16 @@ public function getPropertyInstance(TypedDataInterface $object, $property_name,
    +      // Create the prototype with initial parenting information, but without
    +      // any value.
           $this->prototypes[$key] = $this->create($definition, NULL, $property_name, $object);
    

    The parenting information differs by clone and will be overwritting later by setContext() - thus it does not make sense to set it here. To avoid confusion it shoul be removed and rely on parenting info being set later.

fago’s picture

Discussed 2. with yched on IRC. I wrongly assumed that the patch introduces the pass $object parameter, but it doesn't. Looking closer at it, we shoud keep it such that constructors have enough parenting information to setup objects. But as this is not obvious, let's have that documented here.

yched’s picture

Status: Needs work » Needs review
FileSize
4.37 KB
2.09 KB

Should adress #12 / #13
+ fixes a 80 chars wrapping issue in the previous patch.

yched’s picture

Bump - @fago's remarks have been adressed, this just waiting for an RTBC.

amateescu’s picture

Status: Needs review » Reviewed & tested by the community

Looks great to me.

fago’s picture

New comments are great, thanks. Agreed this is ready.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs issue summary update

This issue is a normal task so we need to outline how it fits within the allowable Drupal 8 beta criteria. Can someone add Drupal 8 beta phase evaluation template to the issue summary.

I think this internal refactoring is justified given the complexity of the code and moving to the consistent hashing for non cryptographic purposes makes sense too.

yched’s picture

Issue summary: View changes
Status: Needs work » Reviewed & tested by the community
Issue tags: -Needs issue summary update

Table added

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

This patch makes this easier to maintain, consistent with other non cryptographic hashing and less fragile. Committed f503eb9 and pushed to 8.0.x. Thanks!

Thanks for adding the beta evaluation for to the issue summary.

  • alexpott committed f503eb9 on 8.0.x
    Issue #2364267 by yched: Clarify the logic in TypedDataManager::...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.