aboutsummaryrefslogtreecommitdiffhomepage
path: root/application
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2017-01-16 12:50:36 +0100
committerArthurHoaro <arthur@hoa.ro>2017-03-21 20:29:20 +0100
commitd16ca2e22f3d7325fc9593fccd8523eebe226567 (patch)
treea1e5fb646ec69240fd882269a2c85a452e081833 /application
parent4306b184c4471825f916d895b047ed03fdf58985 (diff)
downloadShaarli-d16ca2e22f3d7325fc9593fccd8523eebe226567.tar.gz
Shaarli-d16ca2e22f3d7325fc9593fccd8523eebe226567.tar.zst
Shaarli-d16ca2e22f3d7325fc9593fccd8523eebe226567.zip
History: lazy loading for the history file
Only read it when it's necessary
Diffstat (limited to 'application')
-rw-r--r--application/History.php17
1 files changed, 17 insertions, 0 deletions
diff --git a/application/History.php b/application/History.php
index c06067df..f93b0356 100644
--- a/application/History.php
+++ b/application/History.php
@@ -70,6 +70,15 @@ class History
70 if ($retentionTime !== null) { 70 if ($retentionTime !== null) {
71 $this->retentionTime = $retentionTime; 71 $this->retentionTime = $retentionTime;
72 } 72 }
73 }
74
75 /**
76 * Initialize: read history file.
77 *
78 * Allow lazy loading (don't read the file if it isn't necessary).
79 */
80 protected function initialize()
81 {
73 $this->check(); 82 $this->check();
74 $this->read(); 83 $this->read();
75 } 84 }
@@ -120,6 +129,10 @@ class History
120 */ 129 */
121 protected function addEvent($status, $id = null) 130 protected function addEvent($status, $id = null)
122 { 131 {
132 if ($this->history === null) {
133 $this->initialize();
134 }
135
123 $item = [ 136 $item = [
124 'event' => $status, 137 'event' => $status,
125 'datetime' => (new DateTime())->format(DateTime::ATOM), 138 'datetime' => (new DateTime())->format(DateTime::ATOM),
@@ -178,6 +191,10 @@ class History
178 */ 191 */
179 public function getHistory() 192 public function getHistory()
180 { 193 {
194 if ($this->history === null) {
195 $this->initialize();
196 }
197
181 return $this->history; 198 return $this->history;
182 } 199 }
183} 200}