diff --git a/core/includes/database.inc b/core/includes/database.inc index dc878ed..c8e4725 100644 --- a/core/includes/database.inc +++ b/core/includes/database.inc @@ -37,12 +37,12 @@ * For example, one might wish to return a list of the most recent 10 nodes * authored by a given user. Instead of directly issuing the SQL query * @code - * SELECT n.nid, n.title, n.created FROM node n WHERE n.uid = $uid LIMIT 0, 10; + * SELECT e.id, e.title, e.created FROM example e WHERE e.uid = $uid LIMIT 0, 10; * @endcode * one would instead call the Drupal functions: * @code - * $result = db_query_range('SELECT npd.nid, npd.title, n.created - * FROM {node_property_data} npd WHERE npd.uid = :uid', 0, 10, array(':uid' => $uid)); + * $result = db_query_range('SELECT e.id, e.title, e.created + * FROM {example} e WHERE e.uid = :uid', 0, 10, array(':uid' => $uid)); * foreach ($result as $record) { * // Perform operations on $record->title, etc. here. * } @@ -69,7 +69,7 @@ * * Named placeholders begin with a colon followed by a unique string. Example: * @code - * SELECT nid, title FROM {node_property_data} WHERE uid=:uid; + * SELECT id, title FROM {example} WHERE uid=:uid; * @endcode * * ":uid" is a placeholder that will be replaced with a literal value when @@ -81,7 +81,7 @@ * * Unnamed placeholders are simply a question mark. Example: * @code - * SELECT nid, title FROM {node_property_data} WHERE uid=?; + * SELECT id, title FROM {example} WHERE uid=?; * @endcode * * In this case, the array of arguments must be an indexed array of values to @@ -91,11 +91,11 @@ * running a LIKE query the SQL wildcard character, %, should be part of the * value, not the query itself. Thus, the following is incorrect: * @code - * SELECT nid, title FROM {node_property_data} WHERE title LIKE :title%; + * SELECT id, title FROM {example} WHERE title LIKE :title%; * @endcode * It should instead read: * @code - * SELECT nid, title FROM {node_property_data} WHERE title LIKE :title; + * SELECT id, title FROM {example} WHERE title LIKE :title; * @endcode * and the value for :title should include a % as appropriate. Again, note the * lack of quotation marks around :title. Because the value is not inserted @@ -109,7 +109,7 @@ * object-oriented API for defining a query structurally. For example, rather * than: * @code - * INSERT INTO node (nid, title, body) VALUES (1, 'my title', 'my body'); + * INSERT INTO example (id, title, body) VALUES (1, 'my title', 'my body'); * @endcode * one would instead write: * @code @@ -378,7 +378,7 @@ function db_truncate($table, array $options = array()) { * @param $options * An array of options to control how the query operates. * - * @return SelectQuery + * @return \Drupal\Core\Database\Query\SelectInterface * A new SelectQuery object for this connection. */ function db_select($table, $alias = NULL, array $options = array()) { diff --git a/core/includes/form.inc b/core/includes/form.inc index d74dcf7..2324918 100644 --- a/core/includes/form.inc +++ b/core/includes/form.inc @@ -4693,26 +4693,25 @@ function _form_set_class(&$element, $class = array()) { * $context['message'] = check_plain($node->label()); * } * - * // More advanced example: multi-step operation - load all nodes, five by five + * // More advanced example: multi-step operation - load all rows, five by five * function my_function_2(&$context) { * if (empty($context['sandbox'])) { * $context['sandbox']['progress'] = 0; - * $context['sandbox']['current_node'] = 0; - * $context['sandbox']['max'] = db_query('SELECT COUNT(DISTINCT nid) FROM {node}')->fetchField(); + * $context['sandbox']['current_id'] = 0; + * $context['sandbox']['max'] = db_query('SELECT COUNT(DISTINCT id) FROM {example}')->fetchField(); * } * $limit = 5; - * $result = db_select('node') - * ->fields('node', array('nid')) - * ->condition('nid', $context['sandbox']['current_node'], '>') - * ->orderBy('nid') + * $result = db_select('example') + * ->fields('example', array('id')) + * ->condition('id', $context['sandbox']['current_id'], '>') + * ->orderBy('id') * ->range(0, $limit) * ->execute(); * foreach ($result as $row) { - * $node = node_load($row->nid, TRUE); - * $context['results'][] = $node->nid . ' : ' . check_plain($node->label()); + * $context['results'][] = $row->id . ' : ' . check_plain($row->title); * $context['sandbox']['progress']++; - * $context['sandbox']['current_node'] = $node->nid; - * $context['message'] = check_plain($node->label()); + * $context['sandbox']['current_id'] = $row->id; + * $context['message'] = check_plain($row->title); * } * if ($context['sandbox']['progress'] != $context['sandbox']['max']) { * $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max']; diff --git a/core/lib/Drupal/Core/Database/Driver/pgsql/Select.php b/core/lib/Drupal/Core/Database/Driver/pgsql/Select.php index 7a73269..d5509a6 100644 --- a/core/lib/Drupal/Core/Database/Driver/pgsql/Select.php +++ b/core/lib/Drupal/Core/Database/Driver/pgsql/Select.php @@ -32,11 +32,11 @@ public function orderRandom() { * yet selected. * * @code - * $query = db_select('node', 'n'); - * $query->join('node_property_revision', 'nr', 'n.vid = npr.vid'); + * $query = db_select('example', 'e'); + * $query->join('example_revision', 'er', 'e.vid = er.vid'); * $query * ->distinct() - * ->fields('n') + * ->fields('e') * ->orderBy('timestamp'); * @endcode * diff --git a/core/lib/Drupal/Core/Database/Query/SelectInterface.php b/core/lib/Drupal/Core/Database/Query/SelectInterface.php index 779e69d..7dc62b0 100644 --- a/core/lib/Drupal/Core/Database/Query/SelectInterface.php +++ b/core/lib/Drupal/Core/Database/Query/SelectInterface.php @@ -142,7 +142,7 @@ public function getArguments(PlaceholderInterface $queryPlaceholder = NULL); * * @param $distinct * TRUE to flag this query DISTINCT, FALSE to disable it. - * @return SelectQueryInterface + * @return \Drupal\Core\Database\Query\SelectInterface * The called object. */ public function distinct($distinct = TRUE); @@ -184,7 +184,7 @@ public function addField($table_alias, $field, $alias = NULL); * An indexed array of fields present in the specified table that should be * included in this query. If not specified, $table_alias.* will be generated * without any aliases. - * @return Drupal\Core\Database\Query\SelectInterface + * @return \Drupal\Core\Database\Query\SelectInterface * The called object. */ public function fields($table_alias, array $fields = array()); diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Tests/AggregatorTestBase.php b/core/modules/aggregator/lib/Drupal/aggregator/Tests/AggregatorTestBase.php index 02b9bce..003d99c 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Tests/AggregatorTestBase.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Tests/AggregatorTestBase.php @@ -96,7 +96,7 @@ function getFeedEditArray($feed_url = NULL) { */ function getDefaultFeedItemCount() { // Our tests are based off of rss.xml, so let's find out how many elements should be related. - $feed_count = db_query_range('SELECT COUNT(*) FROM {node_property_data} npd WHERE npd.promote = 1 AND npd.status = 1', 0, config('system.rss')->get('items.limit'))->fetchField(); + $feed_count = db_query_range('SELECT COUNT(DISTINCT nid) FROM {node_property_data} npd WHERE npd.promote = 1 AND npd.status = 1', 0, config('system.rss')->get('items.limit'))->fetchField(); return $feed_count > 10 ? 10 : $feed_count; } diff --git a/core/modules/book/book.module b/core/modules/book/book.module index 9c44bdd..3bdebcb 100644 --- a/core/modules/book/book.module +++ b/core/modules/book/book.module @@ -312,13 +312,13 @@ function book_block_view($delta = '') { } elseif ($current_bid) { // Only display this block when the user is browsing a book. - $select = db_select('node_property_data', 'npd') - ->fields('npd', array('title')) - ->condition('npd.nid', $node->book['bid']) + $select = db_select('node', 'n') + ->fields('n', array('nid')) + ->condition('n.nid', $node->book['bid']) ->addTag('node_access'); - $title = $select->execute()->fetchField(); + $nid = $select->execute()->fetchField(); // Only show the block if the user has view access for the top-level node. - if ($title) { + if ($nid) { $tree = menu_tree_all_data($node->book['menu_name'], $node->book); // There should only be one element at the top level. $data = array_shift($tree); @@ -397,7 +397,6 @@ function book_get_books() { $query->join('node_property_data', 'npd', 'n.nid = npd.nid'); $query->join('menu_links', 'ml', 'b.mlid = ml.mlid'); $query->addField('n', 'type', 'type'); - $query->addField('npd', 'title', 'title'); $query->fields('b'); $query->fields('ml'); $query->condition('npd.nid', $nids, 'IN'); @@ -407,9 +406,10 @@ function book_get_books() { $query->addTag('node_access'); $result2 = $query->execute(); foreach ($result2 as $link) { + $node = node_load($link['nid']); $link['href'] = $link['link_path']; $link['options'] = unserialize($link['options']); - $all_books[$link['bid']] = $link; + $all_books[$link['bid']] = $node->label(); } } } diff --git a/core/modules/comment/comment.admin.inc b/core/modules/comment/comment.admin.inc index 82df8d6..d66a79b 100644 --- a/core/modules/comment/comment.admin.inc +++ b/core/modules/comment/comment.admin.inc @@ -83,10 +83,9 @@ function comment_admin_overview($form, &$form_state, $arg) { ->extend('Drupal\Core\Database\Query\PagerSelectExtender') ->extend('Drupal\Core\Database\Query\TableSortExtender'); $query->join('node_property_data', 'npd', 'npd.nid = c.nid'); - $query->addField('npd', 'title', 'node_title'); $query->addTag('node_access'); $result = $query - ->fields('c', array('cid', 'subject', 'name', 'changed')) + ->fields('c', array('cid', 'nid', 'subject', 'name', 'changed')) ->condition('c.status', $status) ->limit(50) ->orderByHeader($header) @@ -97,8 +96,9 @@ function comment_admin_overview($form, &$form_state, $arg) { // We collect a sorted list of node_titles during the query to attach to the // comments later. foreach ($result as $row) { + $node = node_load($row->nid); $cids[] = $row->cid; - $node_titles[] = $row->node_title; + $node_titles[] = $node->label(); } $comments = comment_load_multiple($cids); diff --git a/core/modules/comment/comment.install b/core/modules/comment/comment.install index 30bca60..f8eddc5 100644 --- a/core/modules/comment/comment.install +++ b/core/modules/comment/comment.install @@ -42,6 +42,7 @@ function comment_enable() { $query->addExpression('0', 'comment_count'); $query->addExpression('NULL', 'last_comment_name'); $query->isNull('ncs.comment_count'); + $query->groupBy('npd', 'nid'); db_insert('node_comment_statistics') ->from($query) diff --git a/core/modules/comment/lib/Drupal/comment/CommentStorageController.php b/core/modules/comment/lib/Drupal/comment/CommentStorageController.php index 6427378..6b50964 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentStorageController.php +++ b/core/modules/comment/lib/Drupal/comment/CommentStorageController.php @@ -223,7 +223,7 @@ protected function updateNodeStatistics($nid) { } else { // Comments do not exist. - $node = db_query('SELECT uid, created FROM {node_property_data} WHERE nid = :nid', array(':nid' => $nid))->fetchObject(); + $node = db_query('SELECT uid, created FROM {node_property_data} WHERE nid = :nid LIMIT 1', array(':nid' => $nid))->fetchObject(); db_update('node_comment_statistics') ->fields(array( 'cid' => 0, diff --git a/core/modules/forum/forum.module b/core/modules/forum/forum.module index eac73a7..e3e3454 100644 --- a/core/modules/forum/forum.module +++ b/core/modules/forum/forum.module @@ -809,6 +809,7 @@ function forum_forum_load($tid = NULL) { $query->join('forum', 'f', 'npd.vid = f.vid'); $query->addExpression('COUNT(npd.nid)', 'topic_count'); $query->addExpression('SUM(ncs.comment_count)', 'comment_count'); + $query->groupBy('npd', 'nid'); $counts = $query ->fields('f', array('tid')) ->condition('npd.status', 1) @@ -976,7 +977,8 @@ function forum_get_topics($tid, $sortby, $forum_per_page) { $query ->orderBy('f.sticky', 'DESC') ->orderByHeader($forum_topic_list_header) - ->condition('npd.nid', $nids); + ->condition('npd.nid', $nids) + ->groupBy('npd', 'nid'); $result = array(); foreach ($query->execute() as $row) { @@ -1384,7 +1386,7 @@ function _forum_update_forum_index($nid) { } else { // Comments do not exist. - $node = db_query('SELECT uid, created FROM {node_property_data} WHERE nid = :nid', array(':nid' => $nid))->fetchObject(); + $node = db_query('SELECT uid, created FROM {node_property_data} WHERE nid = :nid LIMIT 1', array(':nid' => $nid))->fetchObject(); db_update('forum_index') ->fields( array( 'comment_count' => 0, diff --git a/core/modules/language/language.api.php b/core/modules/language/language.api.php index 6f19835..2ec0c4c 100644 --- a/core/modules/language/language.api.php +++ b/core/modules/language/language.api.php @@ -52,8 +52,8 @@ function hook_language_update($language) { function hook_language_delete($language) { // On nodes with this language, unset the language db_update('node') - ->fields(array('language' => '')) - ->condition('language', $language->langcode) + ->fields(array('langcode' => '')) + ->condition('langcode', $language->langcode) ->execute(); } diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeAdminTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeAdminTest.php index 85fdae1..de68f7e 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeAdminTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeAdminTest.php @@ -44,6 +44,7 @@ function testContentAdminSort() { // Test that the default sort by node.changed DESC actually fires properly. $nodes_query = db_select('node_property_data', 'npd') + ->distinct(TRUE) ->fields('npd', array('nid')) ->orderBy('changed', 'DESC') ->execute() @@ -59,6 +60,7 @@ function testContentAdminSort() { // Compare the rendered HTML node list to a query for the nodes ordered by // title to account for possible database-dependent sort order. $nodes_query = db_select('node_property_data', 'npd') + ->distinct(TRUE) ->fields('npd', array('nid')) ->orderBy('title') ->execute() diff --git a/core/modules/node/node.admin.inc b/core/modules/node/node.admin.inc index 50816cc..10ab62d 100644 --- a/core/modules/node/node.admin.inc +++ b/core/modules/node/node.admin.inc @@ -495,10 +495,11 @@ function node_admin_nodes() { } $header['operations'] = array('data' => t('Operations')); - $query = db_select('node_property_data', 'npd') + $query = db_select('node', 'n') + ->distinct(TRUE) ->extend('Drupal\Core\Database\Query\PagerSelectExtender') ->extend('Drupal\Core\Database\Query\TableSortExtender'); - $query->innerJoin('node', 'n', 'n.nid = npd.nid'); + $query->innerJoin('node_property_data', 'npd', 'npd.nid = n.nid'); node_build_filter_query($query); if (!user_access('bypass node access')) { @@ -682,14 +683,14 @@ function node_admin_nodes_submit($form, &$form_state) { */ function node_multiple_delete_confirm($form, &$form_state, $nodes) { $form['nodes'] = array('#prefix' => '', '#tree' => TRUE); + $node_entities = node_load_multiple(array_keys($nodes)); // array_filter returns only elements with TRUE values foreach ($nodes as $nid => $value) { - $title = db_query('SELECT title FROM {node_property_data} WHERE nid = :nid', array(':nid' => $nid))->fetchField(); $form['nodes'][$nid] = array( '#type' => 'hidden', '#value' => $nid, '#prefix' => '
  • ', - '#suffix' => check_plain($title) . "
  • \n", + '#suffix' => check_plain($node_entities[$nid]->label()) . "\n", ); } $form['operation'] = array('#type' => 'hidden', '#value' => 'delete'); diff --git a/core/modules/node/node.module b/core/modules/node/node.module index d04e85c..11518c3 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -1700,6 +1700,7 @@ function node_user_cancel($edit, $account, $method) { // Unpublish nodes (current revisions). module_load_include('inc', 'node', 'node.admin'); $nodes = db_select('node_property_data', 'npd') + ->distinct(TRUE) ->fields('npd', array('nid')) ->condition('uid', $account->uid) ->execute() @@ -1711,6 +1712,7 @@ function node_user_cancel($edit, $account, $method) { // Anonymize nodes (current revisions). module_load_include('inc', 'node', 'node.admin'); $nodes = db_select('node_property_data', 'npd') + ->distinct(TRUE) ->fields('npd', array('nid')) ->condition('uid', $account->uid) ->execute() @@ -1736,6 +1738,7 @@ function node_user_predelete($account) { // Delete nodes (current revisions). // @todo Introduce node_mass_delete() or make node_mass_update() more flexible. $nodes = db_select('node_property_data', 'npd') + ->distinct(TRUE) ->fields('npd', array('nid')) ->condition('uid', $account->uid) ->execute() @@ -2112,7 +2115,7 @@ function node_page_title(Node $node) { * A unix timestamp indicating the last time the node was changed. */ function node_last_changed($nid) { - return db_query('SELECT changed FROM {node_property_data} WHERE nid = :nid', array(':nid' => $nid))->fetch()->changed; + return db_query('SELECT changed FROM {node_property_data} WHERE nid = :nid ORDER BY changed DESC LIMIT 1', array(':nid' => $nid))->fetch()->changed; } /** @@ -2231,7 +2234,7 @@ function node_get_recent($number = 10) { // If the user is able to view their own unpublished nodes, allow them // to see these in addition to published nodes. Check that they actually // have some unpublished nodes to view before adding the condition. - if (user_access('view own unpublished content') && $own_unpublished = db_query('SELECT nid FROM {node_property_data} WHERE uid = :uid AND status = :status', array(':uid' => $GLOBALS['user']->uid, ':status' => NODE_NOT_PUBLISHED))->fetchCol()) { + if (user_access('view own unpublished content') && $own_unpublished = db_query('SELECT DISTINCT nid FROM {node_property_data} WHERE uid = :uid AND status = :status', array(':uid' => $GLOBALS['user']->uid, ':status' => NODE_NOT_PUBLISHED))->fetchCol()) { $query->condition(db_or() ->condition('npd.status', NODE_PUBLISHED) ->condition('npd.nid', $own_unpublished, 'IN') @@ -2501,6 +2504,7 @@ function node_feed($nids = FALSE, $channel = array()) { ->condition('npd.promote', 1) ->condition('npd.status', 1) ->orderBy('npd.created', 'DESC') + ->groupBy('npd.nid') ->range(0, $rss_config->get('items.limit')) ->addTag('node_access') ->execute() @@ -2606,6 +2610,7 @@ function node_page_default() { ->condition('npd.status', 1) ->orderBy('npd.sticky', 'DESC') ->orderBy('npd.created', 'DESC') + ->groupBy('npd.nid') ->extend('Drupal\Core\Database\Query\PagerSelectExtender') ->limit(variable_get('default_nodes_main', 10)) ->addTag('node_access'); diff --git a/core/modules/poll/poll.module b/core/modules/poll/poll.module index 2f060da..0ac65ee 100644 --- a/core/modules/poll/poll.module +++ b/core/modules/poll/poll.module @@ -140,6 +140,7 @@ function poll_block_view($delta = '') { $select = db_select('node_property_data', 'npd'); $select->join('poll', 'p', 'p.nid = npd.nid'); $select->fields('npd', array('nid')) + ->distinct(TRUE) ->condition('npd.status', 1) ->condition('p.active', 1) ->orderBy('npd.created', 'DESC') diff --git a/core/modules/poll/poll.pages.inc b/core/modules/poll/poll.pages.inc index 53c9778..365a4a6 100644 --- a/core/modules/poll/poll.pages.inc +++ b/core/modules/poll/poll.pages.inc @@ -20,6 +20,7 @@ function poll_page() { $count_select->addExpression('COUNT(*)', 'expression'); $count_select->join('poll', 'p', 'p.nid = npd.nid'); $count_select->condition('npd.status', 1); + $count_select->groupBy('npd.nid'); // List all polls. $select = db_select('node_property_data', 'npd'); @@ -31,7 +32,6 @@ function poll_page() { ->condition('npd.status', 1) ->orderBy('npd.created', 'DESC') ->groupBy('npd.nid') - ->groupBy('npd.title') ->groupBy('p.active') ->groupBy('npd.created') ->extend('Drupal\Core\Database\Query\PagerSelectExtender') @@ -44,7 +44,8 @@ function poll_page() { $output = ''; $output .= theme('pager'); diff --git a/core/modules/search/search.api.php b/core/modules/search/search.api.php index 263be71..160e177 100644 --- a/core/modules/search/search.api.php +++ b/core/modules/search/search.api.php @@ -117,8 +117,8 @@ function hook_search_reset() { * @ingroup search */ function hook_search_status() { - $total = db_query('SELECT COUNT(*) FROM {node_property_data} WHERE status = 1')->fetchField(); - $remaining = db_query("SELECT COUNT(*) FROM {node_property_data} npd LEFT JOIN {search_dataset} d ON d.type = 'node' AND d.sid = npd.nid WHERE npd.status = 1 AND d.sid IS NULL OR d.reindex <> 0")->fetchField(); + $total = db_query('SELECT COUNT(*) FROM {example} WHERE status = 1')->fetchField(); + $remaining = db_query("SELECT COUNT(*) FROM {example} e LEFT JOIN {search_dataset} d ON d.type = 'example' AND d.sid = e.id WHERE e.status = 1 AND d.sid IS NULL OR d.reindex <> 0")->fetchField(); return array('remaining' => $remaining, 'total' => $total); } @@ -198,18 +198,17 @@ function hook_search_execute($keys = NULL, $conditions = NULL) { $query = db_select('search_index', 'i', array('target' => 'slave')) ->extend('Drupal\search\SearchQuery') ->extend('Drupal\Core\Database\Query\PagerSelectExtender'); - $query->join('node_property_data', 'npd', 'npd.nid = i.sid'); - $query->join('node', 'n', 'n.nid = npd.nid'); + $query->join('example', 'e', 'e.id = i.sid'); $query - ->condition('npd.status', 1) - ->addTag('node_access') - ->searchExpression($keys, 'node'); + ->condition('e.status', 1) + ->addTag('example_access') + ->searchExpression($keys, 'example'); // Insert special keywords. - $query->setOption('type', 'n.type'); - $query->setOption('langcode', 'npd.langcode'); + $query->setOption('type', 'e.type'); + $query->setOption('langcode', 'e.langcode'); if ($query->setOption('term', 'ti.tid')) { - $query->join('taxonomy_index', 'ti', 'npd.nid = ti.nid'); + $query->join('taxonomy_index', 'ti', 'e.id = ti.id'); } // Only continue if the first pass query matches. if (!$query->executeFirstPass()) { @@ -226,29 +225,29 @@ function hook_search_execute($keys = NULL, $conditions = NULL) { $results = array(); foreach ($find as $item) { // Render the node. - $node = node_load($item->sid); - $build = node_view($node, 'search_result', $item->langcode); + $example = example_load($item->sid); + $build = example_view($example, 'search_result', $item->langcode); unset($build['#theme']); - $node->rendered = drupal_render($build); + $example->rendered = drupal_render($build); // Fetch comments for snippet. - $node->rendered .= ' ' . module_invoke('comment', 'node_update_index', $node, $item->langcode); + $example->rendered .= ' ' . module_invoke('comment', 'node_update_index', $example, $item->langcode); - $extra = module_invoke_all('node_search_result', $node, $item->langcode); + $extra = module_invoke_all('node_search_result', $example, $item->langcode); $language = language_load($item->langcode); - $uri = $node->uri(); + $uri = $example->uri(); $results[] = array( 'link' => url($uri['path'], array_merge($uri['options'], array('absolute' => TRUE, 'language' => $language))), - 'type' => check_plain(node_get_type_label($node)), - 'title' => $node->label($item->langcode), - 'user' => theme('username', array('account' => $node)), - 'date' => $node->get('changed', $item->langcode), - 'node' => $node, + 'type' => check_plain(node_get_type_label($example)), + 'title' => $example->label($item->langcode), + 'user' => theme('username', array('account' => $example)), + 'date' => $example->get('changed', $item->langcode), + 'node' => $example, 'extra' => $extra, 'score' => $item->calculated_score, - 'snippet' => search_excerpt($keys, $node->rendered, $item->langcode), - 'langcode' => $node->langcode, + 'snippet' => search_excerpt($keys, $example->rendered, $item->langcode), + 'langcode' => $example->langcode, ); } return $results; diff --git a/core/modules/search/search.module b/core/modules/search/search.module index a122fcc..5747283 100644 --- a/core/modules/search/search.module +++ b/core/modules/search/search.module @@ -647,10 +647,9 @@ function search_index($sid, $module, $text, $langcode) { if (preg_match('!(?:node|book)/(?:view/)?([0-9]+)!i', $path, $match)) { $linknid = $match[1]; if ($linknid > 0) { - $node = db_query('SELECT title, nid, vid FROM {node_property_data} WHERE nid = :nid', array(':nid' => $linknid), array('target' => 'slave'))->fetchObject(); $link = TRUE; - // Do not use $node->label(), $node comes from the database. - $linktitle = $node->title; + $node = node_load($linknid); + $linktitle = $node->label(); } } } diff --git a/core/modules/statistics/statistics.module b/core/modules/statistics/statistics.module index cef0314..f653fb3 100644 --- a/core/modules/statistics/statistics.module +++ b/core/modules/statistics/statistics.module @@ -274,6 +274,7 @@ function statistics_title_list($dbfield, $dbrows) { ->condition($dbfield, 0, '<>') ->condition('npd.status', 1) ->orderBy($dbfield, 'DESC') + ->groupBy('npd.nid') ->range(0, $dbrows) ->execute(); } diff --git a/core/modules/tracker/tracker.module b/core/modules/tracker/tracker.module index 11b9634..8ecbb1e 100644 --- a/core/modules/tracker/tracker.module +++ b/core/modules/tracker/tracker.module @@ -83,7 +83,7 @@ function tracker_cron() { $batch_size = config('tracker.settings')->get('cron_index_limit'); if ($max_nid > 0) { $last_nid = FALSE; - $result = db_query_range('SELECT nid, uid, status FROM {node_property_data} WHERE nid <= :max_nid ORDER BY nid DESC', 0, $batch_size, array(':max_nid' => $max_nid), array('target' => 'slave')); + $result = db_query_range('SELECT nid, uid, status FROM {node_property_data} WHERE nid <= :max_nid GROUP BY nid ORDER BY nid DESC', 0, $batch_size, array(':max_nid' => $max_nid), array('target' => 'slave')); $count = 0; @@ -268,7 +268,7 @@ function tracker_comment_delete($comment) { * The node updated timestamp or comment timestamp. */ function _tracker_add($nid, $uid, $changed) { - $node = db_query('SELECT nid, status, uid, changed FROM {node_property_data} WHERE nid = :nid', array(':nid' => $nid))->fetchObject(); + $node = db_query('SELECT nid, status, uid, changed FROM {node_property_data} WHERE nid = :nid ORDER BY changed DESC, status DESC LIMIT 1', array(':nid' => $nid))->fetchObject(); // Adding a comment can only increase the changed timestamp, so our // calculation here is simple. @@ -307,7 +307,7 @@ function _tracker_add($nid, $uid, $changed) { * is the greatest. */ function _tracker_calculate_changed($nid) { - $changed = db_query('SELECT changed FROM {node_property_data} WHERE nid = :nid', array(':nid' => $nid), array('target' => 'slave'))->fetchField(); + $changed = db_query('SELECT changed FROM {node_property_data} WHERE nid = :nid ORDER BY changed DESC LIMIT 1', array(':nid' => $nid), array('target' => 'slave'))->fetchField(); $latest_comment = db_query_range('SELECT cid, changed FROM {comment} WHERE nid = :nid AND status = :status ORDER BY changed DESC', 0, 1, array( ':nid' => $nid, ':status' => COMMENT_PUBLISHED, @@ -329,7 +329,7 @@ function _tracker_calculate_changed($nid) { * The last changed timestamp of the node. */ function _tracker_remove($nid, $uid = NULL, $changed = NULL) { - $node = db_query('SELECT nid, status, uid, changed FROM {node_property_data} WHERE nid = :nid', array(':nid' => $nid))->fetchObject(); + $node = db_query('SELECT nid, status, uid, changed FROM {node_property_data} WHERE nid = :nid ORDER BY changed DESC, status DESC LIMIT 1', array(':nid' => $nid))->fetchObject(); // The user only keeps his or her subscription if both of the following are true: // (1) The node exists. diff --git a/core/modules/tracker/tracker.pages.inc b/core/modules/tracker/tracker.pages.inc index c69b7e5..09583b3 100644 --- a/core/modules/tracker/tracker.pages.inc +++ b/core/modules/tracker/tracker.pages.inc @@ -55,11 +55,15 @@ function tracker_page($account = NULL, $set_title = FALSE) { 'INNER JOIN {node} n ON n.nid = npd.nid ' . 'INNER JOIN {node_comment_statistics} l ON npd.nid = l.nid ' . 'INNER JOIN {users} u ON npd.uid = u.uid ' . - 'WHERE npd.nid IN (:nids)', + 'WHERE npd.nid IN (:nids) ' . + 'ORDER BY npd.changed DESC ' . + 'GROUP BY npd.nid', array(':nids' => array_keys($nodes)), array('target' => 'slave') ); + $node_entities = node_load_multiple(array_keys($nodes)); foreach ($result as $node) { $node->last_activity = $nodes[$node->nid]->changed; + $node->title = $node_entities[$node->nid]->label(); $nodes[$node->nid] = $node; } diff --git a/core/modules/translation/translation.module b/core/modules/translation/translation.module index 9f9ad28..1dc38ce 100644 --- a/core/modules/translation/translation.module +++ b/core/modules/translation/translation.module @@ -487,7 +487,7 @@ function translation_node_get_translations($tnid) { if (!isset($translations[$tnid])) { $translations[$tnid] = array(); $query = db_select('node_property_data', 'npd'); - $query->innerJoin('node', 'n', 'n.nid = npd.nid'); + $query->innerJoin('node', 'n', 'n.nid = npd.nid AND n.langcode = npd.langcode'); $query->fields('npd', array('nid', 'uid', 'status', 'title', 'langcode')) ->fields('n', array('type')) ->condition('n.tnid', $tnid)