Problem/Motivation

#910190: Entire schema cache needlessly loaded on all pages fixed a performance issue, but introduced a big pain: because entity_get_info() indirectly calls drupal_get_schema() the entity and schema information are intractably bound to each other. Also, because the Field SQL storage needs to query the field information in a hook_schema(), the field system is also intractably bound to the two others.

This means that:

  1. In hook_entity_info() and hook_entity_info_alter(), you cannot call either drupal_get_schema() nor field_info_field()
  2. In hook_schema(), hook_schema_alter and hook_field_schema(), you cannot call either entity_get_info() nor field_info_field()
  3. In hook_field_extra_fields(), you cannot call either entity_get_info() nor drupal_get_schema()

Three example cases:

  • This prevents the UUID module from adding a column to the schema of the base table of an entity based on the entity info; at least not without an ugly workaround;
  • This prevents Drupal Commerce from adding a view mode to an entity based on the fields that point to it; at least not without an ugly workaround;
  • This prevents the Entity Reference module from adding foreign key information to its fields pointing the the base table of the target entity table; at least not without an ugly workaround.

Proposed resolution

We modify entity_get_info() only compute the schema *after* the computing of the entity info is complete (minor API change, see below).

User interface changes

None.

API changes

The SQL schema information is not available anymore in hook_entity_info_alter().

Comments

geek-merlin’s picture

wow, that's complex dependencies. is there a dataflow diagram for this somewhere? ;-)

tim.plunkett’s picture

I opened #1441488: Don't call entity_get_info() from inside hook_field_extra_fields() because this issue seemed to explain the problem, but I can't really track it down.
And of the three code examples above, none are explicitly about hook_field_extra_fields().

geek-merlin’s picture

a hint: looks like the uuid example just uses "basic entity info" (just from hooks) which might be gathered by calling hook_entity_info & ~alter but no field hooks.

geek-merlin’s picture

thought a while about this.
i don't think drupal is broken.

it's just that the system is so complex it's hard to understand the dataflow.
do we need to refactor it? not to tell without a thorough understanding.

posted one approach to gather this understanding:
#1450612: Dataflow browser for hooks system
maybe there are more.

sun’s picture

plach’s picture

Status: Active » Closed (duplicate)