Tiny performance tweaks

This commit is contained in:
Eshin Kunishima 2016-05-03 17:45:07 +09:00
parent 180dd6547c
commit aabee67bdd
No known key found for this signature in database
GPG Key ID: 3232CD58BDF165FF
19 changed files with 38 additions and 37 deletions

View File

@ -38,7 +38,7 @@ Router\get_action('bookmarks', function () {
$group_id = Request\int_param('group_id', null);
$feed_ids = array();
if (! is_null($group_id)) {
if ($group_id !== null) {
$feed_ids = Model\Group\get_feeds_by_group($group_id);
}

View File

@ -7,7 +7,7 @@ Router\before(function ($action) {
// Select the requested database either from post param database or from the
// session variable. If it fails, logout to destroy session and
// 'remember me' cookie
if (! is_null(Request\value('database')) && ! Model\Database\select(Request\value('database'))) {
if (Request\value('database') !== null && ! Model\Database\select(Request\value('database'))) {
Model\User\logout();
Response\redirect('?action=login');
} elseif (! empty($_SESSION['database'])) {

View File

@ -8,7 +8,7 @@ Router\get_action('history', function () {
$group_id = Request\int_param('group_id', null);
$feed_ids = array();
if (! is_null($group_id)) {
if ($group_id !== null) {
$feed_ids = Model\Group\get_feeds_by_group($group_id);
}
@ -59,7 +59,7 @@ Router\get_action('confirm-flush-history', function () {
Router\get_action('flush-history', function () {
$group_id = Request\int_param('group_id', null);
if (!is_null($group_id)) {
if ($group_id !== null) {
Model\Item\mark_group_as_removed($group_id);
} else {
Model\Item\mark_all_as_removed();

View File

@ -11,7 +11,7 @@ Router\get_action('unread', function () {
$group_id = Request\int_param('group_id', null);
$feed_ids = array();
if (! is_null($group_id)) {
if ($group_id !== null) {
$feed_ids = Model\Group\get_feeds_by_group($group_id);
}
@ -160,7 +160,7 @@ Router\post_action('mark-item-unread', function () {
Router\get_action('mark-all-read', function () {
$group_id = Request\int_param('group_id', null);
if (!is_null($group_id)) {
if ($group_id !== null) {
Model\Item\mark_group_as_read($group_id);
} else {
Model\Item\mark_all_as_read();

View File

@ -309,7 +309,7 @@ foreach (array_keys($_GET) as $action) {
}
if (! empty($_POST['mark']) && ! empty($_POST['as'])
&& ! is_null(filter_input(INPUT_POST, 'id', FILTER_VALIDATE_INT, array('options' => array('default' => null, 'min_range' => -1))))) {
&& filter_input(INPUT_POST, 'id', FILTER_VALIDATE_INT, array('options' => array('default' => null, 'min_range' => -1))) !== null) {
if ($_POST['mark'] === 'item') {
route('write_items');
} elseif ($_POST['mark'] === 'feed' && ! empty($_POST['before'])) {

View File

@ -109,7 +109,7 @@ namespace Translator {
}
}
for ($i = $plural; $i >= 0; $i--) {
for ($i = $plural; $i >= 0; --$i) {
if (isset($locales[$identifier][$i])) {
return $locales[$identifier][$i];
}

View File

@ -17,7 +17,7 @@ function parse_app_version($refnames, $commithash)
if ($refnames !== '$Format:%d$') {
$tag = preg_replace('/\s*\(.*tag:\sv([^,]+).*\)/i', '\1', $refnames);
if (!is_null($tag) && $tag !== $refnames) {
if ($tag !== null && $tag !== $refnames) {
return $tag;
}
}
@ -222,7 +222,7 @@ function form_hidden($name, $values = array())
function form_default_select($name, array $options, $values = array(), array $errors = array(), $class = '')
{
$options = array('' => '?') + $options;
$options += array('' => '?');
return form_select($name, $options, $values, $errors, $class);
}

View File

@ -114,9 +114,9 @@ if (!defined('PASSWORD_BCRYPT')) {
}
if (!$buffer_valid || strlen($buffer) < $raw_length) {
$bl = strlen($buffer);
for ($i = 0; $i < $raw_length; $i++) {
for ($i = 0; $i < $raw_length; ++$i) {
if ($i < $bl) {
$buffer[$i] = $buffer[$i] ^ chr(mt_rand(0, 255));
$buffer[$i] ^= chr(mt_rand(0, 255));
} else {
$buffer .= chr(mt_rand(0, 255));
}
@ -212,12 +212,13 @@ if (!defined('PASSWORD_BCRYPT')) {
return false;
}
$ret = crypt($password, $hash);
if (!is_string($ret) || strlen($ret) != strlen($hash) || strlen($ret) <= 13) {
$len = strlen($ret);
if (!is_string($ret) || $len != strlen($hash) || $len <= 13) {
return false;
}
$status = 0;
for ($i = 0; $i < strlen($ret); $i++) {
for ($i = 0; $i < $len; ++$i) {
$status |= (ord($ret[$i]) ^ ord($hash[$i]));
}

View File

@ -244,7 +244,7 @@ function get_nav($item, $status = array('unread'), $bookmark = array(1, 0), $fee
$next_item = null;
$previous_item = null;
for ($i = 0, $ilen = count($items); $i < $ilen; $i++) {
for ($i = 0, $ilen = count($items); $i < $ilen; ++$i) {
if ($items[$i]['id'] == $item['id']) {
if ($i > 0) {
$j = $i - 1;
@ -255,7 +255,7 @@ function get_nav($item, $status = array('unread'), $bookmark = array(1, 0), $fee
break;
}
$j--;
--$j;
}
}
@ -268,7 +268,7 @@ function get_nav($item, $status = array('unread'), $bookmark = array(1, 0), $fee
break;
}
$j++;
++$j;
}
}

View File

@ -49,7 +49,7 @@ foreach (new DirectoryIterator('locales') as $fileInfo) {
$filename = 'locales/'.$fileInfo->getFilename().'/translations.php';
echo $fileInfo->getFilename().' ('.$filename.')'.PHP_EOL;
echo $fileInfo->getFilename(), ' (', $filename, ')', PHP_EOL;
file_put_contents($filename, update_missing_locales($reference, $filename));
}

View File

@ -16,7 +16,7 @@
<h3><?= t('Bookmarks') ?></h3>
<ul>
<li>
<a href="<?= Helper\get_current_base_url().'?action=bookmark-feed&amp;database='.urlencode($db_name).'&amp;token='.urlencode($config['feed_token']) ?>" target="_blank"><?= t('Bookmark RSS Feed') ?></a>
<a href="<?= Helper\get_current_base_url(), '?action=bookmark-feed&amp;database=', urlencode($db_name), '&amp;token=', urlencode($config['feed_token']) ?>" target="_blank"><?= t('Bookmark RSS Feed') ?></a>
</li>
</ul>
</div>

View File

@ -15,7 +15,7 @@
<div class="panel panel-default">
<h3 id="fever"><?= t('Fever API') ?></h3>
<ul>
<li><?= t('API endpoint:') ?> <strong><?= Helper\get_current_base_url().'fever/' ?></strong></li>
<li><?= t('API endpoint:') ?> <strong><?= Helper\get_current_base_url(), 'fever/' ?></strong></li>
<li><?= t('API username:') ?> <strong><?= Helper\escape($config['username']) ?></strong></li>
<li><?= t('API token:') ?> <strong><?= Helper\escape($config['fever_token']) ?></strong></li>
</ul>
@ -23,7 +23,7 @@
<div class="panel panel-default">
<h3 id="api"><?= t('Miniflux API') ?></h3>
<ul>
<li><?= t('API endpoint:') ?> <strong><?= Helper\get_current_base_url().'jsonrpc.php' ?></strong></li>
<li><?= t('API endpoint:') ?> <strong><?= Helper\get_current_base_url(), 'jsonrpc.php' ?></strong></li>
<li><?= t('API username:') ?> <strong><?= Helper\escape($config['username']) ?></strong></li>
<li><?= t('API token:') ?> <strong><?= Helper\escape($config['api_token']) ?></strong></li>
</ul>

View File

@ -1,4 +1,4 @@
<?php if (empty($items) && is_null($group_id)): ?>
<?php if (empty($items) && $group_id === null): ?>
<p class="alert alert-info"><?= t('No bookmark') ?></p>
<?php else: ?>

View File

@ -5,6 +5,6 @@
<p class="alert alert-info"><?= t('Do you really want to remove these items from your history?') ?></p>
<div class="form-actions">
<a href="?action=flush-history<?= is_null($group_id) ? '' : '&amp;group_id='.$group_id ?>" class="btn btn-red"><?= t('Remove') ?></a>
<?= t('or') ?> <a href="?action=history<?= is_null($group_id) ? '' : '&amp;group_id='.$group_id ?>"><?= t('cancel') ?></a>
<a href="?action=flush-history<?= $group_id === null ? '' : '&amp;group_id='.$group_id ?>" class="btn btn-red"><?= t('Remove') ?></a>
<?= t('or') ?> <a href="?action=history<?= $group_id === null ? '' : '&amp;group_id='.$group_id ?>"><?= t('cancel') ?></a>
</div>

View File

@ -34,7 +34,7 @@
<?= Helper\favicon($favicons, $feed['id']) ?>
<a href="?action=feed-items&amp;feed_id=<?= $feed['id'] ?>" title="<?= t('Show only this subscription') ?>"><?= Helper\escape($feed['title']) ?></a>
&lrm;<span class="items-count"><?= $feed['items_unread'] .'/' . $feed['items_total'] ?></span>
&lrm;<span class="items-count"><?= $feed['items_unread'], '/', $feed['items_total'] ?></span>
<?php if ($feed['enabled']): ?>
@ -42,7 +42,7 @@
<?php if ($feed['last_checked']): ?>
<time class="feed-last-checked" data-after-update="<?= t('updated just now') ?>">
<?= t('checked at').' '.dt('%e %B %Y %k:%M', $feed['last_checked']) ?>
<?= t('checked at'), ' ', dt('%e %B %Y %k:%M', $feed['last_checked']) ?>
</time>
<?php else: ?>
<span class="feed-last-checked" data-after-update="<?= t('updated just now') ?>">

View File

@ -18,9 +18,9 @@
<ul>
<li>
<a href="?action=history<?= is_null($group_id) ? '' : '&amp;group_id='.$group_id ?>&amp;order=updated&amp;direction=<?= $direction == 'asc' ? 'desc' : 'asc' ?>"><?= tne('sort by date %s(%s)%s', '<span class="hide-mobile">', $direction == 'desc' ? t('older first') : t('most recent first'), '</span>') ?></a>
<a href="?action=history<?= $group_id === null ? '' : '&amp;group_id='.$group_id ?>&amp;order=updated&amp;direction=<?= $direction == 'asc' ? 'desc' : 'asc' ?>"><?= tne('sort by date %s(%s)%s', '<span class="hide-mobile">', $direction == 'desc' ? t('older first') : t('most recent first'), '</span>') ?></a>
</li>
<li><a href="?action=confirm-flush-history<?= is_null($group_id) ? '' : '&amp;group_id='.$group_id ?>"><?= t('flush all items') ?></a></li>
<li><a href="?action=confirm-flush-history<?= $group_id === null ? '' : '&amp;group_id='.$group_id ?>"><?= t('flush all items') ?></a></li>
</ul>
</div>

View File

@ -16,10 +16,10 @@
<ul>
<li>
<a href="?action=unread<?= is_null($group_id) ? '' : '&amp;group_id='.$group_id ?>&amp;order=updated&amp;direction=<?= $direction == 'asc' ? 'desc' : 'asc' ?>"><?= tne('sort by date %s(%s)%s', '<span class="hide-mobile">',$direction == 'desc' ? t('older first') : t('most recent first'), '</span>') ?></a>
<a href="?action=unread<?= $group_id === null ? '' : '&amp;group_id='.$group_id ?>&amp;order=updated&amp;direction=<?= $direction == 'asc' ? 'desc' : 'asc' ?>"><?= tne('sort by date %s(%s)%s', '<span class="hide-mobile">',$direction == 'desc' ? t('older first') : t('most recent first'), '</span>') ?></a>
</li>
<li>
<a href="?action=mark-all-read<?= is_null($group_id) ? '' : '&amp;group_id='.$group_id ?>"><?= t('mark all as read') ?></a>
<a href="?action=mark-all-read<?= $group_id === null ? '' : '&amp;group_id='.$group_id ?>"><?= t('mark all as read') ?></a>
</li>
</ul>
</div>
@ -43,7 +43,7 @@
<?php endforeach ?>
<div id="bottom-menu">
<a href="?action=mark-all-read<?= is_null($group_id) ? '' : '&amp;group_id='.$group_id ?>"><?= t('mark all as read') ?></a>
<a href="?action=mark-all-read<?= $group_id === null ? '' : '&amp;group_id='.$group_id ?>"><?= t('mark all as read') ?></a>
</div>
<?= \Template\load('paging', array('menu' => $menu, 'nb_items' => $nb_items, 'items_per_page' => $items_per_page, 'offset' => $offset, 'order' => $order, 'direction' => $direction, 'group_id' => $group_id)) ?>

View File

@ -108,7 +108,7 @@ abstract class minifluxTestCase extends PHPUnit_Extensions_Selenium2TestCase
protected function getConnection()
{
if (is_null(static::$databaseConnection)) {
if (static::$databaseConnection === null) {
// let Miniflux setup the database
require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'common.php';
@ -142,7 +142,7 @@ abstract class minifluxTestCase extends PHPUnit_Extensions_Selenium2TestCase
protected function getDatabaseTester($dataset)
{
if (is_null(static::$databaseTester)) {
if (static::$databaseTester === null) {
$rdataset = new PHPUnit_Extensions_Database_DataSet_ReplacementDataSet($dataset);
$rdataset->addSubStrReplacement('##TIMESTAMP##', substr((string)(time()-100), 0, -2));
@ -247,7 +247,7 @@ abstract class minifluxTestCase extends PHPUnit_Extensions_Selenium2TestCase
$elements = $this->elements($this->using('id')->value($id));
if (count($elements) === 1 && $elements[0]->text() == $text
|| count($elements) === 0 && is_null($text)) {
|| count($elements) === 0 && $text === null) {
return true;
}
} catch (PHPUnit_Extensions_Selenium2TestCase_WebDriverException $e) {

View File

@ -19,10 +19,10 @@ function check_job_left(Pheanstalk $connection, array $options)
if (in_array(BEANSTALKD_QUEUE, $queues)) {
$stats = $connection->statsTube(BEANSTALKD_QUEUE);
echo 'Jobs in queue: '.$stats->current_jobs_ready.PHP_EOL;
echo 'Jobs in queue: ', $stats->current_jobs_ready, PHP_EOL;
(int) $stats->current_jobs_ready === 0 && exit(0);
} else {
echo 'No queue'.PHP_EOL;
echo 'No queue', PHP_EOL;
exit(0);
}
}
@ -35,7 +35,7 @@ check_job_left($connection, $options);
while ($job = $connection->reserveFromTube(BEANSTALKD_QUEUE)) {
$feed_id = $job->getData();
echo 'Processing feed_id='.$feed_id.PHP_EOL;
echo 'Processing feed_id=', $feed_id, PHP_EOL;
Model\Feed\refresh($feed_id);
$connection->delete($job);