aboutsummaryrefslogtreecommitdiffhomepage
path: root/application
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2017-10-28 12:44:44 +0200
committerGitHub <noreply@github.com>2017-10-28 12:44:44 +0200
commit0926d263902c184bd4f4c2036cb8ee90f81c5060 (patch)
treef326e180aee99881725e5e2abf5a4c13e323e964 /application
parent88d38cb290aad669ad1406e2362d85c81e46d4f6 (diff)
parent9ec0a61156192484ca90a8dc88b7c23b26129755 (diff)
downloadShaarli-0926d263902c184bd4f4c2036cb8ee90f81c5060.tar.gz
Shaarli-0926d263902c184bd4f4c2036cb8ee90f81c5060.tar.zst
Shaarli-0926d263902c184bd4f4c2036cb8ee90f81c5060.zip
Merge pull request #962 from ArthurHoaro/feature/perfs2
Performances: reorder links when they're written instead of read
Diffstat (limited to 'application')
-rw-r--r--application/LinkDB.php17
-rw-r--r--application/Updater.php8
2 files changed, 16 insertions, 9 deletions
diff --git a/application/LinkDB.php b/application/LinkDB.php
index f026a041..c1661d52 100644
--- a/application/LinkDB.php
+++ b/application/LinkDB.php
@@ -289,13 +289,15 @@ You use the community supported version of the original Shaarli project, by Seba
289 return; 289 return;
290 } 290 }
291 291
292 $this->urls = [];
293 $this->ids = [];
292 $this->links = FileUtils::readFlatDB($this->datastore, []); 294 $this->links = FileUtils::readFlatDB($this->datastore, []);
293 295
294 $toremove = array(); 296 $toremove = array();
295 foreach ($this->links as $key => &$link) { 297 foreach ($this->links as $key => &$link) {
296 if (! $this->loggedIn && $link['private'] != 0) { 298 if (! $this->loggedIn && $link['private'] != 0) {
297 // Transition for not upgraded databases. 299 // Transition for not upgraded databases.
298 $toremove[] = $key; 300 unset($this->links[$key]);
299 continue; 301 continue;
300 } 302 }
301 303
@@ -329,14 +331,10 @@ You use the community supported version of the original Shaarli project, by Seba
329 } 331 }
330 $link['shorturl'] = smallHash($link['linkdate']); 332 $link['shorturl'] = smallHash($link['linkdate']);
331 } 333 }
332 }
333 334
334 // If user is not logged in, filter private links. 335 $this->urls[$link['url']] = $key;
335 foreach ($toremove as $offset) { 336 $this->ids[$link['id']] = $key;
336 unset($this->links[$offset]);
337 } 337 }
338
339 $this->reorder();
340 } 338 }
341 339
342 /** 340 /**
@@ -346,6 +344,7 @@ You use the community supported version of the original Shaarli project, by Seba
346 */ 344 */
347 private function write() 345 private function write()
348 { 346 {
347 $this->reorder();
349 FileUtils::writeFlatDB($this->datastore, $this->links); 348 FileUtils::writeFlatDB($this->datastore, $this->links);
350 } 349 }
351 350
@@ -528,8 +527,8 @@ You use the community supported version of the original Shaarli project, by Seba
528 return $a['created'] < $b['created'] ? 1 * $order : -1 * $order; 527 return $a['created'] < $b['created'] ? 1 * $order : -1 * $order;
529 }); 528 });
530 529
531 $this->urls = array(); 530 $this->urls = [];
532 $this->ids = array(); 531 $this->ids = [];
533 foreach ($this->links as $key => $link) { 532 foreach ($this->links as $key => $link) {
534 $this->urls[$link['url']] = $key; 533 $this->urls[$link['url']] = $key;
535 $this->ids[$link['id']] = $key; 534 $this->ids[$link['id']] = $key;
diff --git a/application/Updater.php b/application/Updater.php
index 723a7a81..bc859536 100644
--- a/application/Updater.php
+++ b/application/Updater.php
@@ -436,6 +436,14 @@ class Updater
436 } 436 }
437 return true; 437 return true;
438 } 438 }
439
440 /**
441 * Save the datastore -> the link order is now applied when links are saved.
442 */
443 public function updateMethodReorderDatastore()
444 {
445 $this->linkDB->save($this->conf->get('resource.page_cache'));
446 }
439} 447}
440 448
441/** 449/**