Skip to content

Performance 2 (libraries/legacy)#12220

Merged
mbabker merged 33 commits intojoomla:stagingfrom
frankmayer:Performance_2
Jul 25, 2017
Merged

Performance 2 (libraries/legacy)#12220
mbabker merged 33 commits intojoomla:stagingfrom
frankmayer:Performance_2

Conversation

@frankmayer
Copy link
Copy Markdown
Contributor

@frankmayer frankmayer commented Sep 30, 2016

[UPDATED (6.1.2017) - see second paragraph]
Performance (and a bit of cleanup) Batch #2

The changes in this batch are all in files under libraries/legacy.
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 6 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.

@sovainfo
Copy link
Copy Markdown
Contributor

Could you explain when '== 0' is oke and when it needs '=== 0' ?

@mbabker
Copy link
Copy Markdown
Contributor

mbabker commented Sep 30, 2016

=== is more strict than ==, it will validate that something matches both the value and data type (so in that case 0 === '0' would fail but 0 == '0' is OK).

It's useful with some of the string functions where you can have a boolean false and an integer zero return. With == the values are compared to represent the same thing but with === they aren't.

// If the node's parent id is not in the _nodes list and the node is not root (doesn't have parent_id == 0),
// then remove the node from the list
if (!(isset($this->_nodes[$result->parent_id]) || $result->parent_id == 0))
if (!($result->parent_id == 0 || isset($this->_nodes[$result->parent_id])))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be === 0 ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I didn't strict type those comparisons where it was not clear if the value is really strict. In that case it could be an integer or a string with a number. So, not to break BC I left those alone.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You could use (int) and them do the strict comparation .

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, but they also do involve a lot more research. It's not always just doing some casting.
I thought that those kind of changes would/could be done later by me or someone else.
Don't these batches already have enough changes?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

right :)

@mahagr
Copy link
Copy Markdown

mahagr commented Oct 3, 2016

@sovainfo The main issue with == comparison is that sometimes it casts the values in very odd way, for example:

    echo (0 == 'asd') ? 'true' : 'false'; // true

Which is just wrong. On the other hand you really need to be careful with === as if you're comparing different types, it always returns false. This is true especially with all (integer) values coming from DB, which are always strings, but usually integers if you happen to update value of the object:

    echo (0 === '0') ? 'true' : 'false'; // false

@sovainfo
Copy link
Copy Markdown
Contributor

sovainfo commented Oct 3, 2016

Thank you all for the feedback. For some reason thought that 'null' would never compare equal to anything, not even 'null'. Maybe that only applies to SQL, requiring you to use 'IS NULL'.

Concerning values coming from the database, expect the driver to make sure the right datatype to be returned. Apparently it doesn't.

@andrepereiradasilva
Copy link
Copy Markdown
Contributor

I have tested this item ✅ successfully on 0148c52

code review


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

public function isSSLConnection()
{
return (isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 'on')) || getenv('SSL_PROTOCOL_VERSION');
return (isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] === 'on')) || getenv('SSL_PROTOCOL_VERSION');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Remove parentheses ($_SERVER['HTTPS'] === 'on')


$ids = $this->input->post->get('cid', array(), 'array');
$inc = ($this->getTask() == 'orderup') ? -1 : 1;
$inc = ($this->getTask() === 'orderup') ? -1 : 1;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Remove parentheses

$input = $app->input;
$old_state = $app->getUserState($key);
$cur_state = (!is_null($old_state)) ? $old_state : $default;
$cur_state = ($old_state !== null) ? $old_state : $default;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Remove parentheses


// Verify that the default home menu set to "all" languages" is not unset
if ($this->home == '1' && $this->language == '*' && ($array['language'] != '*'))
if ($this->home == '1' && $this->language === '*' && ($array['language'] != '*'))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Remove parentheses

@andrepereiradasilva
Copy link
Copy Markdown
Contributor

I have tested this item ✅ successfully on 0148c52

code review


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

{
// Verify that the default home menu is not unset
if ($this->home == '1' && $this->language == '*' && ($array['home'] == '0'))
if ($this->home == '1' && $this->language === '*' && ($array['home'] == '0'))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Remove parentheses

@andrepereiradasilva
Copy link
Copy Markdown
Contributor

I have tested this item ✅ successfully on 0148c52


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

@Quy
Copy link
Copy Markdown
Contributor

Quy commented Jun 13, 2017

I have tested this item ✅ successfully on 0148c52

Code review.


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

@frankmayer
Copy link
Copy Markdown
Contributor Author

RTC please, thank you

@ghost
Copy link
Copy Markdown

ghost commented Jun 15, 2017

RTC after two successful tests.

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

ghost commented Jun 15, 2017

Thanks for Hint, @frankmayer

@rdeutz rdeutz modified the milestone: Joomla 3.7.4 Jun 21, 2017
@frankmayer
Copy link
Copy Markdown
Contributor Author

Merge pls?

@rdeutz rdeutz modified the milestones: Joomla 3.8.0, Joomla 3.7.4 Jul 5, 2017
@frankmayer frankmayer mentioned this pull request Jul 20, 2017
4 tasks
@frankmayer frankmayer changed the base branch from staging to 3.8-dev July 20, 2017 13:26
# Conflicts:
#	libraries/legacy/categories/categories.php
#	libraries/loader.php
#	libraries/src/Joomla/CMS/Controller/Controller.php
#	libraries/src/Joomla/CMS/Controller/Form.php
#	libraries/src/Joomla/CMS/Model/Model.php
@joomla-cms-bot joomla-cms-bot added PR-3.8-dev and removed RTC This Pull Request is Ready To Commit labels Jul 20, 2017
roland-d added a commit to roland-d/joomla-cms that referenced this pull request Jul 26, 2017
* staging: (274 commits)
  Add JCryptCipherSodium to support libsodium (joomla#16754)
  Performance 2 (libraries/legacy) (joomla#12220)
  Performance 6 (templates) (joomla#12233)
  Fixed typehint (joomla#16425)
  Fix for: Repeatable field is no longer rendered with Chosen layout (joomla#16471)
  Fix the path for the ajax-loader.gif (joomla#16701)
  Menu items list parent filter (joomla#17060)
  Text Filters layout (joomla#17113)
  mod_login showon option (joomla#17153)
  com_banners incorret tooltip (joomla#17157)
  fix joomla.content.options_default (joomla#17123)
  remove the never working limitstart call (joomla#17184)
  Update phpDocumentor build
  set 3.8.0 Dev State
  Prepare 3.7.4 Stable Release
  fixed a logic change in joomla#12294, thanks @Hoffi1
  Update sv-SE.ini
  Update pt-BR.ini
  Update lv-LV.ini
  Update fa-IR.ini
  ...
@frankmayer frankmayer deleted the Performance_2 branch August 23, 2017 19:09
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.

10 participants