Skip to content
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

Joomla Permissions Issue - Slow Performance and Timeouts with Non-Super Users #43649

Open
MayaSima opened this issue Jun 13, 2024 · 4 comments
Open

Comments

@MayaSima
Copy link

Description:

I am experiencing performance issues with Joomla permissions on version 5.1.1. I created a group intended to have backend access, specifically to create or edit content. While everything works fine in general, accessing Content >> Articles is extremely slow and often times out or crashes the page. This issue arises when attempting to list articles. However, this problem does not occur when you log in as a Super User.

Steps to Reproduce:

  1. Create a new user group with permissions to create or edit content.
    
  2. Log in as a user from this group.
    
  3. Navigate to Content >> Articles.
    

Expected Result:

The articles list should load efficiently without significant delay or timeouts.

Actual Result:

The page loads extremely slowly, often timing out and crashing.

Debugging Information:

Using the Joomla debugging tool, we discovered that:

  • For non-Super Users, Joomla checks the asset table permissions for each article individually.
    
  • This behavior does not occur with Super Users.
    

Screenshot:

The attached screenshot shows a profile trace comparison:

  •     Left: Profile trace of a Super User.
    
  •     Right: Profile trace of a user with set permissions.
    

Attachment

Screenshot 2024-06-13 143030

Question:

Can you confirm if this is a bug or native Joomla behavior?

Environment:

  • Joomla Version: 5.1.1
    
  • Number of Articles: ~9000
    

Additional Information:

The issue seems to be tied to how Joomla processes permissions for non-Super Users, causing a performance bottleneck when listing a large number of articles. Any insights or workarounds to alleviate this issue would be greatly appreciated.

@Fedik
Copy link
Member

Fedik commented Jun 13, 2024

This happens because Access::preloadPermissions() preloads permissions for ALL 9000 articles
(which is around 90MB from your screenshot)

protected static function preloadPermissions($assetType, $reload = false)

I set it as bug, however I have no idea how it can be fixed.
But I can understand that it gives a really bad experience of use the content editing.

It probably for all Joomla versions. Cannot find older similar issue about it.

@Fedik

This comment was marked as outdated.

@MayaSima
Copy link
Author

I tried changing $preload to $preload = false in joomla-cms/libraries/src/Access/Access.php at line 155, but the issue still persists.

@Fedik
Copy link
Member

Fedik commented Jun 17, 2024

Okay, I think now instead one large DB query you got a few hundrets of small DB queries. That is why it is still slow.

Another thing to try is to plreload only needed items, that in the current view.
Try, edit the articles list layout administrator/components/com_content/tmpl/articles/default.php
And place following code for preload, somewhere around line 70 (before the html rendering):

$accessWorkAround = new class () extends \Joomla\CMS\Access\Access
{
    // Preload only needed items
    public static function verySmartPreload($assetType, $assetsList, $key = 'id')
    {
        $extensionName = self::getExtensionNameFromAsset($assetType);

        /** @var \Joomla\Database\Mysql\MysqlDriver $db */
        $db    = Factory::getContainer()->get(\Joomla\Database\DatabaseInterface::class);
        /** @var \Joomla\Database\Mysql\MysqlQuery $query */
        $query = $db->getQuery(true);
        $query->select($db->quoteName(['id', 'name', 'rules', 'parent_id']))
            ->from($db->quoteName('#__assets'))
            ->where(
                $db->quoteName($key) . ' IN ('
                . implode(',', $query->bindArray($assetsList, \Joomla\Database\ParameterType::STRING)) . ')'
            );

        $assets = $db->setQuery($query)->loadObjectList();

        foreach ($assets as $asset) {
            self::$assetPermissionsParentIdMapping[$extensionName][$asset->id] = $asset;
            self::$preloadedAssets[$asset->id]                                 = $asset->name;
        }

        // Temporary mark as preloaded
        self::$preloadedAssetTypes[$assetType] = true;
    }

    public static function resetVerySmartPreload($assetType)
    {
        unset(self::$preloadedAssetTypes[$assetType]);
    }
};
$assetsList = [];
foreach ($this->items as $item) {
    $assetsList[] = 'com_content.article.' . $item->id;

    if (!empty($item->catid)) {
        $assetsList[] = 'com_content.category.' . $item->catid;
    }
}

$accessWorkAround::verySmartPreload('com_content.article', $assetsList, 'name');

then at the end of the file:

<?php $accessWorkAround::resetVerySmartPreload('com_content.article'); ?>

And please tell us if it help.
The editing form still will be slow, however the list view should be much faster.

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

No branches or pull requests

3 participants