diff --git a/core/modules/views/src/Plugin/views/pager/Mini.php b/core/modules/views/src/Plugin/views/pager/Mini.php
index 5f1750e..c0e425c 100644
--- a/core/modules/views/src/Plugin/views/pager/Mini.php
+++ b/core/modules/views/src/Plugin/views/pager/Mini.php
@@ -56,6 +56,14 @@ public function query() {
       $limit += 1;
       $this->view->query->setLimit($limit);
     }
+
+    // Determine whether we need to calculate the total results.
+    $results = array_merge($this->view->header, $this->view->footer);
+    foreach ($results as $result) {
+      if (strpos($result->options['content'], '@total') !== FALSE) {
+        $this->view->get_total_rows = TRUE;
+      }
+    }
   }
 
   /**
@@ -69,14 +77,19 @@ public function useCountQuery() {
    * {@inheritdoc}
    */
   public function postExecute(&$result) {
-    // In query() one more item might have been retrieved than necessary. If so,
-    // the next link needs to be displayed and the item removed.
     if ($this->getItemsPerPage() > 0 && count($result) > $this->getItemsPerPage()) {
+      // In query() one more item might have been retrieved than necessary. If so,
+      // the next link needs to be displayed and the item removed.
       array_pop($result);
-      // Make sure the pager shows the next link by setting the total items to
-      // the biggest possible number but prevent failing calculations like
-      // ceil(PHP_INT_MAX) we take PHP_INT_MAX / 2.
-      $total = PHP_INT_MAX / 2;
+      if ($this->view->get_total_rows) {
+        $total = $this->view->pager->total_items;
+      }
+      else {
+        // Make sure the pager shows the next link by setting the total items to
+        // the biggest possible number but prevent failing calculations like
+        // ceil(PHP_INT_MAX) we take PHP_INT_MAX / 2.
+        $total = PHP_INT_MAX / 2;
+      }
     }
     else {
       $total = $this->getCurrentPage() * $this->getItemsPerPage() + count($result);
