Which Drupal function inserts the data in the history table? So as far as I've seen, the history table holds timestamps when users viewed nodes.

Which Drupal function insert the data in that database table? The most logical place for me would be in statistics_exit(), where the accesslog table is being populated, but it's not there. The only place I've seen something similar is in node_tag_new(), but I am not sure if that's the right one.

Can anyone shed some light into this?
It is node_tag_new(), the function that is part of the Node module (line 299 of that file in Drupal 7).

/**
 * Updates the 'last viewed' timestamp of the specified node for current user.
 *
 * @param $node
 *   A node object.
 */
function node_tag_new($node) {
  global $user;
  if ($user-&gt;uid) {
    db_merge('history')
      -&gt;key(array(
        'uid' =&gt; $user-&gt;uid,
        'nid' =&gt; $node-&gt;nid,
      ))
      -&gt;fields(array('timestamp' =&gt; REQUEST_TIME))
      -&gt;execute();
   }
}


Here's the same function in Drupal 6.

/**
 * Update the 'last viewed' timestamp of the specified node for current user.
 */
function node_tag_new($nid) {
  global $user;

  if ($user-&gt;uid) {
    if (node_last_viewed($nid)) {
      db_query('UPDATE {history} SET timestamp = %d WHERE uid = %d AND nid = %d', time(), $user-&gt;uid, $nid);
    }
    else {
      @db_query('INSERT INTO {history} (uid, nid, timestamp) VALUES (%d, %d, %d)', $user-&gt;uid, $nid, time());
    }
  }
}


The function is called by node_show(), which uses the following code.

// Update the history table, stating that this user viewed this node.
node_tag_new($node);


As said from that comment, the purpose of the function call is updating the history table to record the fact the current user viewed the node.