0

I am creating a website with Drupal, where users will upload various content. I want to scale Drupal at the rate the site is growing on. I will have more than 45,000 nodes and over 1,000,000 comments on the site.

This is a multi-site installation. I was wondering if I should use the Pathauto module to alias node paths and tags paths or use the following code for taxonomy.

function site_function_term_path($term) {
  $t = taxonomy_get_term($term->tid);
  $term->name = $t->name;
  return 'tags/' . urlencode($term->name);
}

Which is better way to implement this?

2
  • 1
    Pathauto module does not store the path aliases. It just hooks up in different events to alias the entities automatically using the core Path module. – AyeshK Aug 9 '13 at 12:16
  • The above code was pulled from a drupal 6 module I programmed while learning drupal as a computer science student. Everyone has suggested that I use pathauto. My question is, is this the way to go? Seeing that I have over 45,000 nodes and by the end of the year there should be about 50,000 taxonomy terms – don Aug 9 '13 at 13:28
1

Since you still need to generate path aliases for nodes, I would rather use the Pathauto module. The code you show has the following problems:

  • It doesn't work for Drupal 7, since hook_term_path() is not used from Drupal 7
  • It works only when the module handling the vocabulary is not the Taxonomy module, since the hook is invoked from the following function.

    function taxonomy_term_path($term) {
      $vocabulary = taxonomy_vocabulary_load($term->vid);
      if ($vocabulary->module != 'taxonomy' && $path = module_invoke($vocabulary->module, 'term_path', $term)) {
        return $path;
      }
      return 'taxonomy/term/' . $term->tid;
    }
    
  • There should not be the need of calling taxonomy_get_term() since the taxonomy term object is already passed to the hook.

A Drupal 7 solution would be implementing hook_url_inbound_alter() and hook_url_outbound_alter(), for which the equivalent in Drupal 6 are two functions to add to the settings.php file: custom_url_rewrite_inbound() and custom_url_rewrite_outbound().

As for when that hooks/functions should be used instead of using path aliases with the Pathauto module, you can look at What is the difference between implementing hook_url_inbound_alter() and hook_url_outbound_alter(), and using a path alias?

Using hook_url_outbound_alter() has some potential performance issues because it is executed by every single URL on a page via the url() function. This means a module could implement hook_url_outbound_alter() with some complex and slow code that is called 100's of times per page.

Also hook_url_outbound_alter() allows a link's $options, including its query string, to be altered, which is impossible to do to path aliases and a very useful feature. For example, I have altered internal RSS URLs to point to their respective Feedburner and iTunes URLs.

Conceptually, the Path module should be calling the hook_url_*_alter() hooks but it is probably slightly faster to have the drupal_get_path_alias() calls directly in url().

3
  • If I decide to go with pathauto is there any performance implications for having too many nodes and taxonomy terms. Over 45000 nodes and over 55,000 terms. – don Aug 9 '13 at 13:37
  • The only performance issue would be maintaining the path aliases updated, in the case the path alias depends from something that can edited in the node. Suppose the path alias is generated from node/[node:nid]/[node:title]; every time the node title is changed, the Pathauto module will generate a new path alias. At that point the problem would be having a new path alias every time a node is edited, or deleting the old path alias to only have the newer path alias. In both the cases, there are some performance implications. – kiamlaluno Aug 9 '13 at 13:54
  • To make a comparison, the Project module creates a path alias for every project node (project/<project short name>), but the project short name is not editable, once the node is created. – kiamlaluno Aug 9 '13 at 13:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.