Commit ebf478b5 authored by David_Rothstein's avatar David_Rothstein

Issue #1338966 by geerlingguy, loganfsmyth, lokapujya: Fixed Introduce...

Issue #1338966 by geerlingguy, loganfsmyth, lokapujya: Fixed Introduce _rdf_mapping_load_multiple to reduce queries.
parent af79dc0b
......@@ -190,17 +190,33 @@ function _rdf_get_default_mapping($type) {
* An RDF mapping structure or an empty array if no record was found.
*/
function _rdf_mapping_load($type, $bundle) {
$mapping = db_select('rdf_mapping')
->fields(NULL, array('mapping'))
$mappings = _rdf_mapping_load_multiple($type, array($bundle));
return $mappings ? reset($mappings) : array();
}
/**
* Helper function to retrieve a set of RDF mappings from the database.
*
* @param $type
* The entity type of the mappings.
* @param $bundles
* The bundles the mappings refer to.
*
* @return
* An array of RDF mapping structures, or an empty array.
*/
function _rdf_mapping_load_multiple($type, array $bundles) {
$mappings = db_select('rdf_mapping')
->fields(NULL, array('bundle', 'mapping'))
->condition('type', $type)
->condition('bundle', $bundle)
->condition('bundle', $bundles)
->execute()
->fetchField();
->fetchAllKeyed();
if (!$mapping) {
return array();
foreach ($mappings as $bundle => $mapping) {
$mappings[$bundle] = unserialize($mapping);
}
return unserialize($mapping);
return $mappings;
}
/**
......@@ -368,10 +384,13 @@ function rdf_modules_uninstalled($modules) {
function rdf_entity_info_alter(&$entity_info) {
// Loop through each entity type and its bundles.
foreach ($entity_info as $entity_type => $entity_type_info) {
if (isset($entity_type_info['bundles'])) {
foreach ($entity_type_info['bundles'] as $bundle => $bundle_info) {
if ($mapping = _rdf_mapping_load($entity_type, $bundle)) {
$entity_info[$entity_type]['bundles'][$bundle]['rdf_mapping'] = $mapping;
if (!empty($entity_type_info['bundles'])) {
$bundles = array_keys($entity_type_info['bundles']);
$mappings = _rdf_mapping_load_multiple($entity_type, $bundles);
foreach ($bundles as $bundle) {
if (isset($mappings[$bundle])) {
$entity_info[$entity_type]['bundles'][$bundle]['rdf_mapping'] = $mappings[$bundle];
}
else {
// If no mapping was found in the database, assign the default RDF
......
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