diff --git a/core/modules/history/history.module b/core/modules/history/history.module index f42159a..5f35aee 100644 --- a/core/modules/history/history.module +++ b/core/modules/history/history.module @@ -30,7 +30,8 @@ * of when the last view occurred; otherwise, zero. */ function history_read($nid) { - return history_read_multiple(array($nid)); + $history = history_read_multiple(array($nid)); + return $history[$nid]; } /** @@ -69,7 +70,7 @@ function history_read_multiple($nids) { ':nids' => array_keys($nodes_to_read), )); foreach ($result as $row) { - $nodes_to_read[$row->nid] = $row->timestamp; + $nodes_to_read[$row->nid] = (int)$row->timestamp; } $history += $nodes_to_read; @@ -100,7 +101,10 @@ function history_write($nid, $account = NULL) { )) ->fields(array('timestamp' => REQUEST_TIME)) ->execute(); - } + // Update static cache. + $history = &drupal_static('history_read', array()); + $history[$nid] = REQUEST_TIME; + } } /** diff --git a/core/modules/history/lib/Drupal/history/Controller/HistoryController.php b/core/modules/history/lib/Drupal/history/Controller/HistoryController.php index 86c4aa0..b605e6e 100644 --- a/core/modules/history/lib/Drupal/history/Controller/HistoryController.php +++ b/core/modules/history/lib/Drupal/history/Controller/HistoryController.php @@ -37,12 +37,7 @@ public function getNodeReadTimestamps(Request $request) { if (!isset($nids)) { throw new NotFoundHttpException(); } - - $timestamps = array(); - foreach ($nids as $nid) { - $timestamps[$nid] = (int) history_read($nid); - } - return new JsonResponse($timestamps); + return new JsonResponse(history_read_multiple($nids)); } /**