Skip to content

Conversation

Denitz
Copy link
Contributor

@Denitz Denitz commented Sep 12, 2025

Summary of Changes

Subsequent calls to $componentObject->getCategory() produce the same SQL query.

Testing Instructions

Add custom fields for articles, limit fields to category "Any Category".
Add fields values for articles from this category.
Show articles from this category in frontend, i.e. via Category Blog and show custom field values.

Actual result BEFORE applying this Pull Request

See multiple SQL query duplicates with the same params like:

SELECT `c`.`id`,`c`.`asset_id`,`c`.`access`,`c`.`alias`,`c`.`checked_out`,`c`.`checked_out_time`,`c`.`created_time`,`c`.`created_user_id`,`c`.`description`,`c`.`extension`,`c`.`hits`,`c`.`language`,`c`.`level`,`c`.`lft`,`c`.`metadata`,`c`.`metadesc`,`c`.`metakey`,`c`.`modified_time`,`c`.`note`,`c`.`params`,`c`.`parent_id`,`c`.`path`,`c`.`published`,`c`.`rgt`,`c`.`title`,`c`.`modified_user_id`,`c`.`version`, CASE WHEN CHAR_LENGTH(`c`.`alias`) != 0 THEN CONCAT_WS(':', `c`.`id`, `c`.`alias`) ELSE `c`.`id` END as `slug`
FROM `jos_categories` AS `s`
INNER JOIN `jos_categories` AS `c` ON (`s`.`lft` < `c`.`lft` AND `c`.`lft` < `s`.`rgt` AND `c`.`language` IN (:preparedArray3,:preparedArray4)) OR (`c`.`lft` <= `s`.`lft` AND `s`.`rgt` <= `c`.`rgt`)
WHERE (`c`.`extension` = :extension OR `c`.`extension` = 'system') AND `c`.`access` IN (:preparedArray1,:preparedArray2) AND `c`.`published` = 1 AND `s`.`id` = :id
ORDER BY `c`.`lft`

Expected result AFTER applying this Pull Request

Only single query with the same params.

Link to documentations

Please select:

  • No documentation changes for docs.joomla.org needed
  • No documentation changes for manual.joomla.org needed

@ceford
Copy link
Contributor

ceford commented Sep 18, 2025

Not sure about this. With the patch applied I see the number of queries decrease by 1 but the query quoted above is still duplicated. Without the patch there are 3 instances, with the patch there are two instancies.

SELECT `c`.`id`,`c`.`asset_id`,`c`.`access`,`c`.`alias`,`c`.`checked_out`,`c`.`checked_out_time`,`c`.`created_time`,`c`.`created_user_id`,`c`.`description`,`c`.`extension`,`c`.`hits`,`c`.`language`,`c`.`level`,`c`.`lft`,`c`.`metadata`,`c`.`metadesc`,`c`.`metakey`,`c`.`modified_time`,`c`.`note`,`c`.`params`,`c`.`parent_id`,`c`.`path`,`c`.`published`,`c`.`rgt`,`c`.`title`,`c`.`modified_user_id`,`c`.`version`, CASE WHEN CHAR_LENGTH(`c`.`alias`) != 0 THEN CONCAT_WS(':', `c`.`id`, `c`.`alias`) ELSE `c`.`id` END as `slug`
FROM `kxq29_categories` AS `s`
INNER JOIN `kxq29_categories` AS `c` ON (`s`.`lft` < `c`.`lft` AND `c`.`lft` < `s`.`rgt` AND `c`.`language` IN (:preparedArray3,:preparedArray4)) OR (`c`.`lft` <= `s`.`lft` AND `s`.`rgt` <= `c`.`rgt`)
WHERE (`c`.`extension` = :extension OR `c`.`extension` = 'system') AND `c`.`access` IN (:preparedArray1,:preparedArray2) AND `c`.`published` = 1 AND `s`.`id` = :id
ORDER BY `c`.`lft`
```<hr /><sub>This comment was created with the <a href="https://github.com/joomla/jissues">J!Tracker Application</a> at <a href="https://issues.joomla.org/tracker/joomla-cms/46084">issues.joomla.org/tracker/joomla-cms/46084</a>.</sub>

@laoneo
Copy link
Member

laoneo commented Sep 18, 2025

Instead of modifying the existing one, I would create a new one. Like that you don't risk bc breaks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants