[Rt-commit] rt branch, 4.4/cache-roles, updated. rt-4.4.4-108-gcd949cc256

? sunnavy sunnavy at bestpractical.com
Mon Jun 1 13:50:14 EDT 2020


The branch, 4.4/cache-roles has been updated
       via  cd949cc2568c5bf9df4eb8139f9d6d8311842a6a (commit)
       via  3c3727434c2b37f36d1170c64745887e02a0d220 (commit)
      from  53725266941c2aca7522ddea7439da52c1e899d1 (commit)

Summary of changes:
 lib/RT/CustomRole.pm | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

- Log -----------------------------------------------------------------
commit 3c3727434c2b37f36d1170c64745887e02a0d220
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Tue Jun 2 01:19:33 2020 +0800

    Only keep enabled roles in registered list
    
    This is mainly for performance, so we won't need to check if custom
    roles are enabled or not in AppliesToObjectPredicate(will do that in
    another commit).

diff --git a/lib/RT/CustomRole.pm b/lib/RT/CustomRole.pm
index 5d1bfb3d60..5f53424360 100644
--- a/lib/RT/CustomRole.pm
+++ b/lib/RT/CustomRole.pm
@@ -698,8 +698,12 @@ sub SetDisabled {
     $RT::Handle->Commit();
 
     if ( $value == 0 ) {
+        $self->_RegisterAsRole;
+        RT->System->CustomRoleCacheNeedsUpdate(1);
         return (1, $self->loc("Custom role enabled"));
     } else {
+        $self->_UnregisterAsRole;
+        RT->System->CustomRoleCacheNeedsUpdate(1);
         return (1, $self->loc("Custom role disabled"));
     }
 }

commit cd949cc2568c5bf9df4eb8139f9d6d8311842a6a
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Tue Jun 2 01:28:21 2020 +0800

    Tweak AppliesToObjectPredicate as all registered custom roles are enabled
    
    AppliesToObjectPredicate could be called quite a few times with class
    name "RT::Tickets" on ticket creation, in which case we can skip loading
    RT::CustomRole objects when all the registered ones are enabled.
    
    We tested an RT instance with 10+ custom roles, this change could
    improve the performance by about 3%.
    
    See also 3c3727434c

diff --git a/lib/RT/CustomRole.pm b/lib/RT/CustomRole.pm
index 5f53424360..cdcfbcf1a1 100644
--- a/lib/RT/CustomRole.pm
+++ b/lib/RT/CustomRole.pm
@@ -191,21 +191,19 @@ sub _RegisterAsRole {
         AppliesToObjectPredicate => sub {
             my $object = shift;
 
-            # reload the role to avoid capturing $self across requests
-            my $role = RT::CustomRole->new(RT->SystemUser);
-            $role->Load($id);
-
-            return 0 if $role->Disabled;
+            # for callers not specific to any queue, e.g. ColumnMap
+            if (!ref($object)) {
+                return 1;
+            }
 
             # all roles are also available on RT::System for granting rights
             if ($object->isa('RT::System')) {
                 return 1;
             }
 
-            # for callers not specific to any queue, e.g. ColumnMap
-            if (!ref($object)) {
-                return 1;
-            }
+            # reload the role to avoid capturing $self across requests
+            my $role = RT::CustomRole->new(RT->SystemUser);
+            $role->Load($id);
 
             # custom roles apply to queues, so canonicalize a ticket
             # into its queue

-----------------------------------------------------------------------


More information about the rt-commit mailing list