diff --git a/core/modules/action/tests/src/Kernel/Migrate/d6/MigrateActionsTest.php b/core/modules/action/tests/src/Kernel/Migrate/d6/MigrateActionsTest.php
index 7522b2acf4..99d4238e2a 100644
--- a/core/modules/action/tests/src/Kernel/Migrate/d6/MigrateActionsTest.php
+++ b/core/modules/action/tests/src/Kernel/Migrate/d6/MigrateActionsTest.php
@@ -12,7 +12,7 @@
  */
 class MigrateActionsTest extends MigrateDrupal6TestBase {
 
-  protected static $modules = ['action', 'comment', 'node'];
+  protected static $modules = ['action', 'comment', 'history', 'node'];
 
   /**
    * {@inheritdoc}
diff --git a/core/modules/action/tests/src/Kernel/Migrate/d7/MigrateActionsTest.php b/core/modules/action/tests/src/Kernel/Migrate/d7/MigrateActionsTest.php
index 19096ae418..7db6c7077d 100644
--- a/core/modules/action/tests/src/Kernel/Migrate/d7/MigrateActionsTest.php
+++ b/core/modules/action/tests/src/Kernel/Migrate/d7/MigrateActionsTest.php
@@ -12,7 +12,7 @@
  */
 class MigrateActionsTest extends MigrateDrupal7TestBase {
 
-  protected static $modules = ['action', 'comment', 'node'];
+  protected static $modules = ['action', 'comment', 'history', 'node'];
 
   /**
    * {@inheritdoc}
diff --git a/core/modules/block/tests/src/Kernel/BlockConfigSchemaTest.php b/core/modules/block/tests/src/Kernel/BlockConfigSchemaTest.php
index a6a736f5d9..1da76f31e1 100644
--- a/core/modules/block/tests/src/Kernel/BlockConfigSchemaTest.php
+++ b/core/modules/block/tests/src/Kernel/BlockConfigSchemaTest.php
@@ -25,6 +25,7 @@ class BlockConfigSchemaTest extends KernelTestBase {
     'block_content',
     'comment',
     'forum',
+    'history',
     'node',
     'statistics',
     // \Drupal\block\Entity\Block->preSave() calls system_region_list().
diff --git a/core/modules/block/tests/src/Kernel/Migrate/d6/MigrateBlockContentTranslationTest.php b/core/modules/block/tests/src/Kernel/Migrate/d6/MigrateBlockContentTranslationTest.php
index 1801de8780..379fb64a1c 100644
--- a/core/modules/block/tests/src/Kernel/Migrate/d6/MigrateBlockContentTranslationTest.php
+++ b/core/modules/block/tests/src/Kernel/Migrate/d6/MigrateBlockContentTranslationTest.php
@@ -20,6 +20,7 @@ class MigrateBlockContentTranslationTest extends MigrateDrupal6TestBase {
     'block',
     'comment',
     'forum',
+    'history',
     'views',
     'block_content',
     'content_translation',
diff --git a/core/modules/block/tests/src/Kernel/Migrate/d6/MigrateBlockTest.php b/core/modules/block/tests/src/Kernel/Migrate/d6/MigrateBlockTest.php
index f39057308c..f397f10279 100644
--- a/core/modules/block/tests/src/Kernel/Migrate/d6/MigrateBlockTest.php
+++ b/core/modules/block/tests/src/Kernel/Migrate/d6/MigrateBlockTest.php
@@ -26,6 +26,7 @@ class MigrateBlockTest extends MigrateDrupal6TestBase {
     'aggregator',
     'book',
     'forum',
+    'history',
     'path_alias',
     'statistics',
   ];
diff --git a/core/modules/block/tests/src/Kernel/Migrate/d7/MigrateBlockContentTranslationTest.php b/core/modules/block/tests/src/Kernel/Migrate/d7/MigrateBlockContentTranslationTest.php
index 9789b19913..ac118cdb6c 100644
--- a/core/modules/block/tests/src/Kernel/Migrate/d7/MigrateBlockContentTranslationTest.php
+++ b/core/modules/block/tests/src/Kernel/Migrate/d7/MigrateBlockContentTranslationTest.php
@@ -23,6 +23,7 @@ class MigrateBlockContentTranslationTest extends MigrateDrupal7TestBase {
     'comment',
     'filter',
     'forum',
+    'history',
     'views',
     'block_content',
     'config_translation',
diff --git a/core/modules/block/tests/src/Kernel/Migrate/d7/MigrateBlockTest.php b/core/modules/block/tests/src/Kernel/Migrate/d7/MigrateBlockTest.php
index 991d02142c..9d23daa12b 100644
--- a/core/modules/block/tests/src/Kernel/Migrate/d7/MigrateBlockTest.php
+++ b/core/modules/block/tests/src/Kernel/Migrate/d7/MigrateBlockTest.php
@@ -20,6 +20,7 @@ class MigrateBlockTest extends MigrateDrupal7TestBase {
     'block',
     'views',
     'comment',
+    'history',
     'menu_ui',
     'block_content',
     'node',
diff --git a/core/modules/comment/comment.info.yml b/core/modules/comment/comment.info.yml
index 12ff94b4f0..b7bb4ba84b 100644
--- a/core/modules/comment/comment.info.yml
+++ b/core/modules/comment/comment.info.yml
@@ -5,4 +5,5 @@ package: Core
 version: VERSION
 dependencies:
   - drupal:text
+  - drupal:history
 configure: comment.admin
diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module
index 4d5677ecce..1783aa01c2 100644
--- a/core/modules/comment/comment.module
+++ b/core/modules/comment/comment.module
@@ -35,7 +35,10 @@
  * Comments changed after this time may be marked new, updated, or read,
  * depending on their state for the current user. Defaults to 30 days ago.
  *
- * @todo Remove when https://www.drupal.org/node/1029708 lands.
+ * @deprecated in drupal:9.1.0 and is removed from drupal:10.0.0.
+ *   No replacement is provided.
+ *
+ * @see https://www.drupal.org/node/1029708
  */
 define('COMMENT_NEW_LIMIT', REQUEST_TIME - 30 * 24 * 60 * 60);
 
diff --git a/core/modules/comment/comment.services.yml b/core/modules/comment/comment.services.yml
index 3595854ceb..cbd41a6a49 100644
--- a/core/modules/comment/comment.services.yml
+++ b/core/modules/comment/comment.services.yml
@@ -7,7 +7,7 @@ services:
 
   comment.manager:
     class: Drupal\comment\CommentManager
-    arguments: ['@entity_type.manager', '@config.factory', '@string_translation', '@module_handler', '@current_user', '@entity_field.manager', '@entity_display.repository']
+    arguments: ['@entity_type.manager', '@config.factory', '@string_translation', '@module_handler', '@current_user', '@entity_field.manager', '@entity_display.repository', '@history.repository']
 
   comment.statistics:
     class: Drupal\comment\CommentStatistics
@@ -21,4 +21,4 @@ services:
 
   comment.link_builder:
     class: Drupal\comment\CommentLinkBuilder
-    arguments: ['@current_user', '@comment.manager', '@module_handler', '@string_translation', '@entity_type.manager']
+    arguments: ['@current_user', '@comment.manager', '@module_handler', '@string_translation', '@entity_type.manager', '@history.repository']
diff --git a/core/modules/comment/src/CommentLinkBuilder.php b/core/modules/comment/src/CommentLinkBuilder.php
index 4725f88237..4f17b63cfd 100644
--- a/core/modules/comment/src/CommentLinkBuilder.php
+++ b/core/modules/comment/src/CommentLinkBuilder.php
@@ -11,6 +11,7 @@
 use Drupal\Core\StringTranslation\StringTranslationTrait;
 use Drupal\Core\StringTranslation\TranslationInterface;
 use Drupal\Core\Url;
+use Drupal\history\HistoryRepositoryInterface;
 
 /**
  * Defines a class for building markup for comment links on a commented entity.
@@ -49,6 +50,13 @@ class CommentLinkBuilder implements CommentLinkBuilderInterface {
    */
   protected $entityTypeManager;
 
+  /**
+   * The history repository service.
+   *
+   * @var \Drupal\history\HistoryRepositoryInterface
+   */
+  protected $historyRepository;
+
   /**
    * Constructs a new CommentLinkBuilder object.
    *
@@ -62,13 +70,20 @@ class CommentLinkBuilder implements CommentLinkBuilderInterface {
    *   String translation service.
    * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
    *   The entity type manager.
+   * @param \Drupal\history\HistoryRepositoryInterface $history_repository
+   *   The history repository service.
    */
-  public function __construct(AccountInterface $current_user, CommentManagerInterface $comment_manager, ModuleHandlerInterface $module_handler, TranslationInterface $string_translation, EntityTypeManagerInterface $entity_type_manager) {
+  public function __construct(AccountInterface $current_user, CommentManagerInterface $comment_manager, ModuleHandlerInterface $module_handler, TranslationInterface $string_translation, EntityTypeManagerInterface $entity_type_manager, HistoryRepositoryInterface $history_repository = NULL) {
     $this->currentUser = $current_user;
     $this->commentManager = $comment_manager;
     $this->moduleHandler = $module_handler;
     $this->stringTranslation = $string_translation;
     $this->entityTypeManager = $entity_type_manager;
+    if (!$history_repository) {
+      @trigger_error('Calling CommentLinkBuilder::__construct() without the $history_repository argument is deprecated in drupal:9.1.0. The $history_repository argument will be required in drupal:10.0.0. See https://www.drupal.org/node/2081585', E_USER_DEPRECATED);
+      $history_repository = \Drupal::service('history.repository');
+    }
+    $this->historyRepository = $history_repository;
   }
 
   /**
@@ -193,12 +208,13 @@ public function buildCommentedEntityLinks(FieldableEntityInterface $entity, arra
           '#links' => $links,
           '#attributes' => ['class' => ['links', 'inline']],
         ];
-        if ($view_mode == 'teaser' && $this->moduleHandler->moduleExists('history') && $this->currentUser->isAuthenticated()) {
+        if ($view_mode == 'teaser' && $this->currentUser->isAuthenticated()) {
           $entity_links['comment__' . $field_name]['#cache']['contexts'][] = 'user';
           $entity_links['comment__' . $field_name]['#attached']['library'][] = 'comment/drupal.node-new-comments-link';
           // Embed the metadata for the "X new comments" link (if any) on this
           // entity.
-          $entity_links['comment__' . $field_name]['#attached']['drupalSettings']['history']['lastReadTimestamps'][$entity->id()] = (int) history_read($entity->id());
+          $timestamps = $this->historyRepository->getLastViewed($entity->getEntityTypeId(), [$entity->id()]);
+          $entity_links['comment__' . $field_name]['#attached']['drupalSettings']['history']['lastReadTimestamps'][$entity->id()] = (int) $timestamps[$entity->id()];
           $new_comments = $this->commentManager->getCountNewComments($entity);
           if ($new_comments > 0) {
             $page_number = $this->entityTypeManager
diff --git a/core/modules/comment/src/CommentManager.php b/core/modules/comment/src/CommentManager.php
index 41556aa759..3641fc7c1f 100644
--- a/core/modules/comment/src/CommentManager.php
+++ b/core/modules/comment/src/CommentManager.php
@@ -16,6 +16,7 @@
 use Drupal\Core\Url;
 use Drupal\field\Entity\FieldStorageConfig;
 use Drupal\field\Entity\FieldConfig;
+use Drupal\history\HistoryRepositoryInterface;
 use Drupal\user\RoleInterface;
 use Drupal\user\UserInterface;
 
@@ -74,6 +75,13 @@ class CommentManager implements CommentManagerInterface {
    */
   protected $currentUser;
 
+  /**
+   * The history repository service.
+   *
+   * @var \Drupal\history\HistoryRepositoryInterface
+   */
+  protected $historyRepository;
+
   /**
    * Construct the CommentManager object.
    *
@@ -91,8 +99,10 @@ class CommentManager implements CommentManagerInterface {
    *   The entity field manager service.
    * @param \Drupal\Core\Entity\EntityDisplayRepositoryInterface $entity_display_repository
    *   The entity display repository service.
+   * @param \Drupal\history\HistoryRepositoryInterface $history_repository
+   *   The history repository service.
    */
-  public function __construct(EntityTypeManagerInterface $entity_type_manager, ConfigFactoryInterface $config_factory, TranslationInterface $string_translation, ModuleHandlerInterface $module_handler, AccountInterface $current_user, EntityFieldManagerInterface $entity_field_manager, EntityDisplayRepositoryInterface $entity_display_repository) {
+  public function __construct(EntityTypeManagerInterface $entity_type_manager, ConfigFactoryInterface $config_factory, TranslationInterface $string_translation, ModuleHandlerInterface $module_handler, AccountInterface $current_user, EntityFieldManagerInterface $entity_field_manager, EntityDisplayRepositoryInterface $entity_display_repository, HistoryRepositoryInterface $history_repository = NULL) {
     $this->entityTypeManager = $entity_type_manager;
     $this->userConfig = $config_factory->get('user.settings');
     $this->stringTranslation = $string_translation;
@@ -100,6 +110,11 @@ public function __construct(EntityTypeManagerInterface $entity_type_manager, Con
     $this->currentUser = $current_user;
     $this->entityFieldManager = $entity_field_manager;
     $this->entityDisplayRepository = $entity_display_repository;
+    if (!$history_repository) {
+      @trigger_error('Calling CommentManager::__construct() without the $history_repository argument is deprecated in drupal:9.1.0. The $history_repository argument will be required in drupal:10.0.0. See https://www.drupal.org/node/2081585', E_USER_DEPRECATED);
+      $history_repository = \Drupal::service('history.repository');
+    }
+    $this->historyRepository = $history_repository;
   }
 
   /**
@@ -196,25 +211,11 @@ public function forbiddenMessage(EntityInterface $entity, $field_name) {
    * {@inheritdoc}
    */
   public function getCountNewComments(EntityInterface $entity, $field_name = NULL, $timestamp = 0) {
-    // @todo Replace module handler with optional history service injection
-    //   after https://www.drupal.org/node/2081585.
-    if ($this->currentUser->isAuthenticated() && $this->moduleHandler->moduleExists('history')) {
+    if ($this->currentUser->isAuthenticated()) {
       // Retrieve the timestamp at which the current user last viewed this entity.
       if (!$timestamp) {
-        if ($entity->getEntityTypeId() == 'node') {
-          $timestamp = history_read($entity->id());
-        }
-        else {
-          $function = $entity->getEntityTypeId() . '_last_viewed';
-          if (function_exists($function)) {
-            $timestamp = $function($entity->id());
-          }
-          else {
-            // Default to 30 days ago.
-            // @todo Remove once https://www.drupal.org/node/1029708 lands.
-            $timestamp = COMMENT_NEW_LIMIT;
-          }
-        }
+        $timestamp = $this->historyRepository->getLastViewed($entity->getEntityTypeId(), [$entity->id()]);
+        $timestamp = $timestamp[$entity->id()];
       }
       $timestamp = ($timestamp > HISTORY_READ_LIMIT ? $timestamp : HISTORY_READ_LIMIT);
 
diff --git a/core/modules/comment/src/Plugin/views/field/NodeNewComments.php b/core/modules/comment/src/Plugin/views/field/NodeNewComments.php
index 56da2b3df9..f85d5ce2a6 100644
--- a/core/modules/comment/src/Plugin/views/field/NodeNewComments.php
+++ b/core/modules/comment/src/Plugin/views/field/NodeNewComments.php
@@ -156,7 +156,7 @@ public function preRender(&$values) {
 
     if ($nids) {
       $result = $this->database->query("SELECT n.nid, COUNT(c.cid) AS num_comments FROM {node} n INNER JOIN {comment_field_data} c ON n.nid = c.entity_id AND c.entity_type = 'node' AND c.default_langcode = 1
-        LEFT JOIN {history} h ON h.nid = n.nid AND h.uid = :h_uid WHERE n.nid IN ( :nids[] )
+        LEFT JOIN {history} h ON h.entity_id = n.nid AND h.uid = :h_uid WHERE n.nid IN ( :nids[] )
         AND c.changed > GREATEST(COALESCE(h.timestamp, :timestamp1), :timestamp2) AND c.status = :status GROUP BY n.nid", [
         ':status' => CommentInterface::PUBLISHED,
         ':h_uid' => $user->id(),
diff --git a/core/modules/comment/tests/src/Kernel/CommentBaseFieldTest.php b/core/modules/comment/tests/src/Kernel/CommentBaseFieldTest.php
index 6879613a46..b4cc8335aa 100644
--- a/core/modules/comment/tests/src/Kernel/CommentBaseFieldTest.php
+++ b/core/modules/comment/tests/src/Kernel/CommentBaseFieldTest.php
@@ -22,6 +22,7 @@ class CommentBaseFieldTest extends KernelTestBase {
   protected static $modules = [
     'system',
     'user',
+    'history',
     'comment',
     'comment_base_field_test',
   ];
diff --git a/core/modules/comment/tests/src/Kernel/CommentBundlesTest.php b/core/modules/comment/tests/src/Kernel/CommentBundlesTest.php
index d6393f4e8a..cf9fda8f67 100644
--- a/core/modules/comment/tests/src/Kernel/CommentBundlesTest.php
+++ b/core/modules/comment/tests/src/Kernel/CommentBundlesTest.php
@@ -15,7 +15,7 @@ class CommentBundlesTest extends KernelTestBase {
   /**
    * {@inheritdoc}
    */
-  protected static $modules = ['comment', 'node', 'taxonomy', 'user'];
+  protected static $modules = ['comment', 'history', 'node', 'taxonomy', 'user'];
 
   /**
    * Entity type ids to use for target_entity_type_id on comment bundles.
diff --git a/core/modules/comment/tests/src/Kernel/CommentDefaultFormatterCacheTagsTest.php b/core/modules/comment/tests/src/Kernel/CommentDefaultFormatterCacheTagsTest.php
index 0bd3d23de3..bc1e834965 100644
--- a/core/modules/comment/tests/src/Kernel/CommentDefaultFormatterCacheTagsTest.php
+++ b/core/modules/comment/tests/src/Kernel/CommentDefaultFormatterCacheTagsTest.php
@@ -26,7 +26,7 @@ class CommentDefaultFormatterCacheTagsTest extends EntityKernelTestBase {
    *
    * @var array
    */
-  protected static $modules = ['entity_test', 'comment'];
+  protected static $modules = ['entity_test', 'comment', 'history'];
 
   /**
    * {@inheritdoc}
diff --git a/core/modules/comment/tests/src/Kernel/CommentFieldAccessTest.php b/core/modules/comment/tests/src/Kernel/CommentFieldAccessTest.php
index 15bace911a..8dbcd5f783 100644
--- a/core/modules/comment/tests/src/Kernel/CommentFieldAccessTest.php
+++ b/core/modules/comment/tests/src/Kernel/CommentFieldAccessTest.php
@@ -31,7 +31,7 @@ class CommentFieldAccessTest extends EntityKernelTestBase {
    *
    * @var array
    */
-  protected static $modules = ['comment', 'entity_test', 'user'];
+  protected static $modules = ['comment', 'entity_test', 'history', 'user'];
 
   /**
    * Fields that only users with administer comments permissions can change.
diff --git a/core/modules/comment/tests/src/Kernel/CommentHostnameTest.php b/core/modules/comment/tests/src/Kernel/CommentHostnameTest.php
index cbf67985df..de0f208ff9 100644
--- a/core/modules/comment/tests/src/Kernel/CommentHostnameTest.php
+++ b/core/modules/comment/tests/src/Kernel/CommentHostnameTest.php
@@ -19,7 +19,7 @@ class CommentHostnameTest extends KernelTestBase {
   /**
    * {@inheritdoc}
    */
-  protected static $modules = ['comment', 'entity_test', 'user'];
+  protected static $modules = ['comment', 'entity_test', 'history', 'user'];
 
   /**
    * Tests hostname default value callback.
diff --git a/core/modules/comment/tests/src/Kernel/CommentIntegrationTest.php b/core/modules/comment/tests/src/Kernel/CommentIntegrationTest.php
index dc58a2aec3..90dc3779e0 100644
--- a/core/modules/comment/tests/src/Kernel/CommentIntegrationTest.php
+++ b/core/modules/comment/tests/src/Kernel/CommentIntegrationTest.php
@@ -28,6 +28,7 @@ class CommentIntegrationTest extends KernelTestBase {
     'comment',
     'field',
     'entity_test',
+    'history',
     'user',
     'system',
     'dblog',
diff --git a/core/modules/comment/tests/src/Kernel/CommentItemTest.php b/core/modules/comment/tests/src/Kernel/CommentItemTest.php
index 45c1b5babc..af6bebc5b8 100644
--- a/core/modules/comment/tests/src/Kernel/CommentItemTest.php
+++ b/core/modules/comment/tests/src/Kernel/CommentItemTest.php
@@ -23,7 +23,7 @@ class CommentItemTest extends FieldKernelTestBase {
    *
    * @var array
    */
-  protected static $modules = ['comment', 'entity_test', 'user'];
+  protected static $modules = ['comment', 'entity_test', 'history', 'user'];
 
   protected function setUp(): void {
     parent::setUp();
diff --git a/core/modules/comment/tests/src/Kernel/CommentOrphanTest.php b/core/modules/comment/tests/src/Kernel/CommentOrphanTest.php
index 2f1ad83f12..1d2f5615d7 100644
--- a/core/modules/comment/tests/src/Kernel/CommentOrphanTest.php
+++ b/core/modules/comment/tests/src/Kernel/CommentOrphanTest.php
@@ -19,7 +19,7 @@ class CommentOrphanTest extends EntityKernelTestBase {
   /**
    * {@inheritdoc}
    */
-  protected static $modules = ['comment', 'node'];
+  protected static $modules = ['comment', 'history', 'node'];
 
   /**
    * {@inheritdoc}
diff --git a/core/modules/comment/tests/src/Kernel/CommentStringIdEntitiesTest.php b/core/modules/comment/tests/src/Kernel/CommentStringIdEntitiesTest.php
index 817abbcd37..fba379fb5a 100644
--- a/core/modules/comment/tests/src/Kernel/CommentStringIdEntitiesTest.php
+++ b/core/modules/comment/tests/src/Kernel/CommentStringIdEntitiesTest.php
@@ -24,6 +24,7 @@ class CommentStringIdEntitiesTest extends KernelTestBase {
     'field',
     'field_ui',
     'entity_test',
+    'history',
     'text',
   ];
 
diff --git a/core/modules/comment/tests/src/Kernel/CommentUninstallTest.php b/core/modules/comment/tests/src/Kernel/CommentUninstallTest.php
index 71f85d1143..85450c1d22 100644
--- a/core/modules/comment/tests/src/Kernel/CommentUninstallTest.php
+++ b/core/modules/comment/tests/src/Kernel/CommentUninstallTest.php
@@ -23,6 +23,7 @@ class CommentUninstallTest extends KernelTestBase {
   protected static $modules = [
     'comment',
     'field',
+    'history',
     'node',
     'system',
     'text',
diff --git a/core/modules/comment/tests/src/Kernel/CommentValidationTest.php b/core/modules/comment/tests/src/Kernel/CommentValidationTest.php
index 96289c155e..27c12389d3 100644
--- a/core/modules/comment/tests/src/Kernel/CommentValidationTest.php
+++ b/core/modules/comment/tests/src/Kernel/CommentValidationTest.php
@@ -19,7 +19,7 @@ class CommentValidationTest extends EntityKernelTestBase {
    *
    * @var array
    */
-  protected static $modules = ['comment', 'node'];
+  protected static $modules = ['comment', 'history', 'node'];
 
   /**
    * {@inheritdoc}
diff --git a/core/modules/comment/tests/src/Kernel/Migrate/MigrateCommentStubTest.php b/core/modules/comment/tests/src/Kernel/Migrate/MigrateCommentStubTest.php
index c906281836..35608d370d 100644
--- a/core/modules/comment/tests/src/Kernel/Migrate/MigrateCommentStubTest.php
+++ b/core/modules/comment/tests/src/Kernel/Migrate/MigrateCommentStubTest.php
@@ -19,7 +19,7 @@ class MigrateCommentStubTest extends MigrateDrupalTestBase {
   /**
    * {@inheritdoc}
    */
-  protected static $modules = ['comment', 'node'];
+  protected static $modules = ['comment', 'history', 'node'];
 
   /**
    * {@inheritdoc}
diff --git a/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentEntityDisplayTest.php b/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentEntityDisplayTest.php
index b4a670562f..2084a2ace3 100644
--- a/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentEntityDisplayTest.php
+++ b/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentEntityDisplayTest.php
@@ -16,7 +16,7 @@ class MigrateCommentEntityDisplayTest extends MigrateDrupal6TestBase {
   /**
    * {@inheritdoc}
    */
-  protected static $modules = ['comment', 'menu_ui'];
+  protected static $modules = ['comment', 'history', 'menu_ui'];
 
   /**
    * {@inheritdoc}
diff --git a/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentEntityFormDisplaySubjectTest.php b/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentEntityFormDisplaySubjectTest.php
index a57c2250fb..c0b2c748d2 100644
--- a/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentEntityFormDisplaySubjectTest.php
+++ b/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentEntityFormDisplaySubjectTest.php
@@ -16,7 +16,7 @@ class MigrateCommentEntityFormDisplaySubjectTest extends MigrateDrupal6TestBase
   /**
    * {@inheritdoc}
    */
-  protected static $modules = ['comment'];
+  protected static $modules = ['comment', 'history'];
 
   /**
    * {@inheritdoc}
diff --git a/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentEntityFormDisplayTest.php b/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentEntityFormDisplayTest.php
index 5438c938c2..67dc3d1e5a 100644
--- a/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentEntityFormDisplayTest.php
+++ b/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentEntityFormDisplayTest.php
@@ -16,7 +16,7 @@ class MigrateCommentEntityFormDisplayTest extends MigrateDrupal6TestBase {
   /**
    * {@inheritdoc}
    */
-  protected static $modules = ['comment', 'menu_ui'];
+  protected static $modules = ['comment', 'history', 'menu_ui'];
 
   /**
    * {@inheritdoc}
diff --git a/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentFieldInstanceTest.php b/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentFieldInstanceTest.php
index 57c34b2293..e5b795d75b 100644
--- a/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentFieldInstanceTest.php
+++ b/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentFieldInstanceTest.php
@@ -16,7 +16,7 @@ class MigrateCommentFieldInstanceTest extends MigrateDrupal6TestBase {
   /**
    * {@inheritdoc}
    */
-  protected static $modules = ['comment', 'menu_ui'];
+  protected static $modules = ['comment', 'history', 'menu_ui'];
 
   /**
    * {@inheritdoc}
diff --git a/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentFieldTest.php b/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentFieldTest.php
index e2a865cd7c..7a488966d6 100644
--- a/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentFieldTest.php
+++ b/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentFieldTest.php
@@ -16,7 +16,7 @@ class MigrateCommentFieldTest extends MigrateDrupal6TestBase {
   /**
    * {@inheritdoc}
    */
-  protected static $modules = ['comment', 'menu_ui'];
+  protected static $modules = ['comment', 'history', 'menu_ui'];
 
   /**
    * {@inheritdoc}
diff --git a/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentTest.php b/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentTest.php
index 42c96bbcbe..10c0728bad 100644
--- a/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentTest.php
+++ b/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentTest.php
@@ -23,6 +23,7 @@ class MigrateCommentTest extends MigrateDrupal6TestBase {
   protected static $modules = [
     'comment',
     'content_translation',
+    'history',
     'language',
     'menu_ui',
   ];
diff --git a/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentTypeTest.php b/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentTypeTest.php
index 58dc428d89..fa1eaac2b9 100644
--- a/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentTypeTest.php
+++ b/core/modules/comment/tests/src/Kernel/Migrate/d6/MigrateCommentTypeTest.php
@@ -16,7 +16,7 @@ class MigrateCommentTypeTest extends MigrateDrupal6TestBase {
   /**
    * {@inheritdoc}
    */
-  protected static $modules = ['comment'];
+  protected static $modules = ['comment', 'history'];
 
   /**
    * {@inheritdoc}
diff --git a/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentEntityDisplayTest.php b/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentEntityDisplayTest.php
index 1ace7293f0..b3ae867ccc 100644
--- a/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentEntityDisplayTest.php
+++ b/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentEntityDisplayTest.php
@@ -16,7 +16,7 @@ class MigrateCommentEntityDisplayTest extends MigrateDrupal7TestBase {
   /**
    * {@inheritdoc}
    */
-  protected static $modules = ['node', 'comment', 'text', 'menu_ui'];
+  protected static $modules = ['node', 'comment', 'history', 'text', 'menu_ui'];
 
   /**
    * {@inheritdoc}
diff --git a/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentEntityFormDisplaySubjectTest.php b/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentEntityFormDisplaySubjectTest.php
index c0a1de628c..e52c67edcb 100644
--- a/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentEntityFormDisplaySubjectTest.php
+++ b/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentEntityFormDisplaySubjectTest.php
@@ -16,7 +16,7 @@ class MigrateCommentEntityFormDisplaySubjectTest extends MigrateDrupal7TestBase
   /**
    * {@inheritdoc}
    */
-  protected static $modules = ['node', 'comment', 'text', 'menu_ui'];
+  protected static $modules = ['node', 'comment', 'history', 'text', 'menu_ui'];
 
   /**
    * {@inheritdoc}
diff --git a/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentEntityFormDisplayTest.php b/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentEntityFormDisplayTest.php
index 05d1651bc9..ac2b7028ce 100644
--- a/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentEntityFormDisplayTest.php
+++ b/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentEntityFormDisplayTest.php
@@ -16,7 +16,7 @@ class MigrateCommentEntityFormDisplayTest extends MigrateDrupal7TestBase {
   /**
    * {@inheritdoc}
    */
-  protected static $modules = ['node', 'comment', 'text', 'menu_ui'];
+  protected static $modules = ['node', 'comment', 'history', 'text', 'menu_ui'];
 
   /**
    * {@inheritdoc}
diff --git a/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentFieldInstanceTest.php b/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentFieldInstanceTest.php
index e1fd26c66c..ecd9682620 100644
--- a/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentFieldInstanceTest.php
+++ b/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentFieldInstanceTest.php
@@ -16,7 +16,7 @@ class MigrateCommentFieldInstanceTest extends MigrateDrupal7TestBase {
   /**
    * {@inheritdoc}
    */
-  protected static $modules = ['node', 'comment', 'text', 'menu_ui'];
+  protected static $modules = ['node', 'comment', 'history', 'text', 'menu_ui'];
 
   /**
    * {@inheritdoc}
diff --git a/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentFieldTest.php b/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentFieldTest.php
index 25e67d239f..2e239c0fb2 100644
--- a/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentFieldTest.php
+++ b/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentFieldTest.php
@@ -16,7 +16,7 @@ class MigrateCommentFieldTest extends MigrateDrupal7TestBase {
   /**
    * {@inheritdoc}
    */
-  protected static $modules = ['node', 'comment', 'text'];
+  protected static $modules = ['node', 'comment', 'history', 'text'];
 
   /**
    * {@inheritdoc}
diff --git a/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentTest.php b/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentTest.php
index a0a8aa8e51..be5f5a5b97 100644
--- a/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentTest.php
+++ b/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentTest.php
@@ -22,6 +22,7 @@ class MigrateCommentTest extends MigrateDrupal7TestBase {
     'content_translation',
     'datetime',
     'filter',
+    'history',
     'image',
     'language',
     'link',
diff --git a/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentTypeTest.php b/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentTypeTest.php
index 8345cef94b..c9d63801ae 100644
--- a/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentTypeTest.php
+++ b/core/modules/comment/tests/src/Kernel/Migrate/d7/MigrateCommentTypeTest.php
@@ -16,7 +16,7 @@ class MigrateCommentTypeTest extends MigrateDrupal7TestBase {
   /**
    * {@inheritdoc}
    */
-  protected static $modules = ['node', 'comment', 'text'];
+  protected static $modules = ['node', 'comment', 'history', 'text'];
 
   /**
    * {@inheritdoc}
diff --git a/core/modules/comment/tests/src/Kernel/Plugin/migrate/source/d6/CommentSourceWithHighWaterTest.php b/core/modules/comment/tests/src/Kernel/Plugin/migrate/source/d6/CommentSourceWithHighWaterTest.php
index 290550cdb4..753a2bbbbe 100644
--- a/core/modules/comment/tests/src/Kernel/Plugin/migrate/source/d6/CommentSourceWithHighWaterTest.php
+++ b/core/modules/comment/tests/src/Kernel/Plugin/migrate/source/d6/CommentSourceWithHighWaterTest.php
@@ -16,7 +16,7 @@ class CommentSourceWithHighWaterTest extends MigrateSqlSourceTestBase {
   /**
    * {@inheritdoc}
    */
-  protected static $modules = ['comment', 'migrate_drupal'];
+  protected static $modules = ['comment', 'history', 'migrate_drupal'];
 
   /**
    * {@inheritdoc}
diff --git a/core/modules/comment/tests/src/Kernel/Plugin/migrate/source/d6/CommentTest.php b/core/modules/comment/tests/src/Kernel/Plugin/migrate/source/d6/CommentTest.php
index 90c31cfdb3..95f64142cd 100644
--- a/core/modules/comment/tests/src/Kernel/Plugin/migrate/source/d6/CommentTest.php
+++ b/core/modules/comment/tests/src/Kernel/Plugin/migrate/source/d6/CommentTest.php
@@ -15,7 +15,7 @@ class CommentTest extends MigrateSqlSourceTestBase {
   /**
    * {@inheritdoc}
    */
-  protected static $modules = ['comment', 'migrate_drupal'];
+  protected static $modules = ['comment', 'history', 'migrate_drupal'];
 
   /**
    * {@inheritdoc}
diff --git a/core/modules/comment/tests/src/Kernel/Plugin/migrate/source/d7/CommentEntityTranslationTest.php b/core/modules/comment/tests/src/Kernel/Plugin/migrate/source/d7/CommentEntityTranslationTest.php
index cf09667423..4c5545b572 100644
--- a/core/modules/comment/tests/src/Kernel/Plugin/migrate/source/d7/CommentEntityTranslationTest.php
+++ b/core/modules/comment/tests/src/Kernel/Plugin/migrate/source/d7/CommentEntityTranslationTest.php
@@ -15,7 +15,7 @@ class CommentEntityTranslationTest extends MigrateSqlSourceTestBase {
   /**
    * {@inheritdoc}
    */
-  protected static $modules = ['comment', 'migrate_drupal'];
+  protected static $modules = ['comment', 'history', 'migrate_drupal'];
 
   /**
    * {@inheritdoc}
diff --git a/core/modules/comment/tests/src/Kernel/Plugin/migrate/source/d7/CommentTest.php b/core/modules/comment/tests/src/Kernel/Plugin/migrate/source/d7/CommentTest.php
index b40e974d7c..ff9d76e388 100644
--- a/core/modules/comment/tests/src/Kernel/Plugin/migrate/source/d7/CommentTest.php
+++ b/core/modules/comment/tests/src/Kernel/Plugin/migrate/source/d7/CommentTest.php
@@ -15,7 +15,7 @@ class CommentTest extends MigrateSqlSourceTestBase {
   /**
    * {@inheritdoc}
    */
-  protected static $modules = ['comment', 'migrate_drupal'];
+  protected static $modules = ['comment', 'history', 'migrate_drupal'];
 
   /**
    * {@inheritdoc}
diff --git a/core/modules/comment/tests/src/Kernel/Views/CommentAdminViewTest.php b/core/modules/comment/tests/src/Kernel/Views/CommentAdminViewTest.php
index 4431bb6e67..f292ff5676 100644
--- a/core/modules/comment/tests/src/Kernel/Views/CommentAdminViewTest.php
+++ b/core/modules/comment/tests/src/Kernel/Views/CommentAdminViewTest.php
@@ -38,6 +38,7 @@ class CommentAdminViewTest extends ViewsKernelTestBase {
     'user',
     'comment',
     'entity_test',
+    'history',
     'language',
     'locale',
   ];
diff --git a/core/modules/comment/tests/src/Kernel/Views/CommentFieldNameTest.php b/core/modules/comment/tests/src/Kernel/Views/CommentFieldNameTest.php
index af2a451bc5..76329cdc7d 100644
--- a/core/modules/comment/tests/src/Kernel/Views/CommentFieldNameTest.php
+++ b/core/modules/comment/tests/src/Kernel/Views/CommentFieldNameTest.php
@@ -34,6 +34,7 @@ class CommentFieldNameTest extends KernelTestBase {
     'comment_test_views',
     'field',
     'filter',
+    'history',
     'node',
     'system',
     'text',
diff --git a/core/modules/comment/tests/src/Kernel/Views/CommentLinksTest.php b/core/modules/comment/tests/src/Kernel/Views/CommentLinksTest.php
index be5c14606f..50cabe0a34 100644
--- a/core/modules/comment/tests/src/Kernel/Views/CommentLinksTest.php
+++ b/core/modules/comment/tests/src/Kernel/Views/CommentLinksTest.php
@@ -23,7 +23,7 @@ class CommentLinksTest extends CommentViewsKernelTestBase {
    *
    * @var array
    */
-  protected static $modules = ['entity_test'];
+  protected static $modules = ['entity_test', 'history'];
 
   /**
    * Views used by this test.
diff --git a/core/modules/comment/tests/src/Kernel/Views/CommentUserNameTest.php b/core/modules/comment/tests/src/Kernel/Views/CommentUserNameTest.php
index d10a3b91fe..041e684fb8 100644
--- a/core/modules/comment/tests/src/Kernel/Views/CommentUserNameTest.php
+++ b/core/modules/comment/tests/src/Kernel/Views/CommentUserNameTest.php
@@ -27,7 +27,7 @@ class CommentUserNameTest extends ViewsKernelTestBase {
   /**
    * {@inheritdoc}
    */
-  protected static $modules = ['user', 'comment', 'entity_test'];
+  protected static $modules = ['user', 'comment', 'entity_test', 'history'];
 
   /**
    * {@inheritdoc}
diff --git a/core/modules/comment/tests/src/Kernel/Views/CommentViewsFieldAccessTest.php b/core/modules/comment/tests/src/Kernel/Views/CommentViewsFieldAccessTest.php
index f4fc987dcf..e10cbcbbcc 100644
--- a/core/modules/comment/tests/src/Kernel/Views/CommentViewsFieldAccessTest.php
+++ b/core/modules/comment/tests/src/Kernel/Views/CommentViewsFieldAccessTest.php
@@ -17,7 +17,7 @@ class CommentViewsFieldAccessTest extends FieldFieldAccessTestBase {
   /**
    * {@inheritdoc}
    */
-  protected static $modules = ['comment', 'entity_test'];
+  protected static $modules = ['comment', 'entity_test', 'history'];
 
   /**
    * {@inheritdoc}
diff --git a/core/modules/comment/tests/src/Kernel/Views/FilterAndArgumentUserUidTest.php b/core/modules/comment/tests/src/Kernel/Views/FilterAndArgumentUserUidTest.php
index 7dfc6896ff..1a8356d2b1 100644
--- a/core/modules/comment/tests/src/Kernel/Views/FilterAndArgumentUserUidTest.php
+++ b/core/modules/comment/tests/src/Kernel/Views/FilterAndArgumentUserUidTest.php
@@ -33,6 +33,7 @@ class FilterAndArgumentUserUidTest extends KernelTestBase {
     'comment_test_views',
     'field',
     'filter',
+    'history',
     'node',
     'system',
     'text',
diff --git a/core/modules/comment/tests/src/Unit/CommentLinkBuilderTest.php b/core/modules/comment/tests/src/Unit/CommentLinkBuilderTest.php
index 64cdc6079e..efb82b013b 100644
--- a/core/modules/comment/tests/src/Unit/CommentLinkBuilderTest.php
+++ b/core/modules/comment/tests/src/Unit/CommentLinkBuilderTest.php
@@ -6,6 +6,7 @@
 use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
 use Drupal\Core\Entity\EntityTypeManagerInterface;
 use Drupal\Core\Url;
+use Drupal\history\HistoryRepositoryInterface;
 use Drupal\node\NodeInterface;
 use Drupal\Tests\Traits\Core\GeneratePermutationsTrait;
 use Drupal\Tests\UnitTestCase;
@@ -39,6 +40,13 @@ class CommentLinkBuilderTest extends UnitTestCase {
    */
   protected $entityTypeManager;
 
+  /**
+   * The history repository mock.
+   *
+   * @var \Drupal\history\HistoryRepositoryInterface|\PHPUnit\Framework\MockObject\MockObject
+   */
+  protected $historyRepository;
+
   /**
    * Module handler mock.
    *
@@ -72,9 +80,10 @@ protected function setUp(): void {
     $this->commentManager = $this->createMock('\Drupal\comment\CommentManagerInterface');
     $this->stringTranslation = $this->getStringTranslationStub();
     $this->entityTypeManager = $this->createMock(EntityTypeManagerInterface::class);
+    $this->historyRepository = $this->createMock(HistoryRepositoryInterface::class);
     $this->moduleHandler = $this->createMock('\Drupal\Core\Extension\ModuleHandlerInterface');
     $this->currentUser = $this->createMock('\Drupal\Core\Session\AccountProxyInterface');
-    $this->commentLinkBuilder = new CommentLinkBuilder($this->currentUser, $this->commentManager, $this->moduleHandler, $this->stringTranslation, $this->entityTypeManager);
+    $this->commentLinkBuilder = new CommentLinkBuilder($this->currentUser, $this->commentManager, $this->moduleHandler, $this->stringTranslation, $this->entityTypeManager, $this->historyRepository);
     $this->commentManager->expects($this->any())
       ->method('getFields')
       ->with('node')
@@ -87,6 +96,9 @@ protected function setUp(): void {
     $this->stringTranslation->expects($this->any())
       ->method('formatPlural')
       ->willReturnArgument(1);
+    $this->historyRepository->expects($this->any())
+      ->method('getLastViewed')
+      ->willReturn([1 => 0]);
   }
 
   /**
@@ -318,13 +330,3 @@ protected function getMockNode($has_field, $comment_status, $form_location, $com
   }
 
 }
-
-namespace Drupal\comment;
-
-if (!function_exists('history_read')) {
-
-  function history_read() {
-    return 0;
-  }
-
-}
diff --git a/core/modules/comment/tests/src/Unit/CommentManagerTest.php b/core/modules/comment/tests/src/Unit/CommentManagerTest.php
index cfc65d3af4..d2d4f875ee 100644
--- a/core/modules/comment/tests/src/Unit/CommentManagerTest.php
+++ b/core/modules/comment/tests/src/Unit/CommentManagerTest.php
@@ -8,6 +8,7 @@
 use Drupal\Core\Entity\EntityTypeManagerInterface;
 use Drupal\Core\Entity\FieldableEntityInterface;
 use Drupal\Core\Session\AccountInterface;
+use Drupal\history\HistoryRepositoryInterface;
 use Drupal\Tests\UnitTestCase;
 
 /**
@@ -34,6 +35,7 @@ public function testGetFields() {
 
     $entity_field_manager = $this->createMock(EntityFieldManagerInterface::class);
     $entity_type_manager = $this->createMock(EntityTypeManagerInterface::class);
+    $history_repository = $this->createMock(HistoryRepositoryInterface::class);
 
     $entity_field_manager->expects($this->once())
       ->method('getFieldMapByFieldType')
@@ -49,6 +51,10 @@ public function testGetFields() {
       ->method('getDefinition')
       ->will($this->returnValue($entity_type));
 
+    $history_repository->expects($this->any())
+      ->method('getLastViewed')
+      ->willReturn(0);
+
     $comment_manager = new CommentManager(
       $entity_type_manager,
       $this->createMock('Drupal\Core\Config\ConfigFactoryInterface'),
@@ -56,7 +62,8 @@ public function testGetFields() {
       $this->createMock('Drupal\Core\Extension\ModuleHandlerInterface'),
       $this->createMock(AccountInterface::class),
       $entity_field_manager,
-      $this->prophesize(EntityDisplayRepositoryInterface::class)->reveal()
+      $this->prophesize(EntityDisplayRepositoryInterface::class)->reveal(),
+      $history_repository
     );
     $comment_fields = $comment_manager->getFields('node');
     $this->assertArrayHasKey('field_foobar', $comment_fields);
diff --git a/core/modules/content_translation/tests/src/Kernel/Migrate/d7/MigrateEntityTranslationSettingsTest.php b/core/modules/content_translation/tests/src/Kernel/Migrate/d7/MigrateEntityTranslationSettingsTest.php
index 34d0954fae..47b62af286 100644
--- a/core/modules/content_translation/tests/src/Kernel/Migrate/d7/MigrateEntityTranslationSettingsTest.php
+++ b/core/modules/content_translation/tests/src/Kernel/Migrate/d7/MigrateEntityTranslationSettingsTest.php
@@ -18,6 +18,7 @@ class MigrateEntityTranslationSettingsTest extends MigrateDrupal7TestBase {
   protected static $modules = [
     'comment',
     'content_translation',
+    'history',
     'language',
     'menu_ui',
     'node',
diff --git a/core/modules/field/tests/src/Kernel/EntityReference/EntityReferenceItemTest.php b/core/modules/field/tests/src/Kernel/EntityReference/EntityReferenceItemTest.php
index f9ded30b21..e7b28ab983 100644
--- a/core/modules/field/tests/src/Kernel/EntityReference/EntityReferenceItemTest.php
+++ b/core/modules/field/tests/src/Kernel/EntityReference/EntityReferenceItemTest.php
@@ -43,6 +43,7 @@ class EntityReferenceItemTest extends FieldKernelTestBase {
     'node',
     'comment',
     'file',
+    'history',
     'taxonomy',
     'text',
     'filter',
diff --git a/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldFormatterSettingsTest.php b/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldFormatterSettingsTest.php
index 6462bd98d9..6b1fc53992 100644
--- a/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldFormatterSettingsTest.php
+++ b/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldFormatterSettingsTest.php
@@ -16,6 +16,7 @@ class MigrateFieldFormatterSettingsTest extends MigrateDrupal7TestBase {
   protected static $modules = [
     'comment',
     'datetime',
+    'history',
     'image',
     'link',
     'menu_ui',
diff --git a/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldInstanceLabelDescriptionTest.php b/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldInstanceLabelDescriptionTest.php
index 7720c1baa2..3e80c9fd31 100644
--- a/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldInstanceLabelDescriptionTest.php
+++ b/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldInstanceLabelDescriptionTest.php
@@ -23,6 +23,7 @@ class MigrateFieldInstanceLabelDescriptionTest extends MigrateDrupal7TestBase im
     'datetime',
     'field',
     'file',
+    'history',
     'image',
     'language',
     'link',
diff --git a/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldInstanceTest.php b/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldInstanceTest.php
index 832ebe2151..edb068724e 100644
--- a/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldInstanceTest.php
+++ b/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldInstanceTest.php
@@ -19,6 +19,7 @@ class MigrateFieldInstanceTest extends MigrateDrupal7TestBase {
   protected static $modules = [
     'comment',
     'datetime',
+    'history',
     'image',
     'link',
     'menu_ui',
diff --git a/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldInstanceWidgetSettingsTest.php b/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldInstanceWidgetSettingsTest.php
index 6f97ec66b5..779d989ebe 100644
--- a/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldInstanceWidgetSettingsTest.php
+++ b/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldInstanceWidgetSettingsTest.php
@@ -21,6 +21,7 @@ class MigrateFieldInstanceWidgetSettingsTest extends MigrateDrupal7TestBase {
   protected static $modules = [
     'comment',
     'datetime',
+    'history',
     'image',
     'link',
     'menu_ui',
diff --git a/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldOptionTranslationTest.php b/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldOptionTranslationTest.php
index 8edf5d4c89..b5bfd9341f 100644
--- a/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldOptionTranslationTest.php
+++ b/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldOptionTranslationTest.php
@@ -19,6 +19,7 @@ class MigrateFieldOptionTranslationTest extends MigrateDrupal7TestBase {
     'config_translation',
     'datetime',
     'file',
+    'history',
     'image',
     'language',
     'link',
diff --git a/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldTest.php b/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldTest.php
index eacb368c0f..ddcbdae380 100644
--- a/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldTest.php
+++ b/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldTest.php
@@ -22,6 +22,7 @@ class MigrateFieldTest extends MigrateDrupal7TestBase {
     'comment',
     'datetime',
     'file',
+    'history',
     'image',
     'link',
     'node',
diff --git a/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateViewModesTest.php b/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateViewModesTest.php
index 54f7d46636..59222c22fc 100644
--- a/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateViewModesTest.php
+++ b/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateViewModesTest.php
@@ -13,7 +13,7 @@
  */
 class MigrateViewModesTest extends MigrateDrupal7TestBase {
 
-  protected static $modules = ['comment', 'node', 'taxonomy', 'text'];
+  protected static $modules = ['comment', 'history', 'node', 'taxonomy', 'text'];
 
   /**
    * {@inheritdoc}
diff --git a/core/modules/forum/forum.services.yml b/core/modules/forum/forum.services.yml
index 6268c2cf8a..a83af7fea2 100644
--- a/core/modules/forum/forum.services.yml
+++ b/core/modules/forum/forum.services.yml
@@ -1,7 +1,7 @@
 services:
   forum_manager:
     class: Drupal\forum\ForumManager
-    arguments: ['@config.factory', '@entity_type.manager', '@database', '@string_translation', '@comment.manager', '@entity_field.manager']
+    arguments: ['@config.factory', '@entity_type.manager', '@database', '@string_translation', '@comment.manager', '@entity_field.manager', '@history.repository']
     tags:
       - { name: backend_overridable }
   forum.breadcrumb.node:
diff --git a/core/modules/forum/src/ForumManager.php b/core/modules/forum/src/ForumManager.php
index 4a7b0d460e..78ea099fd8 100644
--- a/core/modules/forum/src/ForumManager.php
+++ b/core/modules/forum/src/ForumManager.php
@@ -11,6 +11,7 @@
 use Drupal\Core\StringTranslation\TranslationInterface;
 use Drupal\Core\StringTranslation\StringTranslationTrait;
 use Drupal\comment\CommentManagerInterface;
+use Drupal\history\HistoryRepositoryInterface;
 use Drupal\node\NodeInterface;
 
 /**
@@ -113,6 +114,13 @@ class ForumManager implements ForumManagerInterface {
    */
   protected $index;
 
+  /**
+   * The history repository service.
+   *
+   * @var \Drupal\history\HistoryRepositoryInterface
+   */
+  protected $historyRepository;
+
   /**
    * Constructs the forum manager service.
    *
@@ -128,14 +136,21 @@ class ForumManager implements ForumManagerInterface {
    *   The comment manager service.
    * @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager
    *   The entity field manager.
+   * @param \Drupal\history\HistoryRepositoryInterface $history_repository
+   *   The history repository service.
    */
-  public function __construct(ConfigFactoryInterface $config_factory, EntityTypeManagerInterface $entity_type_manager, Connection $connection, TranslationInterface $string_translation, CommentManagerInterface $comment_manager, EntityFieldManagerInterface $entity_field_manager) {
+  public function __construct(ConfigFactoryInterface $config_factory, EntityTypeManagerInterface $entity_type_manager, Connection $connection, TranslationInterface $string_translation, CommentManagerInterface $comment_manager, EntityFieldManagerInterface $entity_field_manager, HistoryRepositoryInterface $history_repository = NULL) {
     $this->configFactory = $config_factory;
     $this->entityTypeManager = $entity_type_manager;
     $this->connection = $connection;
     $this->stringTranslation = $string_translation;
     $this->commentManager = $comment_manager;
     $this->entityFieldManager = $entity_field_manager;
+    if (!$history_repository) {
+      @trigger_error('Calling ForumManager::__construct() without the $history_repository argument is deprecated in drupal:9.1.0. The $history_repository argument will be required in drupal:10.0.0. See https://www.drupal.org/node/2081585', E_USER_DEPRECATED);
+      $history_repository = \Drupal::service('history.repository');
+    }
+    $this->historyRepository = $history_repository;
   }
 
   /**
@@ -318,16 +333,11 @@ protected function getTopicOrder($sortby) {
    *   previously viewed the node; otherwise HISTORY_READ_LIMIT.
    */
   protected function lastVisit($nid, AccountInterface $account) {
+    $this->history += $this->historyRepository->getLastViewed('node', [$nid]);
     if (empty($this->history[$nid])) {
-      $result = $this->connection->select('history', 'h')
-        ->fields('h', ['nid', 'timestamp'])
-        ->condition('uid', $account->id())
-        ->execute();
-      foreach ($result as $t) {
-        $this->history[$t->nid] = $t->timestamp > HISTORY_READ_LIMIT ? $t->timestamp : HISTORY_READ_LIMIT;
-      }
+      $this->history[$nid] = HISTORY_READ_LIMIT;
     }
-    return isset($this->history[$nid]) ? $this->history[$nid] : HISTORY_READ_LIMIT;
+    return $this->history[$nid];
   }
 
   /**
@@ -480,7 +490,7 @@ public function checkNodeType(NodeInterface $node) {
   public function unreadTopics($term, $uid) {
     $query = $this->connection->select('node_field_data', 'n');
     $query->join('forum', 'f', 'n.vid = f.vid AND f.tid = :tid', [':tid' => $term]);
-    $query->leftJoin('history', 'h', 'n.nid = h.nid AND h.uid = :uid', [':uid' => $uid]);
+    $query->leftJoin('history', 'h', "n.nid = h.entity_id AND h.entity_type = 'node' AND h.uid = :uid", [':uid' => $uid]);
     $query->addExpression('COUNT(n.nid)', 'count');
     return $query
       ->condition('status', 1)
@@ -488,7 +498,7 @@ public function unreadTopics($term, $uid) {
       //   field language and just fall back to the default language.
       ->condition('n.default_langcode', 1)
       ->condition('n.created', HISTORY_READ_LIMIT, '>')
-      ->isNull('h.nid')
+      ->isNull('h.entity_id')
       ->addTag('node_access')
       ->execute()
       ->fetchField();
diff --git a/core/modules/forum/tests/src/Kernel/ForumValidationTest.php b/core/modules/forum/tests/src/Kernel/ForumValidationTest.php
index d7fef86c4b..7d33900837 100644
--- a/core/modules/forum/tests/src/Kernel/ForumValidationTest.php
+++ b/core/modules/forum/tests/src/Kernel/ForumValidationTest.php
@@ -23,6 +23,7 @@ class ForumValidationTest extends EntityKernelTestBase {
     'options',
     'comment',
     'taxonomy',
+    'history',
     'forum',
   ];
 
diff --git a/core/modules/forum/tests/src/Kernel/Migrate/d6/MigrateForumConfigsTest.php b/core/modules/forum/tests/src/Kernel/Migrate/d6/MigrateForumConfigsTest.php
index b68f2f0336..1de2038b2a 100644
--- a/core/modules/forum/tests/src/Kernel/Migrate/d6/MigrateForumConfigsTest.php
+++ b/core/modules/forum/tests/src/Kernel/Migrate/d6/MigrateForumConfigsTest.php
@@ -17,7 +17,7 @@ class MigrateForumConfigsTest extends MigrateDrupal6TestBase {
   /**
    * {@inheritdoc}
    */
-  protected static $modules = ['comment', 'forum', 'taxonomy'];
+  protected static $modules = ['comment', 'forum', 'history', 'taxonomy'];
 
   /**
    * {@inheritdoc}
diff --git a/core/modules/forum/tests/src/Kernel/Migrate/d6/MigrateForumTest.php b/core/modules/forum/tests/src/Kernel/Migrate/d6/MigrateForumTest.php
index 05c6df74b9..d76b530f83 100644
--- a/core/modules/forum/tests/src/Kernel/Migrate/d6/MigrateForumTest.php
+++ b/core/modules/forum/tests/src/Kernel/Migrate/d6/MigrateForumTest.php
@@ -22,6 +22,7 @@ class MigrateForumTest extends MigrateNodeTestBase {
   protected static $modules = [
     'comment',
     'forum',
+    'history',
     'menu_ui',
     'taxonomy',
   ];
diff --git a/core/modules/forum/tests/src/Kernel/Migrate/d7/MigrateForumSettingsTest.php b/core/modules/forum/tests/src/Kernel/Migrate/d7/MigrateForumSettingsTest.php
index 6b1ab64b3c..d440b75b8c 100644
--- a/core/modules/forum/tests/src/Kernel/Migrate/d7/MigrateForumSettingsTest.php
+++ b/core/modules/forum/tests/src/Kernel/Migrate/d7/MigrateForumSettingsTest.php
@@ -19,6 +19,7 @@ class MigrateForumSettingsTest extends MigrateDrupal7TestBase {
     'text',
     'node',
     'taxonomy',
+    'history',
     'forum',
   ];
 
diff --git a/core/modules/forum/tests/src/Unit/ForumManagerTest.php b/core/modules/forum/tests/src/Unit/ForumManagerTest.php
index 969bb71219..abb9f1bc07 100644
--- a/core/modules/forum/tests/src/Unit/ForumManagerTest.php
+++ b/core/modules/forum/tests/src/Unit/ForumManagerTest.php
@@ -4,6 +4,7 @@
 
 use Drupal\Core\Entity\EntityFieldManagerInterface;
 use Drupal\Core\Entity\EntityTypeManagerInterface;
+use Drupal\history\HistoryRepository;
 use Drupal\Tests\UnitTestCase;
 
 /**
@@ -56,6 +57,10 @@ public function testGetIndex() {
       ->disableOriginalConstructor()
       ->getMock();
 
+    $history_repository = $this->getMockBuilder(HistoryRepository::class)
+      ->disableOriginalConstructor()
+      ->getMock();
+
     $comment_manager = $this->getMockBuilder('\Drupal\comment\CommentManagerInterface')
       ->disableOriginalConstructor()
       ->getMock();
@@ -69,6 +74,7 @@ public function testGetIndex() {
         $translation_manager,
         $comment_manager,
         $entity_field_manager,
+        $history_repository,
       ])
       ->getMock();
 
diff --git a/core/modules/history/history.install b/core/modules/history/history.install
index 3020d8bc24..c2a5f221ed 100644
--- a/core/modules/history/history.install
+++ b/core/modules/history/history.install
@@ -5,21 +5,31 @@
  * Installation functions for History module.
  */
 
+use Drupal\Core\Database\Database;
+use Drupal\Core\Entity\EntityTypeInterface;
+
 /**
  * Implements hook_schema().
  */
 function history_schema() {
   $schema['history'] = [
-    'description' => 'A record of which {users} have read which {node}s.',
+    'description' => 'A record of which {users} have read which entities.',
     'fields' => [
       'uid' => [
-        'description' => 'The {users}.uid that read the {node} nid.',
+        'description' => 'The {users}.uid that read the {history}.entity_id entity.',
         'type' => 'int',
         'not null' => TRUE,
         'default' => 0,
       ],
-      'nid' => [
-        'description' => 'The {node}.nid that was read.',
+      'entity_type' => [
+        'description' => 'The type of the entity that was read.',
+        'type' => 'varchar_ascii',
+        'not null' => TRUE,
+        'default' => '',
+        'length' => EntityTypeInterface::ID_MAX_LENGTH,
+      ],
+      'entity_id' => [
+        'description' => 'The ID of the entity that was read.',
         'type' => 'int',
         'unsigned' => TRUE,
         'not null' => TRUE,
@@ -32,9 +42,9 @@ function history_schema() {
         'default' => 0,
       ],
     ],
-    'primary key' => ['uid', 'nid'],
+    'primary key' => ['entity_type', 'uid', 'entity_id'],
     'indexes' => [
-      'nid' => ['nid'],
+      'history_entity' => ['entity_type', 'entity_id'],
     ],
   ];
 
@@ -47,3 +57,70 @@ function history_schema() {
 function history_update_last_removed() {
   return 8101;
 }
+
+/**
+ * Change {history}.nid to {history}.entity_id and add {history}.entity_type.
+ */
+function history_update_9001() {
+  $database = Database::getConnection();
+  $schema = $database->schema();
+  $schema->dropPrimaryKey('history');
+  $schema->dropIndex('history', 'nid');
+  $schema->changeField('history', 'nid', 'entity_id', [
+    'description' => 'The ID of the entity that was read.',
+    'type' => 'int',
+    'unsigned' => TRUE,
+    'not null' => TRUE,
+    'default' => 0,
+  ]);
+  $schema->addField('history', 'entity_type', [
+    'description' => 'The type of the entity that was read.',
+    'type' => 'varchar_ascii',
+    'not null' => TRUE,
+    'default' => '',
+    'length' => EntityTypeInterface::ID_MAX_LENGTH,
+  ]);
+
+  // Set default value for {history}.entity_type.
+  $database->update('history')
+    ->fields(['entity_type' => 'node'])
+    ->execute();
+
+  $schema->addPrimaryKey('history', ['entity_type', 'uid', 'entity_id']);
+  $spec = [
+    'description' => 'A record of which {users} have read which entities.',
+    'fields' => [
+      'uid' => [
+        'description' => 'The {users}.uid that read the {history}.entity_id entity.',
+        'type' => 'int',
+        'not null' => TRUE,
+        'default' => 0,
+      ],
+      'entity_type' => [
+        'description' => 'The type of the entity that was read.',
+        'type' => 'varchar_ascii',
+        'not null' => TRUE,
+        'default' => '',
+        'length' => EntityTypeInterface::ID_MAX_LENGTH,
+      ],
+      'entity_id' => [
+        'description' => 'The ID of the entity that was read.',
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 0,
+      ],
+      'timestamp' => [
+        'description' => 'The Unix timestamp at which the read occurred.',
+        'type' => 'int',
+        'not null' => TRUE,
+        'default' => 0,
+      ],
+    ],
+    'primary key' => ['entity_type', 'uid', 'entity_id'],
+    'indexes' => [
+      'history_entity' => ['entity_type', 'entity_id'],
+    ],
+  ];
+  $schema->addIndex('history', 'history_entity', ['entity_type', 'entity_id'], $spec);
+}
diff --git a/core/modules/history/history.module b/core/modules/history/history.module
index a6d0f27fc9..678af14881 100644
--- a/core/modules/history/history.module
+++ b/core/modules/history/history.module
@@ -13,6 +13,8 @@
 use Drupal\Core\Entity\EntityInterface;
 use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
 use Drupal\Core\Routing\RouteMatchInterface;
+use Drupal\Core\Session\AccountInterface;
+use Drupal\node\Entity\Node;
 use Drupal\user\UserInterface;
 
 /**
@@ -44,10 +46,14 @@ function history_help($route_name, RouteMatchInterface $route_match) {
  * @return int
  *   If a node has been previously viewed by the user, the timestamp in seconds
  *   of when the last view occurred; otherwise, zero.
+ *
+ * @deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Use
+ *   \Drupal\history\HistoryRepositoryInterface::getLastViewed() instead.
+ * @see https://www.drupal.org/node/2197189
  */
 function history_read($nid) {
-  $history = history_read_multiple([$nid]);
-  return $history[$nid];
+  $timestamps = \Drupal::service('history.repository')->getLastViewed('node', [$nid]);
+  return $timestamps[$nid];
 }
 
 /**
@@ -60,37 +66,13 @@ function history_read($nid) {
  *   Array of timestamps keyed by node ID. If a node has been previously viewed
  *   by the user, the timestamp in seconds of when the last view occurred;
  *   otherwise, zero.
+ *
+ * @deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Use
+ *   \Drupal\history\HistoryRepositoryInterface::getLastViewed() instead.
+ * @see https://www.drupal.org/node/2197189
  */
 function history_read_multiple($nids) {
-  $history = &drupal_static(__FUNCTION__, []);
-
-  $return = [];
-
-  $nodes_to_read = [];
-  foreach ($nids as $nid) {
-    if (isset($history[$nid])) {
-      $return[$nid] = $history[$nid];
-    }
-    else {
-      // Initialize value if current user has not viewed the node.
-      $nodes_to_read[$nid] = 0;
-    }
-  }
-
-  if (empty($nodes_to_read)) {
-    return $return;
-  }
-
-  $result = \Drupal::database()->query('SELECT nid, timestamp FROM {history} WHERE uid = :uid AND nid IN ( :nids[] )', [
-    ':uid' => \Drupal::currentUser()->id(),
-    ':nids[]' => array_keys($nodes_to_read),
-  ]);
-  foreach ($result as $row) {
-    $nodes_to_read[$row->nid] = (int) $row->timestamp;
-  }
-  $history += $nodes_to_read;
-
-  return $return + $nodes_to_read;
+  return \Drupal::service('history.repository')->getLastViewed('node', $nids);
 }
 
 /**
@@ -98,27 +80,23 @@ function history_read_multiple($nids) {
  *
  * @param $nid
  *   The node ID that has been read.
- * @param $account
+ * @param \Drupal\Core\Session\AccountInterface $account
  *   (optional) The user account to update the history for. Defaults to the
  *   current user.
+ *
+ * @deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Use
+ *   \Drupal\history\HistoryRepositoryInterface::updateLastViewed() instead.
+ * @see https://www.drupal.org/node/2197189
  */
-function history_write($nid, $account = NULL) {
+function history_write($nid, AccountInterface $account = NULL) {
 
   if (!isset($account)) {
     $account = \Drupal::currentUser();
   }
 
   if ($account->isAuthenticated()) {
-    \Drupal::database()->merge('history')
-      ->keys([
-        'uid' => $account->id(),
-        'nid' => $nid,
-      ])
-      ->fields(['timestamp' => REQUEST_TIME])
-      ->execute();
-    // Update static cache.
-    $history = &drupal_static('history_read_multiple', []);
-    $history[$nid] = REQUEST_TIME;
+    $node = Node::load($nid);
+    \Drupal::service('history.repository')->updateLastViewed($node);
   }
 }
 
@@ -126,9 +104,7 @@ function history_write($nid, $account = NULL) {
  * Implements hook_cron().
  */
 function history_cron() {
-  \Drupal::database()->delete('history')
-    ->condition('timestamp', HISTORY_READ_LIMIT, '<')
-    ->execute();
+  \Drupal::service('history.repository')->purge();
 }
 
 /**
@@ -153,9 +129,7 @@ function history_node_view_alter(array &$build, EntityInterface $node, EntityVie
  * Implements hook_ENTITY_TYPE_delete() for node entities.
  */
 function history_node_delete(EntityInterface $node) {
-  \Drupal::database()->delete('history')
-    ->condition('nid', $node->id())
-    ->execute();
+  \Drupal::service('history.repository')->deleteByEntity($node);
 }
 
 /**
@@ -164,9 +138,7 @@ function history_node_delete(EntityInterface $node) {
 function history_user_cancel($edit, UserInterface $account, $method) {
   switch ($method) {
     case 'user_cancel_reassign':
-      \Drupal::database()->delete('history')
-        ->condition('uid', $account->id())
-        ->execute();
+      \Drupal::service('history.repository')->deleteByUser($account);
       break;
   }
 }
@@ -175,7 +147,5 @@ function history_user_cancel($edit, UserInterface $account, $method) {
  * Implements hook_ENTITY_TYPE_delete() for user entities.
  */
 function history_user_delete($account) {
-  \Drupal::database()->delete('history')
-    ->condition('uid', $account->id())
-    ->execute();
+  \Drupal::service('history.repository')->deleteByUser($account);
 }
diff --git a/core/modules/history/history.views.inc b/core/modules/history/history.views.inc
index 60c95cd868..4df607754f 100644
--- a/core/modules/history/history.views.inc
+++ b/core/modules/history/history.views.inc
@@ -22,8 +22,9 @@ function history_views_data() {
     'node_field_data' => [
       'table' => 'history',
       'left_field' => 'nid',
-      'field' => 'nid',
+      'field' => 'entity_id',
       'extra' => [
+        ['field' => 'entity_type', 'value' => 'node'],
         ['field' => 'uid', 'value' => '***CURRENT_USER***', 'numeric' => TRUE],
       ],
     ],
diff --git a/core/modules/history/src/Controller/HistoryController.php b/core/modules/history/src/Controller/HistoryController.php
index c6a4834903..f95d9efb20 100644
--- a/core/modules/history/src/Controller/HistoryController.php
+++ b/core/modules/history/src/Controller/HistoryController.php
@@ -2,6 +2,7 @@
 
 namespace Drupal\history\Controller;
 
+use Symfony\Component\DependencyInjection\ContainerInterface;
 use Symfony\Component\HttpFoundation\Request;
 use Symfony\Component\HttpFoundation\JsonResponse;
 use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
@@ -14,6 +15,22 @@
  */
 class HistoryController extends ControllerBase {
 
+  /**
+   * The history repository service.
+   *
+   * @var \Drupal\history\HistoryRepositoryInterface
+   */
+  protected $historyRepository;
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function create(ContainerInterface $container) {
+    $instance = parent::create($container);
+    $instance->historyRepository = $container->get('history.repository');
+    return $instance;
+  }
+
   /**
    * Returns a set of nodes' last read timestamps.
    *
@@ -32,7 +49,7 @@ public function getNodeReadTimestamps(Request $request) {
     if (!isset($nids)) {
       throw new NotFoundHttpException();
     }
-    return new JsonResponse(history_read_multiple($nids));
+    return new JsonResponse($this->historyRepository->getLastViewed('node', $nids));
   }
 
   /**
@@ -42,6 +59,8 @@ public function getNodeReadTimestamps(Request $request) {
    *   The request of the page.
    * @param \Drupal\node\NodeInterface $node
    *   The node whose "last read" timestamp should be updated.
+   *
+   * @return \Symfony\Component\HttpFoundation\JsonResponse
    */
   public function readNode(Request $request, NodeInterface $node) {
     if ($this->currentUser()->isAnonymous()) {
@@ -49,9 +68,10 @@ public function readNode(Request $request, NodeInterface $node) {
     }
 
     // Update the history table, stating that this user viewed this node.
-    history_write($node->id());
-
-    return new JsonResponse((int) history_read($node->id()));
+    $timestamps = $this->historyRepository
+      ->updateLastViewed($node)
+      ->getLastViewed('node', [$node->id()]);
+    return new JsonResponse($timestamps[$node->id()]);
   }
 
 }
diff --git a/core/modules/history/src/HistoryRenderCallback.php b/core/modules/history/src/HistoryRenderCallback.php
index c6a92eda68..982709d397 100644
--- a/core/modules/history/src/HistoryRenderCallback.php
+++ b/core/modules/history/src/HistoryRenderCallback.php
@@ -20,7 +20,8 @@ class HistoryRenderCallback implements RenderCallbackInterface {
    */
   public static function lazyBuilder($node_id) {
     $element = [];
-    $element['#attached']['drupalSettings']['history']['lastReadTimestamps'][$node_id] = (int) history_read($node_id);
+    $timestamps = \Drupal::service('history.repository')->getLastViewed('node', [$node_id], \Drupal::currentUser());
+    $element['#attached']['drupalSettings']['history']['lastReadTimestamps'][$node_id] = (int) $timestamps[$node_id];
     return $element;
   }
 
diff --git a/core/modules/history/tests/src/Kernel/Views/HistoryTimestampTest.php b/core/modules/history/tests/src/Kernel/Views/HistoryTimestampTest.php
index ddcb064c0f..a422d41a74 100644
--- a/core/modules/history/tests/src/Kernel/Views/HistoryTimestampTest.php
+++ b/core/modules/history/tests/src/Kernel/Views/HistoryTimestampTest.php
@@ -72,14 +72,16 @@ public function testHandlers() {
     $connection->insert('history')
       ->fields([
         'uid' => $account->id(),
-        'nid' => $nodes[0]->id(),
+        'entity_id' => $nodes[0]->id(),
+        'entity_type' => 'node',
         'timestamp' => REQUEST_TIME - 100,
       ])->execute();
 
     $connection->insert('history')
       ->fields([
         'uid' => $account->id(),
-        'nid' => $nodes[1]->id(),
+        'entity_id' => $nodes[1]->id(),
+        'entity_type' => 'node',
         'timestamp' => REQUEST_TIME + 100,
       ])->execute();
 
diff --git a/core/modules/language/tests/src/Kernel/Migrate/d6/MigrateLanguageContentCommentSettingsTest.php b/core/modules/language/tests/src/Kernel/Migrate/d6/MigrateLanguageContentCommentSettingsTest.php
index 0bddd96ae0..03696accf0 100644
--- a/core/modules/language/tests/src/Kernel/Migrate/d6/MigrateLanguageContentCommentSettingsTest.php
+++ b/core/modules/language/tests/src/Kernel/Migrate/d6/MigrateLanguageContentCommentSettingsTest.php
@@ -17,6 +17,7 @@ class MigrateLanguageContentCommentSettingsTest extends MigrateDrupal6TestBase {
    */
   protected static $modules = [
     'comment',
+    'history',
     'language',
     'content_translation',
   ];
diff --git a/core/modules/language/tests/src/Kernel/Migrate/d7/MigrateLanguageContentCommentSettingsNoEntityTranslationTest.php b/core/modules/language/tests/src/Kernel/Migrate/d7/MigrateLanguageContentCommentSettingsNoEntityTranslationTest.php
index 44907518c4..64c3bf8f9e 100644
--- a/core/modules/language/tests/src/Kernel/Migrate/d7/MigrateLanguageContentCommentSettingsNoEntityTranslationTest.php
+++ b/core/modules/language/tests/src/Kernel/Migrate/d7/MigrateLanguageContentCommentSettingsNoEntityTranslationTest.php
@@ -21,6 +21,7 @@ class MigrateLanguageContentCommentSettingsNoEntityTranslationTest extends Migra
   protected static $modules = [
     'comment',
     'content_translation',
+    'history',
     'language',
     'node',
     'text',
diff --git a/core/modules/language/tests/src/Kernel/Migrate/d7/MigrateLanguageContentCommentSettingsTest.php b/core/modules/language/tests/src/Kernel/Migrate/d7/MigrateLanguageContentCommentSettingsTest.php
index 216283b916..2b84298ef5 100644
--- a/core/modules/language/tests/src/Kernel/Migrate/d7/MigrateLanguageContentCommentSettingsTest.php
+++ b/core/modules/language/tests/src/Kernel/Migrate/d7/MigrateLanguageContentCommentSettingsTest.php
@@ -18,6 +18,7 @@ class MigrateLanguageContentCommentSettingsTest extends MigrateDrupal7TestBase {
   protected static $modules = [
     'comment',
     'content_translation',
+    'history',
     'language',
     'node',
     'text',
diff --git a/core/modules/migrate/tests/src/Kernel/Plugin/MigrationPluginListTest.php b/core/modules/migrate/tests/src/Kernel/Plugin/MigrationPluginListTest.php
index 10ed8755cf..248cdc7bee 100644
--- a/core/modules/migrate/tests/src/Kernel/Plugin/MigrationPluginListTest.php
+++ b/core/modules/migrate/tests/src/Kernel/Plugin/MigrationPluginListTest.php
@@ -39,6 +39,7 @@ class MigrationPluginListTest extends KernelTestBase {
     'file',
     'filter',
     'forum',
+    'history',
     'image',
     'language',
     'locale',
diff --git a/core/modules/migrate_drupal/tests/src/Kernel/d6/FieldDiscoveryTest.php b/core/modules/migrate_drupal/tests/src/Kernel/d6/FieldDiscoveryTest.php
index f4af3d508d..7882c63b7d 100644
--- a/core/modules/migrate_drupal/tests/src/Kernel/d6/FieldDiscoveryTest.php
+++ b/core/modules/migrate_drupal/tests/src/Kernel/d6/FieldDiscoveryTest.php
@@ -26,6 +26,7 @@ class FieldDiscoveryTest extends MigrateDrupal6TestBase {
     'comment',
     'datetime',
     'file',
+    'history',
     'image',
     'link',
     'node',
diff --git a/core/modules/migrate_drupal/tests/src/Kernel/d7/FieldDiscoveryTest.php b/core/modules/migrate_drupal/tests/src/Kernel/d7/FieldDiscoveryTest.php
index ccbcde606c..b3c973c0b5 100644
--- a/core/modules/migrate_drupal/tests/src/Kernel/d7/FieldDiscoveryTest.php
+++ b/core/modules/migrate_drupal/tests/src/Kernel/d7/FieldDiscoveryTest.php
@@ -29,6 +29,7 @@ class FieldDiscoveryTest extends MigrateDrupal7TestBase {
     'comment',
     'datetime',
     'file',
+    'history',
     'image',
     'link',
     'node',
diff --git a/core/modules/migrate_drupal/tests/src/Kernel/d7/FollowUpMigrationsTest.php b/core/modules/migrate_drupal/tests/src/Kernel/d7/FollowUpMigrationsTest.php
index cc0b309566..cc39e1472f 100644
--- a/core/modules/migrate_drupal/tests/src/Kernel/d7/FollowUpMigrationsTest.php
+++ b/core/modules/migrate_drupal/tests/src/Kernel/d7/FollowUpMigrationsTest.php
@@ -21,6 +21,7 @@ class FollowUpMigrationsTest extends MigrateDrupal7TestBase {
     'content_translation',
     'comment',
     'datetime',
+    'history',
     'image',
     'language',
     'link',
diff --git a/core/modules/migrate_drupal/tests/src/Kernel/dependencies/MigrateDependenciesTest.php b/core/modules/migrate_drupal/tests/src/Kernel/dependencies/MigrateDependenciesTest.php
index c080f33e3d..5a73200acb 100644
--- a/core/modules/migrate_drupal/tests/src/Kernel/dependencies/MigrateDependenciesTest.php
+++ b/core/modules/migrate_drupal/tests/src/Kernel/dependencies/MigrateDependenciesTest.php
@@ -17,7 +17,7 @@ class MigrateDependenciesTest extends MigrateDrupal6TestBase {
   /**
    * {@inheritdoc}
    */
-  protected static $modules = ['aggregator', 'comment'];
+  protected static $modules = ['aggregator', 'comment', 'history'];
 
   /**
    * Tests that the order is correct when loading several migrations.
diff --git a/core/modules/node/tests/src/Kernel/Migrate/d7/MigrateNodeCompleteTest.php b/core/modules/node/tests/src/Kernel/Migrate/d7/MigrateNodeCompleteTest.php
index 153fd185da..b1129f8038 100644
--- a/core/modules/node/tests/src/Kernel/Migrate/d7/MigrateNodeCompleteTest.php
+++ b/core/modules/node/tests/src/Kernel/Migrate/d7/MigrateNodeCompleteTest.php
@@ -28,6 +28,7 @@ class MigrateNodeCompleteTest extends MigrateDrupal7TestBase {
     'content_translation',
     'comment',
     'datetime',
+    'history',
     'image',
     'language',
     'link',
@@ -60,6 +61,7 @@ protected function setUp(): void {
 
     $this->installEntitySchema('comment');
     $this->installEntitySchema('taxonomy_term');
+    $this->installSchema('history', ['history']);
     $this->installSchema('comment', ['comment_entity_statistics']);
     $this->installSchema('node', ['node_access']);
     $this->installSchema('system', ['sequences']);
diff --git a/core/modules/node/tests/src/Kernel/Migrate/d7/MigrateNodeRevisionTest.php b/core/modules/node/tests/src/Kernel/Migrate/d7/MigrateNodeRevisionTest.php
index 0af06a0f20..62eb5bdd17 100644
--- a/core/modules/node/tests/src/Kernel/Migrate/d7/MigrateNodeRevisionTest.php
+++ b/core/modules/node/tests/src/Kernel/Migrate/d7/MigrateNodeRevisionTest.php
@@ -31,6 +31,7 @@ class MigrateNodeRevisionTest extends MigrateDrupal7TestBase {
     'datetime',
     'file',
     'filter',
+    'history',
     'image',
     'language',
     'link',
diff --git a/core/modules/node/tests/src/Kernel/Migrate/d7/MigrateNodeTest.php b/core/modules/node/tests/src/Kernel/Migrate/d7/MigrateNodeTest.php
index 4428bb906e..66358a47c3 100644
--- a/core/modules/node/tests/src/Kernel/Migrate/d7/MigrateNodeTest.php
+++ b/core/modules/node/tests/src/Kernel/Migrate/d7/MigrateNodeTest.php
@@ -25,6 +25,7 @@ class MigrateNodeTest extends MigrateDrupal7TestBase {
     'content_translation',
     'comment',
     'datetime',
+    'history',
     'image',
     'language',
     'link',
diff --git a/core/modules/rdf/tests/src/Kernel/Plugin/migrate/source/d7/RdfMappingTest.php b/core/modules/rdf/tests/src/Kernel/Plugin/migrate/source/d7/RdfMappingTest.php
index 84a2e3b43c..7f11a456ea 100644
--- a/core/modules/rdf/tests/src/Kernel/Plugin/migrate/source/d7/RdfMappingTest.php
+++ b/core/modules/rdf/tests/src/Kernel/Plugin/migrate/source/d7/RdfMappingTest.php
@@ -18,6 +18,7 @@ class RdfMappingTest extends MigrateSqlSourceTestBase {
    */
   protected static $modules = [
     'comment',
+    'history',
     'migrate_drupal',
     'node',
     'rdf',
diff --git a/core/modules/rdf/tests/src/Kernel/RdfCommentStorageLoadTest.php b/core/modules/rdf/tests/src/Kernel/RdfCommentStorageLoadTest.php
index 011676c324..ef6fcda241 100644
--- a/core/modules/rdf/tests/src/Kernel/RdfCommentStorageLoadTest.php
+++ b/core/modules/rdf/tests/src/Kernel/RdfCommentStorageLoadTest.php
@@ -17,7 +17,7 @@ class RdfCommentStorageLoadTest extends EntityKernelTestBase {
   /**
    * {@inheritdoc}
    */
-  protected static $modules = ['comment', 'rdf'];
+  protected static $modules = ['comment', 'history', 'rdf'];
 
   /**
    * Tests rdf_comment_storage_load.
diff --git a/core/modules/system/tests/src/Functional/Entity/EntityReferenceSelection/EntityReferenceSelectionAccessTest.php b/core/modules/system/tests/src/Functional/Entity/EntityReferenceSelection/EntityReferenceSelectionAccessTest.php
index 89c7b7dbc3..e92b8335de 100644
--- a/core/modules/system/tests/src/Functional/Entity/EntityReferenceSelection/EntityReferenceSelectionAccessTest.php
+++ b/core/modules/system/tests/src/Functional/Entity/EntityReferenceSelection/EntityReferenceSelectionAccessTest.php
@@ -40,6 +40,7 @@ class EntityReferenceSelectionAccessTest extends KernelTestBase {
     'comment',
     'field',
     'file',
+    'history',
     'image',
     'node',
     'media',
diff --git a/core/modules/taxonomy/tests/src/Kernel/Migrate/d7/MigrateNodeTaxonomyTest.php b/core/modules/taxonomy/tests/src/Kernel/Migrate/d7/MigrateNodeTaxonomyTest.php
index 2f323eccd2..1a8ee81e0d 100644
--- a/core/modules/taxonomy/tests/src/Kernel/Migrate/d7/MigrateNodeTaxonomyTest.php
+++ b/core/modules/taxonomy/tests/src/Kernel/Migrate/d7/MigrateNodeTaxonomyTest.php
@@ -14,6 +14,7 @@ class MigrateNodeTaxonomyTest extends MigrateDrupal7TestBase {
   protected static $modules = [
     'comment',
     'datetime',
+    'history',
     'image',
     'link',
     'menu_ui',
diff --git a/core/modules/taxonomy/tests/src/Kernel/Migrate/d7/MigrateTaxonomyTermTest.php b/core/modules/taxonomy/tests/src/Kernel/Migrate/d7/MigrateTaxonomyTermTest.php
index de22f1db94..47fb083f73 100644
--- a/core/modules/taxonomy/tests/src/Kernel/Migrate/d7/MigrateTaxonomyTermTest.php
+++ b/core/modules/taxonomy/tests/src/Kernel/Migrate/d7/MigrateTaxonomyTermTest.php
@@ -17,6 +17,7 @@ class MigrateTaxonomyTermTest extends MigrateDrupal7TestBase {
     'comment',
     'content_translation',
     'datetime',
+    'history',
     'image',
     'language',
     'link',
diff --git a/core/modules/taxonomy/tests/src/Kernel/Migrate/d7/MigrateTaxonomyTermTranslationTest.php b/core/modules/taxonomy/tests/src/Kernel/Migrate/d7/MigrateTaxonomyTermTranslationTest.php
index 89390302a4..cd50ab3e8b 100644
--- a/core/modules/taxonomy/tests/src/Kernel/Migrate/d7/MigrateTaxonomyTermTranslationTest.php
+++ b/core/modules/taxonomy/tests/src/Kernel/Migrate/d7/MigrateTaxonomyTermTranslationTest.php
@@ -20,6 +20,7 @@ class MigrateTaxonomyTermTranslationTest extends MigrateDrupal7TestBase {
     'comment',
     'content_translation',
     'datetime',
+    'history',
     'image',
     'language',
     'link',
diff --git a/core/modules/user/tests/src/Kernel/Migrate/d7/MigrateUserTest.php b/core/modules/user/tests/src/Kernel/Migrate/d7/MigrateUserTest.php
index 179d80e0c8..631e385490 100644
--- a/core/modules/user/tests/src/Kernel/Migrate/d7/MigrateUserTest.php
+++ b/core/modules/user/tests/src/Kernel/Migrate/d7/MigrateUserTest.php
@@ -22,6 +22,7 @@ class MigrateUserTest extends MigrateDrupal7TestBase {
     'comment',
     'content_translation',
     'datetime',
+    'history',
     'image',
     'language',
     'link',
diff --git a/core/modules/views/tests/src/Kernel/Entity/ViewEntityDependenciesTest.php b/core/modules/views/tests/src/Kernel/Entity/ViewEntityDependenciesTest.php
index 0c52a1452a..ff547175d4 100644
--- a/core/modules/views/tests/src/Kernel/Entity/ViewEntityDependenciesTest.php
+++ b/core/modules/views/tests/src/Kernel/Entity/ViewEntityDependenciesTest.php
@@ -32,6 +32,7 @@ class ViewEntityDependenciesTest extends ViewsKernelTestBase {
   protected static $modules = [
     'node',
     'comment',
+    'history',
     'user',
     'field',
     'text',
diff --git a/core/modules/views/tests/src/Kernel/ViewExecutableTest.php b/core/modules/views/tests/src/Kernel/ViewExecutableTest.php
index 30efd0dd49..8c87f820b3 100644
--- a/core/modules/views/tests/src/Kernel/ViewExecutableTest.php
+++ b/core/modules/views/tests/src/Kernel/ViewExecutableTest.php
@@ -37,6 +37,7 @@ class ViewExecutableTest extends ViewsKernelTestBase {
     'system',
     'node',
     'comment',
+    'history',
     'user',
     'filter',
     'field',
diff --git a/core/tests/Drupal/KernelTests/Core/Entity/CreateSampleEntityTest.php b/core/tests/Drupal/KernelTests/Core/Entity/CreateSampleEntityTest.php
index ca1eedd52c..3a6017dc8d 100644
--- a/core/tests/Drupal/KernelTests/Core/Entity/CreateSampleEntityTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Entity/CreateSampleEntityTest.php
@@ -30,6 +30,7 @@ class CreateSampleEntityTest extends KernelTestBase {
     'system',
     'field',
     'filter',
+    'history',
     'text',
     'file',
     'user',
diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityCrudHookTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityCrudHookTest.php
index c829d7b40c..a7cf38f04f 100644
--- a/core/tests/Drupal/KernelTests/Core/Entity/EntityCrudHookTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityCrudHookTest.php
@@ -48,6 +48,7 @@ class EntityCrudHookTest extends EntityKernelTestBase {
     'taxonomy',
     'node',
     'comment',
+    'history',
   ];
 
   protected $ids = [];
@@ -58,6 +59,7 @@ protected function setUp(): void {
     $this->installSchema('user', ['users_data']);
     $this->installSchema('file', ['file_usage']);
     $this->installSchema('node', ['node_access']);
+    $this->installSchema('history', ['history']);
     $this->installSchema('comment', ['comment_entity_statistics']);
     $this->installConfig(['node', 'comment']);
   }
diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityDeriverTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityDeriverTest.php
index cdee2f30f7..391b2b1fd1 100644
--- a/core/tests/Drupal/KernelTests/Core/Entity/EntityDeriverTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityDeriverTest.php
@@ -33,6 +33,7 @@ class EntityDeriverTest extends KernelTestBase {
     'node',
     'comment',
     'entity_test',
+    'history',
   ];
 
   /**
diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityDisplayBaseTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityDisplayBaseTest.php
index 435d2fdd56..ccd9345259 100644
--- a/core/tests/Drupal/KernelTests/Core/Entity/EntityDisplayBaseTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityDisplayBaseTest.php
@@ -24,6 +24,7 @@ class EntityDisplayBaseTest extends KernelTestBase {
     'field',
     'system',
     'comment',
+    'history',
     'user',
   ];
 
