]> git.immae.eu Git - github/shaarli/Shaarli.git/blobdiff - application/History.php
History: lazy loading for the history file
[github/shaarli/Shaarli.git] / application / History.php
index c06067df80ca454bf0b8d3647e2f2d2b2cc3b35f..f93b03568235c1f71ecc7d9d86b21e0a56fab34b 100644 (file)
@@ -70,6 +70,15 @@ class History
         if ($retentionTime !== null) {
             $this->retentionTime = $retentionTime;
         }
+    }
+
+    /**
+     * Initialize: read history file.
+     *
+     * Allow lazy loading (don't read the file if it isn't necessary).
+     */
+    protected function initialize()
+    {
         $this->check();
         $this->read();
     }
@@ -120,6 +129,10 @@ class History
      */
     protected function addEvent($status, $id = null)
     {
+        if ($this->history === null) {
+            $this->initialize();
+        }
+
         $item = [
             'event' => $status,
             'datetime' => (new DateTime())->format(DateTime::ATOM),
@@ -178,6 +191,10 @@ class History
      */
     public function getHistory()
     {
+        if ($this->history === null) {
+            $this->initialize();
+        }
+
         return $this->history;
     }
 }