[Rt-commit] rt branch, 4.4/exclude-groups-in-watcher-join, created. rt-4.4.4-45-g392143541

? sunnavy sunnavy at bestpractical.com
Mon Jun 3 15:25:31 EDT 2019


The branch, 4.4/exclude-groups-in-watcher-join has been created
        at  392143541f4dd27b540bd1a161f33826bd4302e4 (commit)

- Log -----------------------------------------------------------------
commit 392143541f4dd27b540bd1a161f33826bd4302e4
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Tue Jun 4 03:04:00 2019 +0800

    Exclude user defined groups in role groups for _WatcherJoin
    
    _WatcherJoin is actaully for Users. As user defined groups are also
    supported in role groups, we need to exclude them here.  This commit
    fixes the wrong NULLs in Users table when user defined groups are in
    role groups. Without this, ticket search charts grouped by role groups
    will get wrong "(no value)" counts.

diff --git a/lib/RT/SearchBuilder/Role/Roles.pm b/lib/RT/SearchBuilder/Role/Roles.pm
index 5980882d3..f12faf2d7 100644
--- a/lib/RT/SearchBuilder/Role/Roles.pm
+++ b/lib/RT/SearchBuilder/Role/Roles.pm
@@ -190,10 +190,9 @@ sub _WatcherJoin {
     # XXX: work around, we must hide groups that
     # are members of the role group we search in,
     # otherwise them result in wrong NULLs in Users
-    # table and break ordering. Now, we know that
-    # RT doesn't allow to add groups as members of the
-    # ticket roles, so we just hide entries in CGM table
-    # with MemberId == GroupId from results
+    # table and break ordering.
+
+    # Exclude role groups themselves
     $self->Limit(
         LEFTJOIN   => $group_members,
         FIELD      => 'GroupId',
@@ -201,6 +200,26 @@ sub _WatcherJoin {
         VALUE      => "$group_members.MemberId",
         QUOTEVALUE => 0,
     );
+
+    # Exclude groups added in role groups.  It technially also covers
+    # the above limit, but with that limit, SQL could be faster as it
+    # reduces rows to process before the following join.
+
+    my $groups_2 = $self->Join(
+        TYPE   => 'LEFT',
+        ALIAS1 => $group_members,
+        FIELD1 => 'MemberId',
+        TABLE2 => 'Groups',
+        FIELD2 => 'id',
+    );
+    $self->Limit(
+        ALIAS           => $groups_2,
+        FIELD           => 'id',
+        OPERATOR        => 'IS',
+        VALUE           => 'NULL',
+        SUBCLAUSE       => "exclude_groups",
+    );
+
     my $users = $self->Join(
         TYPE            => 'LEFT',
         ALIAS1          => $group_members,

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


More information about the rt-commit mailing list