Commit 73cbacac authored by rossb89's avatar rossb89 Committed by generalredneck

Issue #2707123 by rossb89: entity_load to load all entities at once causing...

Issue #2707123 by rossb89: entity_load to load all entities at once causing module to be unusable on sites with large amount of entities of type being loaded
parent 866a795c
...@@ -79,17 +79,31 @@ function views_natural_sort_views_natural_sort_get_rebuild_data($entry_type){ ...@@ -79,17 +79,31 @@ function views_natural_sort_views_natural_sort_get_rebuild_data($entry_type){
empty($supported_entity_properties[$entry_type['entity_type']][$entry_type['field']])) { empty($supported_entity_properties[$entry_type['entity_type']][$entry_type['field']])) {
return array(); return array();
} }
$entities = entity_load($entry_type['entity_type']);
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', $entry_type['entity_type']);
$result = $query->execute();
$entity_ids = array();
if (isset($result[$entry_type['entity_type']])) {
$entity_ids = array_keys($result[$entry_type['entity_type']]);
}
$data = array(); $data = array();
foreach($entities as $eid => $entity) {
foreach ($entity_ids as $entity_id) {
$entity = reset(entity_load($entry_type['entity_type'], array($entity_id)));
$data[] = array( $data[] = array(
'eid' => $eid, 'eid' => $entity_id,
'entity_type' => $entry_type['entity_type'], 'entity_type' => $entry_type['entity_type'],
'field' => $entry_type['field'], 'field' => $entry_type['field'],
'delta' => 0, 'delta' => 0,
'content' => $entity->$entry_type['field'], 'content' => $entity->$entry_type['field'],
); );
} }
return $data; return $data;
} }
......
...@@ -59,11 +59,30 @@ function views_natural_sort_text_field_views_natural_sort_get_rebuild_data($entr ...@@ -59,11 +59,30 @@ function views_natural_sort_text_field_views_natural_sort_get_rebuild_data($entr
} }
$field = field_info_field($entry_type['field']); $field = field_info_field($entry_type['field']);
$data = array(); $data = array();
$entities = entity_load($entry_type['entity_type']); $bundles = array();
foreach ($entities as $entity) {
if (isset($field['bundles'][$entry_type['entity_type']])) {
foreach ($field['bundles'][$entry_type['entity_type']] as $key => $bundle) {
$bundles[] = $bundle;
}
}
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', $entry_type['entity_type'])
->entityCondition('bundle', $bundles, 'IN');
$result = $query->execute();
$entity_ids = array();
if (isset($result[$entry_type['entity_type']])) {
$entity_ids = array_keys($result[$entry_type['entity_type']]);
}
foreach ($entity_ids as $entity_id) {
$entity = reset(entity_load($entry_type['entity_type'], array($entity_id)));
$entries = _views_natural_sort_text_field_to_vns($entry_type['entity_type'], $entity, $field); $entries = _views_natural_sort_text_field_to_vns($entry_type['entity_type'], $entity, $field);
if (!empty($entries)) { if (!empty($entries)) {
$data += $entries; $data = array_merge($data, $entries);
} }
} }
return $data; return $data;
......
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