From: ArthurHoaro Date: Sat, 28 Oct 2017 10:44:44 +0000 (+0200) Subject: Merge pull request #962 from ArthurHoaro/feature/perfs2 X-Git-Tag: v0.9.4~36 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=0926d263902c184bd4f4c2036cb8ee90f81c5060;hp=-c;p=github%2Fshaarli%2FShaarli.git Merge pull request #962 from ArthurHoaro/feature/perfs2 Performances: reorder links when they're written instead of read --- 0926d263902c184bd4f4c2036cb8ee90f81c5060 diff --combined application/LinkDB.php index f026a041,eace625e..c1661d52 --- a/application/LinkDB.php +++ b/application/LinkDB.php @@@ -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 @@@ -248,13 -248,13 +248,13 @@@ $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' @@@ -264,9 -264,9 +264,9 @@@ $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', @@@ -289,13 -289,15 +289,15 @@@ 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; } @@@ -329,14 -331,10 +331,10 @@@ } $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(); } /** @@@ -346,6 -344,7 +344,7 @@@ */ private function write() { + $this->reorder(); FileUtils::writeFlatDB($this->datastore, $this->links); } @@@ -528,8 -527,8 +527,8 @@@ 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 723a7a81,0702158a..bc859536 --- a/application/Updater.php +++ b/application/Updater.php @@@ -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) { @@@ -398,7 -398,7 +398,7 @@@ */ 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; } @@@ -413,7 -413,7 +413,7 @@@ $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) { @@@ -436,6 -436,14 +436,14 @@@ } 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 . '.')); } }