Skip to content

[6.0] Multiload of article associations #39189

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

Open
wants to merge 32 commits into
base: 6.0-dev
Choose a base branch
from

Conversation

Denitz
Copy link
Contributor

@Denitz Denitz commented Nov 11, 2022

Summary of Changes

Load language associations for multiple articles and categories in a single query per each ArticlesModel::getItems() call.

These methods now can accept array of IDs and return results grouped by ID in this case.
If a single int is provided as ID, the results are returned as they were before, full BC.

CategoriesHelper::getAssociations()
CategoryAssociationHelper::getCategoryAssociations()
AssociationHelper::getAssociations()
Associations::getAssociations

Also, CategoriesHelper::getAssociations() is optimized and an extra query for each loaded category is removed by using $advClause param of Associations::getAssociations().

ArticlesModel::getItems() now collects the article IDs to load the assocations for, next loads all associations in the single query.
Similar to I have already done with tags load.

Testing Instructions

  1. Install 5.0-beta2-dev
  2. Install German language
  3. Install Sample multingual data
  4. Clone each English article "Article (en-gb)" (edit it and click Save As Copy 2 times), we have 3 en-GB articles now.
  5. Clone each German article"Beitrag (de-de)" (edit it and click Save As Copy 2 times, we have 3 de-DE articles now.
  6. Edit 2nd and 3rd copies of articles and associate them. Now we have 3 en-GB articles asociated with 3 de-DE articles.
  7. Enable Joomla debug
  8. Enable "Associations" in com_content options (they can be enabled in homepage menu item settings but it doesn't work for some reason, looks like another issuse, hence we need to enable display of associations globally).
  9. Load frontend, see list of articles from a category with 37 SQL queries executed in debug bar, for each articles we load associated article in a separate query.
  10. Apply patch, see a single query which loads associated articles for all displayed articles.

Actual result BEFORE applying this Pull Request

37 queries in total, see a separate SQL query for each displayed article, like:

SELECT `c2`.`language`,CONCAT_WS(':', `c2`.`id`, `c2`.`alias`) AS `id`,CONCAT_WS(':', `ca`.`id`, `ca`.`alias`) AS `catid`
FROM `jos_content` AS `c`
INNER JOIN `jos_associations` AS `a` ON `a`.`id` = `c`.`id` AND `a`.`context` = :context
INNER JOIN `jos_associations` AS `a2` ON `a`.`key` = `a2`.`key`
INNER JOIN `jos_content` AS `c2` ON `a2`.`id` = `c2`.`id`
INNER JOIN `jos_categories` AS `ca` ON `c2`.`catid` = `ca`.`id` AND `ca`.`extension` = :extension2
...

Expected result AFTER applying this Pull Request

34 queries in total, see a single query per each ArticlesModel::getItems() call.

A new single query is like:

SELECT `c2`.`language`,`c`.`id` AS `pk`,CONCAT_WS(':', `c2`.`id`, `c2`.`alias`) AS `id`,CONCAT_WS(':', `ca`.`id`, `ca`.`alias`) AS `catid`
FROM `jos_content` AS `c`
INNER JOIN `jos_associations` AS `a` ON `a`.`id` = `c`.`id` AND `a`.`context` = :context
INNER JOIN `jos_associations` AS `a2` ON `a`.`key` = `a2`.`key`
INNER JOIN `jos_content` AS `c2` ON `a2`.`id` = `c2`.`id`
INNER JOIN `jos_categories` AS `ca` ON `c2`.`catid` = `ca`.`id` AND `ca`.`extension` = :extension2
...

Link to documentations

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

@richard67
Copy link
Member

I don't see it as a bug fix but as an improvement, so it should be made for the 4.3-dev branch and not the 4.2-dev branch.

@Denitz Denitz changed the base branch from 4.2-dev to 4.3-dev November 11, 2022 13:14
@Denitz
Copy link
Contributor Author

Denitz commented Nov 11, 2022

@richard67 Sorry, rebased.

@richard67
Copy link
Member

Thanks.

@Hackwar Hackwar added the Feature label Apr 7, 2023
@HLeithner HLeithner changed the base branch from 4.3-dev to 5.0-dev May 8, 2023 15:02
@HLeithner
Copy link
Member

This pull request has been automatically rebased to 5.0-dev. No new features will be merged into Joomla! 4.3 series. Joomla! 4.4 series is a bridge release to make migration from Joomla! 4 to 5 as smooth as possible.

@ceford
Copy link
Contributor

ceford commented Sep 15, 2023

This does not work for me - perhaps I have misunderstood the instructions. I selected the testing data All Frontend Views / Content Component / Article Category List. The debug queries show there are 10 Select calls as shown above both with and without the patch applied (my list length). With the patch applied there are 50 queries in total, without the patch there are 49.


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

@Denitz
Copy link
Contributor Author

Denitz commented Sep 16, 2023

@ceford Sorry, I've updated the test instructions for 5.0.0-bet2-dev, we need to enable display of associated articles.

@Denitz
Copy link
Contributor Author

Denitz commented Feb 29, 2024

@Hackwar updated

@HLeithner
Copy link
Member

This pull request has been automatically rebased to 5.2-dev.

@HLeithner HLeithner changed the base branch from 5.1-dev to 5.2-dev April 24, 2024 09:09
@HLeithner HLeithner changed the title [5.1] Multiload of article associations [5.2] Multiload of article associations Apr 24, 2024
@Hackwar
Copy link
Member

Hackwar commented Jul 24, 2024

@fgsw @Nuyonuyonoina Can you test this again?

@HLeithner HLeithner changed the base branch from 5.2-dev to 5.3-dev September 2, 2024 08:53
@HLeithner
Copy link
Member

This pull request has been automatically rebased to 5.3-dev.

@HLeithner HLeithner changed the title [5.2] Multiload of article associations [5.3] Multiload of article associations Sep 2, 2024
@Hackwar Hackwar removed the PR-5.2-dev label Sep 3, 2024
@ghost
Copy link

ghost commented Sep 4, 2024

I have tested this item ✅ successfully on ee1851d


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

@HLeithner HLeithner changed the base branch from 5.3-dev to 6.0-dev March 4, 2025 17:22
@HLeithner
Copy link
Member

This pull request has been automatically rebased to 6.0-dev.

@HLeithner HLeithner changed the title [5.3] Multiload of article associations [6.0] Multiload of article associations Mar 4, 2025
@rdeutz rdeutz removed the PR-5.3-dev label Mar 5, 2025
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.

9 participants