Uploaded image for project: 'Nuxeo Platform'
  1. Nuxeo Platform
  2. NXP-30657

Fix poor performance of automation helper functions

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 10.10, 2021.0
    • Fix Version/s: 10.10-HF55, 2021.12
    • Component/s: Automation
    • Release Notes Summary:
      The performance of "group" automation helper functions is improved.
    • Backlog priority:
      800
    • Sprint:
      nxplatform #47, nxplatform #48
    • Story Points:
      1

      Description

      Fn.getEmail(userName)

      Fn.getEmail(userName) automation helper function has poor performance if the provided username is member of groups having large number (tens of thousands) of members.

      If the user is member of groups group1, group2, group3, group4, and group5, the following traces gets generated when Fn.getEmail(userName) is called in an automation script:

      2021-10-11T15:54:24,717 TRACE [http-nio-0.0.0.0-8080-exec-1] [org.nuxeo.ecm.core.storage.sql.jdbc.JDBCLogger] (SQLDirectory) SQL: SELECT "groupId" FROM "user2group" WHERE "userId" = 'vdu1'
      2021-10-11T15:54:24,723 TRACE [http-nio-0.0.0.0-8080-exec-1] [org.nuxeo.ecm.core.storage.sql.jdbc.JDBCLogger] (SQLDirectory) SQL: SELECT "tenantId", "description", "grouplabel", "groupname" FROM "groups" WHERE "groupname" = 'group1'
      2021-10-11T15:54:24,723 TRACE [http-nio-0.0.0.0-8080-exec-1] [org.nuxeo.ecm.core.storage.sql.jdbc.JDBCLogger] (SQLDirectory) SQL:   -> tenantId=NULL, description=NULL, grouplabel='Group 1', groupname='group1'
      2021-10-11T15:54:24,724 TRACE [http-nio-0.0.0.0-8080-exec-1] [org.nuxeo.ecm.core.storage.sql.jdbc.JDBCLogger] (SQLDirectory) SQL: SELECT "parentGroupId" FROM "group2group" WHERE "childGroupId" = 'group1'
      2021-10-11T15:54:24,724 TRACE [http-nio-0.0.0.0-8080-exec-1] [org.nuxeo.ecm.core.storage.sql.jdbc.JDBCLogger] (SQLDirectory) SQL: SELECT "userId" FROM "user2group" WHERE "groupId" = 'group1'
      2021-10-11T15:54:24,725 TRACE [http-nio-0.0.0.0-8080-exec-1] [org.nuxeo.ecm.core.storage.sql.jdbc.JDBCLogger] (SQLDirectory) SQL: SELECT "childGroupId" FROM "group2group" WHERE "parentGroupId" = 'group1'
      2021-10-11T15:54:24,725 TRACE [http-nio-0.0.0.0-8080-exec-1] [org.nuxeo.ecm.core.storage.sql.jdbc.JDBCLogger] (SQLDirectory) SQL: SELECT "tenantId", "description", "grouplabel", "groupname" FROM "groups" WHERE "groupname" = 'group2'
      2021-10-11T15:54:24,726 TRACE [http-nio-0.0.0.0-8080-exec-1] [org.nuxeo.ecm.core.storage.sql.jdbc.JDBCLogger] (SQLDirectory) SQL:   -> tenantId=NULL, description=NULL, grouplabel='Group 2', groupname='group2'
      2021-10-11T15:54:24,726 TRACE [http-nio-0.0.0.0-8080-exec-1] [org.nuxeo.ecm.core.storage.sql.jdbc.JDBCLogger] (SQLDirectory) SQL: SELECT "parentGroupId" FROM "group2group" WHERE "childGroupId" = 'group2'
      2021-10-11T15:54:24,726 TRACE [http-nio-0.0.0.0-8080-exec-1] [org.nuxeo.ecm.core.storage.sql.jdbc.JDBCLogger] (SQLDirectory) SQL: SELECT "userId" FROM "user2group" WHERE "groupId" = 'group2'
      2021-10-11T15:54:24,763 TRACE [http-nio-0.0.0.0-8080-exec-1] [org.nuxeo.ecm.core.storage.sql.jdbc.JDBCLogger] (SQLDirectory) SQL: SELECT "childGroupId" FROM "group2group" WHERE "parentGroupId" = 'group2'
      2021-10-11T15:54:25,343 TRACE [http-nio-0.0.0.0-8080-exec-1] [org.nuxeo.ecm.core.storage.sql.jdbc.JDBCLogger] (SQLDirectory) SQL: SELECT "tenantId", "description", "grouplabel", "groupname" FROM "groups" WHERE "groupname" = 'group3'
      2021-10-11T15:54:25,344 TRACE [http-nio-0.0.0.0-8080-exec-1] [org.nuxeo.ecm.core.storage.sql.jdbc.JDBCLogger] (SQLDirectory) SQL:   -> tenantId=NULL, description=NULL, grouplabel='Group 3', groupname='group3'
      2021-10-11T15:54:25,344 TRACE [http-nio-0.0.0.0-8080-exec-1] [org.nuxeo.ecm.core.storage.sql.jdbc.JDBCLogger] (SQLDirectory) SQL: SELECT "parentGroupId" FROM "group2group" WHERE "childGroupId" = 'group3'
      2021-10-11T15:54:25,345 TRACE [http-nio-0.0.0.0-8080-exec-1] [org.nuxeo.ecm.core.storage.sql.jdbc.JDBCLogger] (SQLDirectory) SQL: SELECT "userId" FROM "user2group" WHERE "groupId" = 'group3'
      2021-10-11T15:54:25,347 TRACE [http-nio-0.0.0.0-8080-exec-1] [org.nuxeo.ecm.core.storage.sql.jdbc.JDBCLogger] (SQLDirectory) SQL: SELECT "childGroupId" FROM "group2group" WHERE "parentGroupId" = 'group3'
      2021-10-11T15:54:25,353 TRACE [http-nio-0.0.0.0-8080-exec-1] [org.nuxeo.ecm.core.storage.sql.jdbc.JDBCLogger] (SQLDirectory) SQL: SELECT "tenantId", "description", "grouplabel", "groupname" FROM "groups" WHERE "groupname" = 'group4'
      2021-10-11T15:54:25,354 TRACE [http-nio-0.0.0.0-8080-exec-1] [org.nuxeo.ecm.core.storage.sql.jdbc.JDBCLogger] (SQLDirectory) SQL:   -> tenantId=NULL, description=NULL, grouplabel='Group 4', groupname='group4'
      2021-10-11T15:54:25,354 TRACE [http-nio-0.0.0.0-8080-exec-1] [org.nuxeo.ecm.core.storage.sql.jdbc.JDBCLogger] (SQLDirectory) SQL: SELECT "parentGroupId" FROM "group2group" WHERE "childGroupId" = 'group4'
      2021-10-11T15:54:25,354 TRACE [http-nio-0.0.0.0-8080-exec-1] [org.nuxeo.ecm.core.storage.sql.jdbc.JDBCLogger] (SQLDirectory) SQL: SELECT "userId" FROM "user2group" WHERE "groupId" = 'group4'
      2021-10-11T15:54:25,373 TRACE [http-nio-0.0.0.0-8080-exec-1] [org.nuxeo.ecm.core.storage.sql.jdbc.JDBCLogger] (SQLDirectory) SQL: SELECT "childGroupId" FROM "group2group" WHERE "parentGroupId" = 'group4'
      2021-10-11T15:54:25,800 TRACE [http-nio-0.0.0.0-8080-exec-1] [org.nuxeo.ecm.core.storage.sql.jdbc.JDBCLogger] (SQLDirectory) SQL: SELECT "tenantId", "description", "grouplabel", "groupname" FROM "groups" WHERE "groupname" = 'group5'
      2021-10-11T15:54:25,801 TRACE [http-nio-0.0.0.0-8080-exec-1] [org.nuxeo.ecm.core.storage.sql.jdbc.JDBCLogger] (SQLDirectory) SQL:   -> tenantId=NULL, description=NULL, grouplabel='Group 5', groupname='group5'
      2021-10-11T15:54:25,801 TRACE [http-nio-0.0.0.0-8080-exec-1] [org.nuxeo.ecm.core.storage.sql.jdbc.JDBCLogger] (SQLDirectory) SQL: SELECT "parentGroupId" FROM "group2group" WHERE "childGroupId" = 'group5'
      2021-10-11T15:54:25,802 TRACE [http-nio-0.0.0.0-8080-exec-1] [org.nuxeo.ecm.core.storage.sql.jdbc.JDBCLogger] (SQLDirectory) SQL: SELECT "userId" FROM "user2group" WHERE "groupId" = 'group5'
      2021-10-11T15:54:25,816 TRACE [http-nio-0.0.0.0-8080-exec-1] [org.nuxeo.ecm.core.storage.sql.jdbc.JDBCLogger] (SQLDirectory) SQL: SELECT "childGroupId" FROM "group2group" WHERE "parentGroupId" = 'group5'
      

      These SQL queries are unnecessary when just retrieving the user's email address.

      The following code change prevents these SQL queries:

      diff --git a/nuxeo-features/nuxeo-automation/nuxeo-automation-features/src/main/java/org/nuxeo/ecm/automation/features/PlatformFunctions.java b/nuxeo-features/nuxeo-automation/nuxeo-automation-features/src/main/java/org/nuxeo/ecm/automation/features/PlatformFunctions.java
      index 2625d8e77fe..b9391c1d253 100644
      --- a/nuxeo-features/nuxeo-automation/nuxeo-automation-features/src/main/java/org/nuxeo/ecm/automation/features/PlatformFunctions.java
      +++ b/nuxeo-features/nuxeo-automation/nuxeo-automation-features/src/main/java/org/nuxeo/ecm/automation/features/PlatformFunctions.java
      @@ -97,7 +97,7 @@ public class PlatformFunctions extends CoreFunctions {
       
           public String getEmail(String username) {
               UserManager userManager = getUserManager();
      -        return getEmail(userManager.getPrincipal(username), userManager.getUserSchemaName(),
      +        return getEmail(userManager.getPrincipal(username, false), userManager.getUserSchemaName(),
                       userManager.getUserEmailField());
           }
       
      

      Fn.getEmailsFromGroup()

      It is overkill to call UserManager#getPrincipal(userName) in PrincipalHelper#collectObjectsFromGroup, which instantiates a NuxeoPrincipal object with all its references (groups and their members, virtual groups, ...), just to get the email address, email address that could be retrieved by simply getting the directory entry in directory userDirectory.

      This has very poor performance when the user is member of groups with many members.

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: