summaryrefslogtreecommitdiff
path: root/modules/rdf
diff options
context:
space:
mode:
authorAngie Byron <webchick@24967.no-reply.drupal.org>2010-01-14 03:42:45 +0000
committerAngie Byron <webchick@24967.no-reply.drupal.org>2010-01-14 03:42:45 +0000
commit40638ae8df4625e39b2943b778fd693d1bd67bd9 (patch)
tree9fd6c4e1c0c37dfd28cb4187421090d3d7b8378c /modules/rdf
parent7e0059d53b8f79f72ecd51fa8553ec319c36026b (diff)
downloadbrdo-40638ae8df4625e39b2943b778fd693d1bd67bd9.tar.gz
brdo-40638ae8df4625e39b2943b778fd693d1bd67bd9.tar.bz2
#683590 by catch: Fixed user_load() still being called for every node view.
Diffstat (limited to 'modules/rdf')
-rw-r--r--modules/rdf/rdf.module88
1 files changed, 35 insertions, 53 deletions
diff --git a/modules/rdf/rdf.module b/modules/rdf/rdf.module
index 31f3e2821..59dc541f9 100644
--- a/modules/rdf/rdf.module
+++ b/modules/rdf/rdf.module
@@ -477,45 +477,46 @@ function rdf_preprocess_user_profile(&$variables) {
function rdf_preprocess_username(&$variables) {
// $variables['account'] is a pseudo account object, and as such, does not
// contain the rdf mappings for the user; in the case of nodes and comments,
- // it contains the mappings for the node or comment object instead. Therefore,
- // the real account object for the user is needed. The real account object is
- // needed for this function only; it should not replace $variables['account'].
- if ($account = user_load($variables['uid'])) {
- // An RDF resource for the user is created with the 'about' attribute and
- // the profile URI is used to identify this resource. Even if the user
- // profile is not accessible, we generate its URI regardless in order to
- // be able to identify the user in RDF. We do not use this attribute for
- // the anonymous user because we do not have a user profile URI for it (only
- // a homepage which cannot be used as user profile in RDF).
- if ($account->uid > 0) {
- $variables['attributes_array']['about'] = url('user/' . $account->uid);
- }
-
- // The remaining attributes are defined by RDFa as lists
- // (http://www.w3.org/TR/rdfa-syntax/#rdfa-attributes). Therefore, merge
- // rather than override, so as not to clobber values set by earlier
- // preprocess functions.
- $attributes = array();
+ // it contains the mappings for the node or comment object instead. However
+ // while the rdf mappings are available from a full user_load(), this should
+ // be avoided for performance reasons. Since the type and bundle for
+ // users is already known, call rdf_mapping_load() directly.
+ $rdf_mapping = rdf_mapping_load('user', 'user');
+
+ // An RDF resource for the user is created with the 'about' attribute and
+ // the profile URI is used to identify this resource. Even if the user
+ // profile is not accessible, we generate its URI regardless in order to
+ // be able to identify the user in RDF. We do not use this attribute for
+ // the anonymous user because we do not have a user profile URI for it (only
+ // a homepage which cannot be used as user profile in RDF).
+ if ($variables['uid'] > 0) {
+ $variables['attributes_array']['about'] = url('user/' . $variables['uid']);
+ }
- // The 'typeof' attribute specifies the RDF type(s) of this resource. They
- // are defined in the 'rdftype' property of the user object RDF mapping.
- if (!empty($account->rdf_mapping['rdftype'])) {
- $attributes['typeof'] = $account->rdf_mapping['rdftype'];
- }
+ // The remaining attributes are defined by RDFa as lists
+ // (http://www.w3.org/TR/rdfa-syntax/#rdfa-attributes). Therefore, merge
+ // rather than override, so as not to clobber values set by earlier
+ // preprocess functions.
+ $attributes = array();
- // Annotate the user name in RDFa. The attribute 'property' is used here
- // because the user name is a literal.
- if (!empty($account->rdf_mapping['name'])) {
- $attributes['property'] = $account->rdf_mapping['name']['predicates'];
- }
+ // The 'typeof' attribute specifies the RDF type(s) of this resource. They
+ // are defined in the 'rdftype' property of the user RDF mapping.
+ if (!empty($rdf_mapping['rdftype'])) {
+ $attributes['typeof'] = $rdf_mapping['rdftype'];
+ }
- // Add the homepage RDFa markup if present.
- if (!empty($variables['homepage']) && !empty($account->rdf_mapping['homepage'])) {
- $attributes['rel'] = $account->rdf_mapping['homepage']['predicates'];
- }
+ // Annotate the user name in RDFa. The attribute 'property' is used here
+ // because the user name is a literal.
+ if (!empty($rdf_mapping['name'])) {
+ $attributes['property'] = $rdf_mapping['name']['predicates'];
+ }
- $variables['attributes_array'] = array_merge_recursive($variables['attributes_array'], $attributes);
+ // Add the homepage RDFa markup if present.
+ if (!empty($variables['homepage']) && !empty($rdf_mapping['homepage'])) {
+ $attributes['rel'] = $rdf_mapping['homepage']['predicates'];
}
+
+ $variables['attributes_array'] = array_merge_recursive($variables['attributes_array'], $attributes);
}
/**
@@ -595,25 +596,6 @@ function rdf_field_attach_view_alter(&$output, $context) {
}
/**
- * Implements hook_entity_prepare_view().
- */
-function rdf_entity_prepare_view($entities, $entity_type) {
- $uids = array();
- // In the case of both nodes and comments, the full $account object for the
- // author is needed in rdf_preprocess_username(), however this is not
- // available from node_load() or comment_load(). If the users are loaded
- // for the first time in rdf_preprocess_username() this will issue an
- // individual user_load() for each account, so pre-load the users needed
- // here where we can take advantage of user_load_multiple().
- if ($entity_type == 'node' || $entity_type == 'comment') {
- foreach ($entities as $entity) {
- $uids[$entity->uid] = $entity->uid;
- }
- user_load_multiple($uids);
- }
-}
-
-/**
* Wraps a template variable in an HTML element with the desired attributes.
*
* This is called by rdf_process() shortly before the theme system renders