]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
Merge pull request #962 from ArthurHoaro/feature/perfs2
authorArthurHoaro <arthur@hoa.ro>
Sat, 28 Oct 2017 10:44:44 +0000 (12:44 +0200)
committerGitHub <noreply@github.com>
Sat, 28 Oct 2017 10:44:44 +0000 (12:44 +0200)
Performances: reorder links when they're written instead of read

1  2 
application/LinkDB.php
application/Updater.php

diff --combined application/LinkDB.php
index f026a0418b98335ae861100968f3104f6f76a7b9,eace625eed517f840fbd8cdd65516c66b4d7d966..c1661d52c972970e34f26b156f60b3012dd3cb97
@@@ -133,16 -133,16 +133,16 @@@ class LinkDB implements Iterator, Count
      {
          // TODO: use exceptions instead of "die"
          if (!$this->loggedIn) {
 -            die('You are not authorized to add a link.');
 +            die(t('You are not authorized to add a link.'));
          }
          if (!isset($value['id']) || empty($value['url'])) {
 -            die('Internal Error: A link should always have an id and URL.');
 +            die(t('Internal Error: A link should always have an id and URL.'));
          }
          if (($offset !== null && ! is_int($offset)) || ! is_int($value['id'])) {
 -            die('You must specify an integer as a key.');
 +            die(t('You must specify an integer as a key.'));
          }
          if ($offset !== null && $offset !== $value['id']) {
 -            die('Array offset and link ID must be equal.');
 +            die(t('Array offset and link ID must be equal.'));
          }
  
          // If the link exists, we reuse the real offset, otherwise new entry
          $this->links = array();
          $link = array(
              'id' => 1,
 -            'title'=>' Shaarli: the personal, minimalist, super-fast, no-database delicious clone',
 +            'title'=> t('The personal, minimalist, super-fast, database free, bookmarking service'),
              'url'=>'https://shaarli.readthedocs.io',
 -            'description'=>'Welcome to Shaarli! This is your first public bookmark. To edit or delete me, you must first login.
 +            'description'=>t('Welcome to Shaarli! This is your first public bookmark. To edit or delete me, you must first login.
  
 -To learn how to use Shaarli, consult the link "Help/documentation" at the bottom of this page.
 +To learn how to use Shaarli, consult the link "Documentation" at the bottom of this page.
  
 -You use the community supported version of the original Shaarli project, by Sebastien Sauvage.',
 +You use the community supported version of the original Shaarli project, by Sebastien Sauvage.'),
              'private'=>0,
              'created'=> new DateTime(),
              'tags'=>'opensource software'
  
          $link = array(
              'id' => 0,
 -            'title'=>'My secret stuff... - Pastebin.com',
 +            'title'=> t('My secret stuff... - Pastebin.com'),
              'url'=>'http://sebsauvage.net/paste/?8434b27936c09649#bR7XsXhoTiLcqCpQbmOpBi3rq2zzQUC5hBI7ZT1O3x8=',
 -            'description'=>'Shhhh! I\'m a private link only YOU can see. You can delete me too.',
 +            'description'=> t('Shhhh! I\'m a private link only YOU can see. You can delete me too.'),
              'private'=>1,
              'created'=> new DateTime('1 minute ago'),
              'tags'=>'secretstuff',
              return;
          }
  
+         $this->urls = [];
+         $this->ids = [];
          $this->links = FileUtils::readFlatDB($this->datastore, []);
  
          $toremove = array();
          foreach ($this->links as $key => &$link) {
              if (! $this->loggedIn && $link['private'] != 0) {
                  // Transition for not upgraded databases.
-                 $toremove[] = $key;
+                 unset($this->links[$key]);
                  continue;
              }
  
                  }
                  $link['shorturl'] = smallHash($link['linkdate']);
              }
-         }
  
-         // If user is not logged in, filter private links.
-         foreach ($toremove as $offset) {
-             unset($this->links[$offset]);
+             $this->urls[$link['url']] = $key;
+             $this->ids[$link['id']] = $key;
          }
-         $this->reorder();
      }
  
      /**
       */
      private function write()
      {
+         $this->reorder();
          FileUtils::writeFlatDB($this->datastore, $this->links);
      }
  
              return $a['created'] < $b['created'] ? 1 * $order : -1 * $order;
          });
  
-         $this->urls = array();
-         $this->ids = array();
+         $this->urls = [];
+         $this->ids = [];
          foreach ($this->links as $key => $link) {
              $this->urls[$link['url']] = $key;
              $this->ids[$link['id']] = $key;
diff --combined application/Updater.php
index 723a7a81dac89bbb1cc57d548c762ce698a4ae8c,0702158a7c9e1f3e4192dbcb5d85c3d75fd438d1..bc859536f61a846d9a5923e03f35ea33e9fae77d
@@@ -73,7 -73,7 +73,7 @@@ class Update
          }
  
          if ($this->methods === null) {
 -            throw new UpdaterException('Couldn\'t retrieve Updater class methods.');
 +            throw new UpdaterException(t('Couldn\'t retrieve Updater class methods.'));
          }
  
          foreach ($this->methods as $method) {
       */
      public function updateMethodCheckUpdateRemoteBranch()
      {
 -        if (shaarli_version === 'dev' || $this->conf->get('updates.check_updates_branch') === 'latest') {
 +        if (SHAARLI_VERSION === 'dev' || $this->conf->get('updates.check_updates_branch') === 'latest') {
              return true;
          }
  
          $latestMajor = $matches[1];
  
          // Get current major version digit
 -        preg_match('/(\d+)\.\d+$/', shaarli_version, $matches);
 +        preg_match('/(\d+)\.\d+$/', SHAARLI_VERSION, $matches);
          $currentMajor = $matches[1];
  
          if ($currentMajor === $latestMajor) {
          }
          return true;
      }
+     /**
+      * Save the datastore -> the link order is now applied when links are saved.
+      */
+     public function updateMethodReorderDatastore()
+     {
+         $this->linkDB->save($this->conf->get('resource.page_cache'));
+     }
  }
  
  /**
@@@ -482,7 -490,7 +490,7 @@@ class UpdaterException extends Exceptio
          }
  
          if (! empty($this->method)) {
 -            $out .= 'An error occurred while running the update '. $this->method . PHP_EOL;
 +            $out .= t('An error occurred while running the update ') . $this->method . PHP_EOL;
          }
  
          if (! empty($this->previous)) {
@@@ -522,11 -530,11 +530,11 @@@ function read_updates_file($updatesFile
  function write_updates_file($updatesFilepath, $updates)
  {
      if (empty($updatesFilepath)) {
 -        throw new Exception('Updates file path is not set, can\'t write updates.');
 +        throw new Exception(t('Updates file path is not set, can\'t write updates.'));
      }
  
      $res = file_put_contents($updatesFilepath, implode(';', $updates));
      if ($res === false) {
 -        throw new Exception('Unable to write updates in '. $updatesFilepath . '.');
 +        throw new Exception(t('Unable to write updates in '. $updatesFilepath . '.'));
      }
  }