Search
Other Articles Field questions
Forum

Query optimization for Articles Linked Field

Andrea Malalana's Avatar Andrea Malalana
Hey there,

Since Articles Linked Field supports both standard Articles Fields, as well as Articles Field part of a subform, the current query also does an RLIKE condition to find subform occurrences of the given article id.

However, this slows down the query quite a bit, even taking up to 0.30 seconds. While just the query that only looks up standard articles fields (not in subform) would take 0.00 seconds.

See confidential image as a comparison:
Confidential information:
(hidden)


So I'm wondering:

Instead of doing it in one single WHERE with a OR in-between, is it possible to split these into two separate queries? Maybe it would be better for performance?

Also, another idea: in most cases, it's not needed to look up Subform fields. Maybe it would be nice to add a "Linked Subforms" option under "Linked Fields", like this:



If Linked Subforms is compiled, then it adds the Subform query, searching within the selected field_ids (instead of having to to a IN(all_subforms_field_ids) like it is now). If it's not compiled, then it doesn't do the Subform query at all.

What do you think of these improvements?
Peter van Westen's Avatar Peter van Westen ADMIN
The new dev version splits the query. But I doubt it will make much of a difference in performance.
regularlabs.com/development-releases

I think the Linked Subforms option would be pretty confusing for people to use and wrap their head around. Don't think it is worth adding that.
Please post a rating at the Joomla! Extensions Directory
Andrea Malalana's Avatar Andrea Malalana
The new dev version splits the query.
Nice!

PS: Just so you know the current version gives a query error:

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'field(146)\"🙁\\[[^\\]]*)?\"22605\""' at line 3

Call Stack
# Function Location
1 () JROOT/libraries/vendor/joomla/database/src/Mysqli/MysqliStatement.php:138
2 mysqli->prepare() JROOT/libraries/vendor/joomla/database/src/Mysqli/MysqliStatement.php:138
3 Joomla\Database\Mysqli\MysqliStatement->__construct() JROOT/libraries/vendor/joomla/database/src/Mysqli/MysqliDriver.php:1020
4 Joomla\Database\Mysqli\MysqliDriver->prepareStatement() JROOT/libraries/vendor/joomla/database/src/DatabaseDriver.php:1785
5 Joomla\Database\DatabaseDriver->setQuery() JROOT/plugins/fields/articles/src/Helper.php:558
6 RegularLabs\Plugin\Fields\Articles\Helper::getLinkedArticleIdsByFieldId() JROOT/plugins/fields/articles/src/Helper.php:103
I think the Linked Subforms option would be pretty confusing for people to use and wrap their head around. Don't think it is worth adding that.

Maybe you could do a simpler radio toggle, then. eg:
"Also Lookup Subforms?" YES/NO

With default on Yes for BC.

So it can be turned to NO for fields that don't need look up in Subform, and it saves having to do the Subform query when not needed?
Peter van Westen's Avatar Peter van Westen ADMIN
Error should be fixed now:
regularlabs.com/development-releases
Please post a rating at the Joomla! Extensions Directory
Andrea Malalana's Avatar Andrea Malalana
Something wrong with the query. The articles linked from a Subform field are not listed anymore in the output.
Andrea Malalana's Avatar Andrea Malalana
I confirm that it now works correctly with the latest dev version 🙂

What do you think about the toggle idea? As, like you said, even with the query split in 2, performance has not much improved, and maybe a toggle would be nice to avoid doing the Subform query for fields that don't need it.
Andrea Malalana's Avatar Andrea Malalana
Awesome! Already tested, it works, and I do see a great performance benefit especially when using many fields. Very cool!
Peter van Westen's Avatar Peter van Westen ADMIN
👍
The new feature will be included in the next release.
Please post a rating at the Joomla! Extensions Directory
Andrea Malalana's Avatar Andrea Malalana
Hey there, not sure if related, but with the latest dev version I get this error when saving an article from the backend:
i.imgur.com/PGPZJr0.png
Peter van Westen's Avatar Peter van Westen ADMIN
Should be fixed now...
Please post a rating at the Joomla! Extensions Directory
Andrea Malalana's Avatar Andrea Malalana
Yup 🙂
You can only post on the extension support forum if you have an active subscription and you log in

Buy a Pro subscription