[Rt-commit] rt branch, 4.2/cache-ocfvs-on-update, updated. rt-4.2.14-9-g8b19740

Jim Brandt jbrandt at bestpractical.com
Tue Sep 19 15:41:38 EDT 2017


The branch, 4.2/cache-ocfvs-on-update has been updated
       via  8b197401ae6c35349f7ab42ac8e5bfd49181e5b1 (commit)
      from  97a3570b6cfdfa78eee027eb753ea237541b0cba (commit)

Summary of changes:
 lib/RT/ObjectCustomFieldValues.pm | 22 ++++++++++++++++------
 lib/RT/Record.pm                  |  3 +--
 2 files changed, 17 insertions(+), 8 deletions(-)

- Log -----------------------------------------------------------------
commit 8b197401ae6c35349f7ab42ac8e5bfd49181e5b1
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Tue Sep 19 15:41:29 2017 -0400

    Don't store object in the cache

diff --git a/lib/RT/ObjectCustomFieldValues.pm b/lib/RT/ObjectCustomFieldValues.pm
index 4bcc7ec..24d81c5 100644
--- a/lib/RT/ObjectCustomFieldValues.pm
+++ b/lib/RT/ObjectCustomFieldValues.pm
@@ -156,7 +156,6 @@ sub HasEntry {
         foreach my $item ( @{$self->ItemsArrayRef} ) {
             push @{$_OCFV_CACHE->{$ocfv_key}}, {
                 'ObjectId'       => $item->Id,
-                'Object'         => $item,
                 'CustomFieldObj' => $item->CustomFieldObj,
                 'Content'        => $item->_Value('Content'),
                 'LargeContent'   => $item->LargeContent };
@@ -164,6 +163,7 @@ sub HasEntry {
     }
 
     my %canon_value;
+    my $item_id;
     foreach my $item ( @{$_OCFV_CACHE->{$ocfv_key}} ) {
         my $cf = $item->{'CustomFieldObj'};
         my $args = $canon_value{ $cf->Type };
@@ -176,25 +176,35 @@ sub HasEntry {
 
         if ( $cf->Type eq 'Select' ) {
             # select is case insensitive
-            return $item->{'Object'} if lc $item->{'Content'} eq lc $args->{Content};
+            $item_id = $item->{'ObjectId'} if lc $item->{'Content'} eq lc $args->{Content};
         }
         else {
             if ( ($item->{'Content'} // '') eq $args->{Content} ) {
                 if ( defined $item->{'LargeContent'} ) {
-                    return $item->{'Object'}
+                    $item_id = $item->{'ObjectId'}
                       if defined $args->{LargeContent}
                       && $item->{'LargeContent'} eq $args->{LargeContent};
                 }
                 else {
-                    return $item->{'Object'} unless defined $args->{LargeContent};
+                    $item_id = $item->{'ObjectId'} unless defined $args->{LargeContent};
                 }
             } elsif ( $item->{'LargeContent'} && $args->{Content} ) {
-                return $item->{'Object'} if ($item->{'LargeContent'} eq $args->{Content});
+                $item_id = $item->{'ObjectId'} if ($item->{'LargeContent'} eq $args->{Content});
             }
         }
+        last if $item_id;
     }
 
-    return undef;
+    if ( $item_id ) {
+        my $ocfv = RT::ObjectCustomFieldValue->new( $self->CurrentUser );
+        my ($ret, $msg) = $ocfv->Load($item_id);
+        RT::Logger->error("Unable to load object custom field value from id: $item_id $msg")
+            unless $ret;
+        return $ocfv;
+    }
+    else {
+        return undef;
+    }
 }
 
 sub _DoSearch {
diff --git a/lib/RT/Record.pm b/lib/RT/Record.pm
index 8e0392b..9c1ab8d 100644
--- a/lib/RT/Record.pm
+++ b/lib/RT/Record.pm
@@ -2066,7 +2066,6 @@ sub _AddCustomFieldValue {
         # Add the new one
         push @{$RT::ObjectCustomFieldValues::_OCFV_CACHE->{$ocfv_key}}, {
             'ObjectId'       => $new_value->Id,
-            'Object'         => $new_value,
             'CustomFieldObj' => $new_value->CustomFieldObj,
             'Content'        => $args{'Value'},
             'LargeContent'   => $args{'LargeContent'} };
@@ -2139,7 +2138,7 @@ sub _AddCustomFieldValue {
         # Update the OCFV cache
         my $ocfv_key = $new_value->GetOCFVCacheKey;
         push @{$RT::ObjectCustomFieldValues::_OCFV_CACHE->{$ocfv_key}}, {
-            'Object'         => $new_value,
+            'ObjectId'       => $new_value->Id,
             'CustomFieldObj' => $new_value->CustomFieldObj,
             'Content'        => $args{'Value'},
             'LargeContent'   => $args{'LargeContent'} };

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


More information about the rt-commit mailing list