No Code Attached Yet bug
avatar salitygen
salitygen
16 Feb 2022

$fields = FieldsHelper::getFields('com_content.article', $oldItem, true);

The true flag is set, it must be removed or replaced with false, since this significantly loads the server and is not used in any way!

avatar salitygen salitygen - open - 16 Feb 2022
avatar joomla-cms-bot joomla-cms-bot - change - 16 Feb 2022
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 16 Feb 2022
avatar brianteeman
brianteeman - comment - 16 Feb 2022

Please provide your evidence. I am not saying you are right or wrong. But how can we test your assertion that it has an impact on the server or that it isnt used

avatar salitygen
salitygen - comment - 16 Feb 2022

The same is on line 247

According to the documentation, this flag means that the fields will be additionally processed by the template engine, but we use rawvalue and we do not need templating here, it goes to empty, when a massive operation occurs, the server is very heavily loaded trying to wrap the fields in a template that will be in value but will not be in rawvalue

avatar salitygen
salitygen - comment - 16 Feb 2022

Evidence is not needed, just look at what this operation is for, in this place it is meaningless

avatar brianteeman
brianteeman - comment - 16 Feb 2022

But how can we test your assertion that it has an impact on the server or that it isnt used

avatar salitygen
salitygen - comment - 16 Feb 2022

Fields like list, radio, and other multiple fields worsen the situation because they are additionally processed by the template engine. The more such fields a material has, the slower it is to save, move to another category, change the state of the material. This is not to mention group operations, it's even worse there.

avatar salitygen
salitygen - comment - 16 Feb 2022

Move 100 materials that have 100 properties to another category, and then the server will start turning fans very quickly))

avatar salitygen
salitygen - comment - 16 Feb 2022

#37072
An event is called there that is associated with this branch, in general, this can be combined into one problem

avatar salitygen
salitygen - comment - 17 Feb 2022

Evidence that in this context the true flag is simply not needed

The GetFields method in the FieldsHelper model

The third argument GetFields is $preparvalue = false
Let's see what it's for, let's go down below

if ($prepareValue && (is_bool($prepareValue) || $prepareValue === (int) $field->params->get('display', '2')))

It says here that if $preparvalue = true, the onCustomFieldsPrepareField event will be called with passing arguments for templating.

$value = Factory::getApplication()->triggerEvent('onCustomFieldsPrepareField', array($context, $item, &$field));

Let's see what the onCustomFieldsPrepareField method does, to which we pass arguments for templating.

public function onCustomFieldsPrepareField($context, $item, $field)

Inside we will see the templating

$path = PluginHelper::getLayoutPath('fields', $this->_name, $field->type);
ob_start();
include $path;
$output = ob_get_clean();
return $output;

The result of onCustomFieldsPrepareField will be saved in $field->value

After that, the FieldsHelper model will return us an array of $fields with objects
Which we use at this point by collecting the $fieldsData array

$fieldsData['com_fields'][$field->name] = $field->rawvalue;

After that, the $fieldsData array will be passed on, onContentAfterSave

Factory::getApplication()->triggerEvent('onContentAfterSave', array('com_content.article', &$this->table, false, $fieldsData));

As a result, a template engine was called, the result of which will be stored in $field->value, but $field->value was not used anywhere! But we used $field->rawvalue, which is available without the template engine.

$fields = FieldsHelper::getFields('com_content.article', $oldItem, true);

$fieldsData = array();

if (!empty($fields))
{
	$fieldsData['com_fields'] = array();

	foreach ($fields as $field)
	{
		$fieldsData['com_fields'][$field->name] = $field->rawvalue;
	}
}

Factory::getApplication()->triggerEvent('onContentAfterSave', array('com_content.article', &$this->table, false, $fieldsData));

It turns out that we just started templating, consumed server resources and did not use the result of the work in any way

avatar salitygen
salitygen - comment - 17 Feb 2022

$fields = FieldsHelper::getFields($context, $item, true);

It can significantly slow down the loading of the category. I can agree that someone actively uses prepared custom fields in their templates, but still in this place it is up to the user to decide whether to prepare the fields or not. I propose to make an add-in in the administrative panel for this flag in this context.

avatar chmst chmst - change - 23 Feb 2022
Title
Change the flag
Change the flag in FieldsHelper::getFields()
avatar chmst chmst - edited - 23 Feb 2022
avatar joomdonation
joomdonation - comment - 14 Nov 2022

By quick look at the code, seems a valid performance improvement to me although I haven't looked at it carefully enough yet. @laoneo Since you understand this better than anyone else, could you please look at this issue and make PR to improve it (or ask @salitygen to make PR)

avatar laoneo
laoneo - comment - 14 Nov 2022

I guess @salitygen is right here, that it can be changed to false as the value is not needed.

avatar joomdonation
joomdonation - comment - 14 Nov 2022

Thanks for confirming. @salitygen Could you please make PR with your suggested changes so that we can get this performance improvement ? Thanks !

avatar laoneo
laoneo - comment - 14 Nov 2022

As @wilsonge added the code in #1350, it would also make sense to ask him, why he added it with the true flag.

avatar joomdonation
joomdonation - comment - 14 Nov 2022

@laoneo Look like you linked wrong PR as I don't see any related change there.

avatar laoneo
laoneo - comment - 14 Nov 2022

Somehow the last 1 got lost, here is the pr #13501 I wanted to reference.

avatar Hackwar Hackwar - change - 17 Feb 2023
Labels Added: bug
avatar Hackwar Hackwar - labeled - 17 Feb 2023

Add a Comment

Login with GitHub to post a comment