Skip to content

Performance 6 (templates)#12233

Merged
mbabker merged 41 commits intojoomla:stagingfrom
frankmayer:Performance_6
Jul 25, 2017
Merged

Performance 6 (templates)#12233
mbabker merged 41 commits intojoomla:stagingfrom
frankmayer:Performance_6

Conversation

@frankmayer
Copy link
Copy Markdown
Contributor

@frankmayer frankmayer commented Sep 30, 2016

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

The changes in this batch are all in files under templates.
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 and cleaning up, but those 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 4 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 10.6.2017]
All Sub-PRs of this PR have now been merged. That means a lot less changes to be reviewed 😄

Attention potential testers: Those changes should only need code review.

Thank you!



<?php if (($params->get('show_author')) or ($params->get('show_parent_category')) or ($params->get('show_category')) or ($params->get('show_create_date')) or ($params->get('show_modify_date')) or ($params->get('show_publish_date')) or ($params->get('show_hits'))) : ?>
<?php if ($params->get('show_author') || $params->get('show_parent_category') || $params->get('show_category') || $params->get('show_create_date') || $params->get('show_modify_date') || $params->get('show_publish_date') || $params->get('show_hits')) : ?>
Copy link
Copy Markdown
Contributor

@Bakual Bakual Sep 30, 2016

Choose a reason for hiding this comment

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

In template layout files (everything within the /tmpl/ folders) we prefer or and and over || and &&. So please leave those alone.

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.

Didn't know that. Why is this?

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.

It's easier to read for people (users) which aren't that familiar with PHP.
Same for the if (...) : ... endif instead of if (...) { ... }

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.

When did that become a thing? Because last I remember that's NOT in our codestyle rules or documented guidelines. Not to mention there are (mostly small) behavioral differences between $foo and $bar versus $foo && $bar.

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.

Is there some kind of system with those? I ask because there are also plenty of && and || in those files.
A quick count revealed
84 x && | 29 x and
49 x || vs x 48 or

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.

When did that become a thing? Because last I remember that's NOT in our codestyle rules or documented guidelines.

Agreed, it's not in the codestyle rules. But I was under the impression that it is usally done like this and I always followed that unspoken rule. Same as the if ... endif stuff which isn't (imho) written in the codestyle rules as well.

@brianteeman
Copy link
Copy Markdown
Contributor

brianteeman commented Sep 30, 2016 via email

@mbabker
Copy link
Copy Markdown
Contributor

mbabker commented Sep 30, 2016

Definitely easier to read but it's not just a 1-for-1 swap between and and && or || and or.

@frankmayer
Copy link
Copy Markdown
Contributor Author

@mbabker could you elaborate on that?

@mbabker
Copy link
Copy Markdown
Contributor

mbabker commented Sep 30, 2016

http://php.net/manual/en/language.operators.logical.php will probably cover it better than I can.

@frankmayer
Copy link
Copy Markdown
Contributor Author

@mbabker Got it. Thanks.

@frankmayer
Copy link
Copy Markdown
Contributor Author

@mbabker ok but from what I see, most - if not all of those are swap-able 1-for-1. Why is it preferred then? And why specifically for the tmpl?

@Bakual
Copy link
Copy Markdown
Contributor

Bakual commented Sep 30, 2016

The tmpl folder contains the HTML output, which is the stuff users likely want to adjust.
Those files also are easy to override in a template. The files you got in the /html/ folder are actually overrides of the layout files in the /tmpl/ folder.

most - if not all of those are swap-able 1-for-1

In the layout files, they usually are interchangeable. It only starts to matter if you have them mixed in a assignments and ternaries (see http://php.net/manual/en/language.operators.precedence.php). But there I prefer to use () around the logical blocks anyway to make it simpler to read.

@frankmayer
Copy link
Copy Markdown
Contributor Author

Ok, I see, but still it's a mix of both styles, with the && and || having the most occurrences. That can be even more confusing to "users".
I would suggest to choose one way and go with it.

@Bakual
Copy link
Copy Markdown
Contributor

Bakual commented Sep 30, 2016

I would suggest to choose one way and go with it.

Agreed, but please don't do it in this PR. If we want to choose one way, the proper way is to define a codestyle rule and then apply it. Otherwise you're going to change it now and the next guy wants to change it back 😄

@frankmayer
Copy link
Copy Markdown
Contributor Author

😄 Yes, of course! I have already reversed those changes.

<dd class="createdby">
<?php $author = $item->author; ?>
<?php $author = ($item->created_by_alias ? $item->created_by_alias : $author);?>
<?php $author = ($item->created_by_alias ?: $author);?>
Copy link
Copy Markdown
Contributor

@andrepereiradasilva andrepereiradasilva Oct 3, 2016

Choose a reason for hiding this comment

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

like the other PR just

<?php $author = $item->created_by_alias ?: $item->author; ?>

<dd class="createdby">
<?php $author = $this->item->author; ?>
<?php $author = ($this->item->created_by_alias ? $this->item->created_by_alias : $author);?>
<?php $author = ($this->item->created_by_alias ?: $author);?>
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.

again, just

<?php $author = $this->item->created_by_alias ?: $this->item->author; ?>

<?php endif; ?>
<?php
$introcount = (count($this->intro_items));
$introcount = count($this->intro_items);
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.

actually this seems to be only used once ahead so it should only be there.

see ahead

<?php if (($rowcount == $this->columns) or ($counter == $introcount)) : ?>

<dd class="createdby">
<?php $author = $this->item->author; ?>
<?php $author = ($this->item->created_by_alias ? $this->item->created_by_alias : $author);?>
<?php $author = ($this->item->created_by_alias ?: $author);?>
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.

again, just

<?php $author = $this->item->created_by_alias ?: $this->item->author; ?>

<?php if (!empty($article->author) || !empty($article->created_by_alias)) : ?>
<?php $author = $article->author ?>
<?php $author = ($article->created_by_alias ? $article->created_by_alias : $author); ?>
<?php $author = ($article->created_by_alias ?: $author); ?>
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.

again, just

<?php $author = $article->created_by_alias ?: $article->author; ?>

<dd class="createdby">
<?php $author = $this->item->author; ?>
<?php $author = ($this->item->created_by_alias ? $this->item->created_by_alias : $author);?>
<?php $author = ($this->item->created_by_alias ?: $author);?>
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.

again, just

<?php $author = $this->item->created_by_alias ?: $this->item->author; ?>

var bildauf = '" . $this->baseurl . "/templates/" . $this->template . "/images/plus.png';
var bildzu = '" . $this->baseurl . "/templates/" . $this->template . "/images/minus.png';
var bildauf = '" . $this->baseurl . '/templates/' . $this->template . "/images/plus.png';
var bildzu = '" . $this->baseurl . '/templates/' . $this->template . "/images/minus.png';
Copy link
Copy Markdown
Contributor

@andrepereiradasilva andrepereiradasilva Oct 3, 2016

Choose a reason for hiding this comment

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

dont't understand why this change, before the baseurl var you have " and after '. IMHO or we use always ' or we use always "

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.

Thanks, this was an automated change which I obviously reviewed poorly... 😄

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.

Actually this was supposed to be a HEREDOC.. Forgot to implement...

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.

@frankmayer please review this

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.

😸

}");
background: " . $this->params->get('backgroundcolor') . ';
}'
);
Copy link
Copy Markdown
Contributor

@andrepereiradasilva andrepereiradasilva Oct 3, 2016

Choose a reason for hiding this comment

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

dont't understand why this change, before you have " and after '. IMHO or we use always ' or we use always "


<?php if ($this->item->state == 0 || strtotime($this->item->publish_up) > strtotime(JFactory::getDate())
|| ((strtotime($this->item->publish_down) < strtotime(JFactory::getDate())) && $this->item->publish_down != JFactory::getDbo()->getNullDate())) : ?>
|| ((strtotime($this->item->publish_down) < strtotime(JFactory::getDate())) && $this->item->publish_down !== JFactory::getDbo()->getNullDate())) : ?>
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.

<?php if ($this->params->get('show_page_heading') and ($this->params->get('show_category_title') or $this->params->get('page_subheading'))) : ?>
<?php
if ($this->params->get('show_page_heading')) : ?>
<?php if ($this->params->get('show_page_heading') and ($showCategoryTitle === true or $pageSubHeading)) : ?>
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.

Redundant checking with the previous line $this->params->get('show_page_heading'.

Copy link
Copy Markdown
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.

two doubts

</h2>
<?php endif; ?>
<?php if ($this->params->get('show_page_heading') and $params->get('show_title')) :?>
<?php if ($showPageHeading and $params->get('show_title')) :?>
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.

are you sure $showPageHeading defined at this time?

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.

It is defined in the first if() statement at line 30. Or, did I miss something?

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 sorry ... tought this instruction was inside an else

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.

No issue, thought I had messed up :)

</article>
<?php $counter++; ?>
<?php if (($rowcount == $this->columns) or ($counter == $introcount)) : ?>
<?php if ($rowcount === $this->columns or $counter === $introcount) : ?>
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.

are you sure $this->columns is an integer ? (see line above echo (int) $this->columns;)

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.

Thank you. Somehow got that wrong...

<?php $author = ($this->item->created_by_alias ?: $author);?>
<?php if (!empty($this->item->contact_link ) && $params->get('link_author') == true) : ?>
<?php $author = $this->item->created_by_alias ?: $this->item->author; ?>
<?php if (!empty($this->item->contact_link) && $params->get('link_author') == true) : ?>
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 extra space

@andrepereiradasilva
Copy link
Copy Markdown
Contributor

I have tested this item ✅ successfully on 4f3c91f

code review


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

@Quy
Copy link
Copy Markdown
Contributor

Quy commented Jun 13, 2017

I have tested this item ✅ successfully on 4f3c91f

Code review.


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

@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
<?php if ($showPageHeading = $this->params->get('show_page_heading')) : ?>

<?php if ($this->params->get('show_page_heading') and $params->get('show_title')) :?>
<?php if ($showPageHeading and $params->get('show_title')) :?>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is there any reason we are using and here? :-)

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.

Since this really big one is already RTC, and those seem to be no show-stoppers, do you mind marking those reviews as non-stoppers? It took a long time to go RTC for those bug ones :).
I will happily open a new PR for those ones after this is merged.

Also for this one and the one after the next, those are mixed files, and there has been lot of discussion on that in one of my other PR's.. in the code-standards Repo. Still ongoing I think.


<?php if ($this->item->state == 0 || strtotime($this->item->publish_up) > strtotime(JFactory::getDate())
|| ((strtotime($this->item->publish_down) < strtotime(JFactory::getDate())) && $this->item->publish_down != JFactory::getDbo()->getNullDate())) : ?>
|| (strtotime($this->item->publish_down) < strtotime(JFactory::getDate()) && $this->item->publish_down !== JFactory::getDbo()->getNullDate())) : ?>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

instead of calling strtotime on JFactory::getDate you can use JFactory::getDate()->getTimestamp();

<?php endif; ?>

<?php if ($this->params->get('show_category_title') or $this->params->get('page_subheading')) : ?>
<?php if ($showCategoryTitle === true or $pageSubHeading) : ?>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why are we using or here? :-)

<?php foreach ($this->children[$this->category->id] as $id => $child) : ?>
<?php
if ($this->params->get('show_empty_categories') || $child->numitems || count($child->getChildren())) :
if ($child->numitems || $this->params->get('show_empty_categories') || count($child->getChildren())) :
Copy link
Copy Markdown
Member

@yvesh yvesh Jun 15, 2017

Choose a reason for hiding this comment

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

!empty is faster than count :-)

// Make a link if not the last item in the breadcrumbs
$show_last = $params->get('showLast', 1);
if ($key != $last_item_key)
if ($key !== $last_item_key)
Copy link
Copy Markdown
Member

@yvesh yvesh Jun 15, 2017

Choose a reason for hiding this comment

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

new line missing before (yep i know it has been like that)

@rdeutz rdeutz added this to the Joomla 3.7.4 milestone Jun 21, 2017
@rdeutz rdeutz modified the milestones: Joomla 3.8.0, Joomla 3.7.4 Jul 5, 2017
@rdeutz
Copy link
Copy Markdown
Contributor

rdeutz commented Jul 5, 2017

I am not going to merge these types of PR into 3.7.4, we have seen that chances are good to miss something and then we introduce a bug as we have seen in the last release. Make the software more solid and stable is more important.

@frankmayer
Copy link
Copy Markdown
Contributor Author

@mbabker should I change the base of this PR and of #12220 to 3.8-dev and resolve any conflicts if there are any?

@mbabker
Copy link
Copy Markdown
Contributor

mbabker commented Jul 20, 2017

That'd be helpful.

@frankmayer frankmayer changed the base branch from staging to 3.8-dev July 20, 2017 13:26
@frankmayer
Copy link
Copy Markdown
Contributor Author

Base changed to 3.8-dev without conflicts on this PR.

@frankmayer
Copy link
Copy Markdown
Contributor Author

@mbabker Base changed to 3.8-dev on this PR. Conflicts resolved.

@joomla-cms-bot joomla-cms-bot removed the RTC This Pull Request is Ready To Commit label Jul 25, 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_6 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