Feature No Code Attached Yet
avatar mickmackusa
mickmackusa
22 Aug 2020

There are multiple places in the code base where the database object is not cached as a variable for re-use. As a result, the code is not DRY and developers may be initially confused by inconsistency when they expect to see $db->quoteName() but $query->quoteName() is written. There are some occurrences where $this->getDbo() is called multiple times within the same method which is not ideal / best practice (I found one occurrence within a loop).

The advised fix does not need to change any behavior and as far as I can tell there is no bug in the current implementation.

To find the occurrences just search on "$this->getDbo()" in your IDE and observe the number of times the getDbo() method is called. If more than one, then declare a variable on the first call and re-use the variable on all subsequent occurrences. If the getDbo() method is called over and over within a loop, declare $db prior to entering the loop and only use $db within the loop.

avatar mickmackusa mickmackusa - open - 22 Aug 2020
avatar joomla-cms-bot joomla-cms-bot - change - 22 Aug 2020
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - labeled - 22 Aug 2020
avatar brianteeman
brianteeman - comment - 22 Aug 2020

Pull requests are welcome

avatar Hackwar
Hackwar - comment - 18 Jan 2022

Yes, this is a good codestyle, however as @brianteeman stated, pull requests would be welcome. Otherwise I would vote to close this issue for now.

avatar pritam825
pritam825 - comment - 22 Jan 2022

@mickmackusa sir, I have found multiple occurrences of "$this->getDbo()", so, sir can you please upload an screenshot to approach this, so that I will accordingly, and will change in the best manner, thanks in advance :)

avatar Hackwar Hackwar - change - 20 Feb 2023
Labels Added: ? No Code Attached Yet
Removed: ?
avatar Hackwar Hackwar - labeled - 20 Feb 2023
avatar Hackwar Hackwar - change - 25 Sep 2024
Status New Closed
Closed_Date 0000-00-00 00:00:00 2024-09-25 21:08:59
Closed_By Hackwar
Labels Added: Feature
Removed: ?
avatar Hackwar Hackwar - close - 25 Sep 2024
avatar Hackwar
Hackwar - comment - 25 Sep 2024

In the meantime we refactored the code to use the DatabaseAwareTrait. That changed the original issue of this PR only a little bit, however we are in the process of improving this overall in the coming months and years. I don't think we need to keep this issue open for this, so I'm going to close this. Thank you, @mickmackusa, for reporting this. We will try to refactor as you proposed.

Add a Comment

Login with GitHub to post a comment