Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance 4 (plugins) #12228

Merged
merged 42 commits into from
Jun 8, 2017
Merged

Performance 4 (plugins) #12228

merged 42 commits into from
Jun 8, 2017

Conversation

frankmayer
Copy link
Contributor

@frankmayer frankmayer commented Sep 30, 2016

[UPDATED (1.6.2017) - see third paragraph]
Performance (and a bit of cleanup) Batch #4

The changes in this batch are all in files under plugins.
This PR modifies code to be a bit more performant and also does some cleanup.

I have mostly done work on low hanging fruit. There are still other ways of improving, but whose involve more deep research in the code and probably more drastic changes in order to be implemented.

[Update 6.1.2017]
In order to lighten this PR up, I have introduced 5 sub-PRs, which are easier to digest and mostly with very specific changes. In order to continue with this one, those ones should be tested/reviewed/merged first. After that, I can resolve the conflicts and there should finally be only a few changes left.

[Update 1.6.2017]
All Sub-PRs of this PR have now been merged. That means a lot less changes to be reviewed 😄
Please review.
Thank you!

@@ -258,14 +258,14 @@ private function _recaptcha_http_post($host, $path, $data, $port = 80)
$http_request = "POST $path HTTP/1.0\r\n";
$http_request .= "Host: $host\r\n";
$http_request .= "Content-Type: application/x-www-form-urlencoded;\r\n";
$http_request .= "Content-Length: " . strlen($req) . "\r\n";
$http_request .= 'Content-Length: ' . strlen($req) . "\r\n";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again why use ' when you use " in all others?

{
die("To use reCAPTCHA you must get an API key from <a href='"
. self::$_signupUrl . "'>" . self::$_signupUrl . "</a>");
. self::$_signupUrl . "'>" . self::$_signupUrl . '</a>');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again why use ' when you use " in all others?

@@ -39,7 +39,7 @@ public function onContentBeforeDisplay($context, &$row, &$params, $page = 0)
return false;
}

if (($context == 'com_content.article') && ($view == 'article') && $params->get('show_item_navigation'))
if (($context === 'com_content.article') && ($view === 'article') && $params->get('show_item_navigation'))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could remove the parenthisis here


if (($task == 'register') && ($tosenabled) && ($tosarticle) && ($option == 'com_users'))
// Check that the tos is checked.
if (($task === 'register') && $tosenabled && $tosarticle && ($option === 'com_users') && !$data['profile']['tos'])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could remove the parenthisis here

@andrepereiradasilva
Copy link
Contributor

I have tested this item ✅ successfully on 42a5a54

code review


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/12228.

# Conflicts:
#	plugins/content/pagebreak/pagebreak.php
#	plugins/content/pagenavigation/pagenavigation.php
#	plugins/system/debug/debug.php
#	plugins/system/languagefilter/languagefilter.php
#	plugins/user/profile/field/dob.php
#	plugins/user/profile/profile.php
@frankmayer
Copy link
Contributor Author

This PR is waiting on merge of sub PR #13272, so I can resolve conflicts here and get this reviewed / tested / merged, too.

@@ -472,6 +472,8 @@ public function onContentPrepare($context, $item)
{
$item->fields[$field->id] = $field;
}

return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted this one to its prior state, so it won't raise conflicts with @laoneo 's efforts.

@frankmayer
Copy link
Contributor Author

Edited initial post to show which sub-PRs still have to go through, in order to make this one easier to digest.
It would be great if the initial big batch PRs of mine could make it into alpha2. Thanks!

# Conflicts:
#	plugins/authentication/gmail/gmail.php
#	plugins/editors-xtd/image/image.php
#	plugins/editors/tinymce/tinymce.php
#	plugins/system/debug/debug.php
#	plugins/system/fields/fields.php
#	plugins/user/joomla/joomla.php
#	plugins/user/profile/field/dob.php
@frankmayer
Copy link
Contributor Author

Pls don't review this yet. There was a git problem. Need to resolve first.

# Conflicts:
#	plugins/captcha/recaptcha/recaptchalib.php
#	plugins/content/contact/contact.php
#	plugins/finder/categories/categories.php
#	plugins/finder/contacts/contacts.php
#	plugins/finder/newsfeeds/newsfeeds.php
#	plugins/finder/tags/tags.php
@frankmayer
Copy link
Contributor Author

All Sub-PRs of this PR have now been merged. That means a lot less changes to be reviewed 😄
Please review.
Thank you!

@andrepereiradasilva
Copy link
Contributor

next in my list of tests - tomorrow probably

@@ -268,7 +268,7 @@ private function _recaptcha_http_post($host, $path, $data, $port = 80)

$response = '';

if (($fs = @fsockopen($host, $port, $errno, $errstr, 10)) == false )
if (($fs = @fsockopen($host, $port, $errno, $errstr, 10)) === false )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove space after false.

@@ -39,7 +39,7 @@ public function onContentBeforeDisplay($context, &$row, &$params, $page = 0)
return false;
}

if (($context === 'com_content.article') && ($view === 'article') && $params->get('show_item_navigation'))
if (($context === 'com_content.article') && $view === 'article' && $params->get('show_item_navigation'))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove parenthesis ($context === 'com_content.article')

@@ -1110,7 +1106,7 @@ protected function displayQueries()
$title = '<span class="dbg-noprofile">' . $title . '</span>';
}

$htmlProfile = ($info[$id]->profile ? $info[$id]->profile : JText::_('PLG_DEBUG_NO_PROFILE'));
$htmlProfile = ($info[$id]->profile ?: JText::_('PLG_DEBUG_NO_PROFILE'));

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove outside parenthesis (ignore if done in a different PR).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't remember if that is in any other PR. There are so many PR's still open, that some may overlap. I'll just do that here and move on 😄
Thanks for reviewing!

@@ -384,13 +384,10 @@ public function onUserBeforeSave($user, $isnew, $data)
$tosarticle = $this->params->get('register_tos_article');
$tosenabled = ($this->params->get('register-require_tos', 0) == 2);

if (($task === 'register') && $tosenabled && $tosarticle && ($option === 'com_users'))
// Check that the tos is checked.
if (($task === 'register') && $tosenabled && $tosarticle && $option === 'com_users' && !$data['profile']['tos'])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove parenthesis ($task === 'register').

@frankmayer
Copy link
Contributor Author

@Quy would you be so kind and check the changes of your reviews for this one, too? So maybe we can get this RTC as soon as @andrepereiradasilva also has time to check it?
Thanks guys!!!

@Quy
Copy link
Contributor

Quy commented Jun 1, 2017

I have tested this item ✅ successfully on 475b880


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/12228.

@ghost
Copy link

ghost commented Jun 1, 2017

RTC after two successful tests.

@joomla-cms-bot joomla-cms-bot added the RTC This Pull Request is Ready To Commit label Jun 1, 2017
Copy link
Contributor

@andrepereiradasilva andrepereiradasilva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some minor issues/sugestions

@@ -72,7 +72,7 @@ public function onUserAuthenticate($credentials, $options, &$response)
{
// Bind using Connect Username/password
// Force anon bind to mitigate misconfiguration like [#7119]
if (strlen($this->params->get('username')))
if ($this->params->get('username'))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strict? $this->params->get('username', '') !== ''

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.. thanks

@@ -40,7 +40,7 @@ public function onInit($id = 'dynamic_recaptcha_1')
{
$pubkey = $this->params->get('public_key', '');

if ($pubkey == null || $pubkey == '')
if ($pubkey === null || $pubkey === '')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: can pubkey be null? when in line above default to '' if doesn't exist

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it can't... changing

@@ -117,13 +117,13 @@ public function onCheckAnswer($code = null)
case '1.0':
$challenge = $input->get('recaptcha_challenge_field', '', 'string');
$response = $input->get('recaptcha_response_field', '', 'string');
$spam = ($challenge == null || strlen($challenge) == 0 || $response == null || strlen($response) == 0);
$spam = ($challenge === null || $challenge === '' || $response === null || $response === '');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

break;
case '2.0':
// Challenge Not needed in 2.0 but needed for getResponse call
$challenge = null;
$response = $input->get('g-recaptcha-response', '', 'string');
$spam = ($response == null || strlen($response) == 0);
$spam = ($response === null || $response === '');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

@@ -131,7 +131,7 @@ public function verifyResponse($remoteIp, $response)
$answers = json_decode($getResponse, true);
$recaptchaResponse = new JReCaptchaResponse();

if (trim($answers['success']) == true)
if (trim($answers['success']))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strict? trim($answers['success']) !== ''

{
return;
}

// Check if the extension that owns the category is also enabled.
if (JComponentHelper::isEnabled($item->extension) === false)
if (!JComponentHelper::isEnabled($item->extension))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why remove the strict compare?

@@ -251,7 +251,7 @@ public function onFinderChangeState($context, $pks, $value)
protected function index(FinderIndexerResult $item, $format = 'html')
{
// Check if the extension is enabled
if (JComponentHelper::isEnabled($this->extension) === false)
if (!JComponentHelper::isEnabled($this->extension))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why remove the strict compare?

@@ -246,7 +246,7 @@ protected function index(FinderIndexerResult $item, $format = 'html')
$item->setLanguage();

// Check if the extension is enabled.
if (JComponentHelper::isEnabled($this->extension) == false)
if (!JComponentHelper::isEnabled($this->extension))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why remove the strict compare?

@@ -252,7 +252,7 @@ public function onFinderChangeState($context, $pks, $value)
protected function index(FinderIndexerResult $item, $format = 'html')
{
// Check if the extension is enabled.
if (JComponentHelper::isEnabled($this->extension) === false)
if (!JComponentHelper::isEnabled($this->extension))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why remove the strict compare?

@@ -206,7 +206,7 @@ public function onFinderChangeState($context, $pks, $value)
protected function index(FinderIndexerResult $item, $format = 'html')
{
// Check if the extension is enabled
if (JComponentHelper::isEnabled($this->extension) === false)
if (!JComponentHelper::isEnabled($this->extension))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why remove the strict compare?

@ghost
Copy link

ghost commented Jun 2, 2017

@andrepereiradasilva set Status back on Pending?

@frankmayer
Copy link
Contributor Author

@franz-wohlkoenig Let me just fly over those comments and I'll come back to you.

@frankmayer
Copy link
Contributor Author

@franz-wohlkoenig @andrepereiradasilva updated according to reviewer's comments.
Please check and RTC.
Thanks!!

@andrepereiradasilva
Copy link
Contributor

I have tested this item ✅ successfully on 475b880


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/12228.

@rdeutz rdeutz merged commit d434df3 into joomla:staging Jun 8, 2017
@joomla-cms-bot joomla-cms-bot removed the RTC This Pull Request is Ready To Commit label Jun 8, 2017
@rdeutz rdeutz added this to the Joomla 3.7.3 milestone Jun 8, 2017
@frankmayer frankmayer deleted the Performance_4 branch June 8, 2017 10:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants