From 77bea499997e11a64fe624fc1d5565d1dc54702a Mon Sep 17 00:00:00 2001 From: Alex Barth <alex_b@53995.no-reply.drupal.org> Date: Mon, 6 Dec 2010 20:57:00 +0000 Subject: [PATCH] Faster lookup of terms. --- mappers/taxonomy.inc | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/mappers/taxonomy.inc b/mappers/taxonomy.inc index c6c17eeb..1b5e1d94 100644 --- a/mappers/taxonomy.inc +++ b/mappers/taxonomy.inc @@ -120,14 +120,25 @@ function taxonomy_feeds_set_target($source, $entity, $target, $terms) { */ function taxonomy_term_check_term($name, $vid) { $name = trim($name); - $terms = taxonomy_term_load_multiple(array(), array('name' => $name, 'vid' => $vid)); - if (empty($terms)) { + $term = taxonomy_term_lookup_term($name, $vid); + if (empty($term)) { $term = new stdClass(); $term->name = $name; $term->vid = $vid; taxonomy_term_save($term); return $term->tid; } - $term = reset($terms); return $term->tid; } + +/** + * Looks up a term, assumes SQL storage backend. + */ +function taxonomy_term_lookup_term($name, $vid) { + return db_select('taxonomy_term_data', 'td') + ->fields('td', array('tid', 'name')) + ->condition('name', $name) + ->condition('vid', $vid) + ->execute() + ->fetchObject(); +} -- GitLab