What hook to use to update history table What hook can I use to update the history table for my use case?

I am using the answers module. When viewing a question it appends a view of answers by format of view mode. The history table for the question type is updated, but not for the answer type. This has the effect that all comments on the answer are always tagged as new. I added code to the hook_node_view for the question type wherein I get all related answers and update the history table correctly for them. However, hook_node_view runs before hook_comment_view and now all comments do not get a tag at all. I probably need to alter the history table after hook_comment has run. Any suggestions?
You are looking for the node_tag_new() core function.

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();
  }
}


Normally you'd just pass the full node object to the function, but if you only have the nid, you can just pass a dummy object.

$node = new stdClass();
$node-&gt;nide = 1234;
node_tag_new($node);


Modifying the OP's own answer, this would be:

function answers_exit() {
  $router_item  = menu_get_object();
  if (isset($router_item) &amp;&amp; $router_item-&gt;type == "answers_question") {
    if ($user-&gt;uid) {
      $results = db_select('field_data_answers_related_question', 'rq')
        -&gt;fields('rq', array('entity_id'))
        -&gt;condition('answers_related_question_target_id', $router_item-&gt;nid)
        -&gt;execute();
      foreach($results as $row) {
        $node = new stdClass();
        $node-&gt;nid = $row-&gt;entity_id;
        node_tag_new($node);
      }
    }
  }
}


However you should probably be using EntityFieldQuery since it will handle all all the specifics about which tables/columns to use:

function answers_exit() {
  $router_item  = menu_get_object();
  if (isset($router_item) &amp;&amp; $router_item-&gt;type == "answers_question") {
    $query = new EntityFieldQuery();
    $query-&gt;entityCondition('entity_type', 'node')
          -&gt;entityCondition('bundle', 'answers')
          -&gt;fieldCondition('answers_related_question', 'target_id', $router_item-&gt;nid);
    $result = $query-&gt;execute();
    if (isset($result['node'])) {
      foreach ($result['node'] as $answer) {
        node_tag_new($answer);
      }
    }
}