Commit fee42cb6 authored by catch's avatar catch
Browse files

Issue #2247095 by yched, xjm, alexpott: Optimize loading of deleted fields.

parent 6e70062d
......@@ -97,7 +97,12 @@ public function loadByProperties(array $conditions = array()) {
$include_deleted = isset($conditions['include_deleted']) ? $conditions['include_deleted'] : FALSE;
unset($conditions['include_deleted']);
// Get fields stored in configuration.
$fields = array();
// Get fields stored in configuration. If we are explicitly looking for
// deleted fields only, this can be skipped, because they will be retrieved
// from state below.
if (empty($conditions['deleted'])) {
if (isset($conditions['entity_type']) && isset($conditions['field_name'])) {
// Optimize for the most frequent case where we do have a specific ID.
$id = $conditions['entity_type'] . $conditions['field_name'];
......@@ -107,9 +112,10 @@ public function loadByProperties(array $conditions = array()) {
// No specific ID, we need to examine all existing fields.
$fields = $this->loadMultiple();
}
}
// Merge deleted fields (stored in state) if needed.
if ($include_deleted) {
if ($include_deleted || !empty($conditions['deleted'])) {
$deleted_fields = $this->state->get('field.field.deleted') ?: array();
foreach ($deleted_fields as $id => $config) {
$fields[$id] = $this->create($config);
......
......@@ -104,7 +104,12 @@ public function loadByProperties(array $conditions = array()) {
$include_deleted = isset($conditions['include_deleted']) ? $conditions['include_deleted'] : FALSE;
unset($conditions['include_deleted']);
// Get instances stored in configuration.
$instances = array();
// Get instances stored in configuration. If we are explicitly looking for
// deleted instances only, this can be skipped, because they will be
// retrieved from state below.
if (empty($conditions['deleted'])) {
if (isset($conditions['entity_type']) && isset($conditions['bundle']) && isset($conditions['field_name'])) {
// Optimize for the most frequent case where we do have a specific ID.
$id = $conditions['entity_type'] . '.' . $conditions['bundle'] . '.' . $conditions['field_name'];
......@@ -114,9 +119,10 @@ public function loadByProperties(array $conditions = array()) {
// No specific ID, we need to examine all existing instances.
$instances = $this->loadMultiple();
}
}
// Merge deleted instances (stored in state) if needed.
if ($include_deleted) {
if ($include_deleted || !empty($conditions['deleted'])) {
$deleted_instances = $this->state->get('field.instance.deleted') ?: array();
$deleted_fields = $this->state->get('field.field.deleted') ?: array();
foreach ($deleted_instances as $id => $config) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment