[Rt-commit] rt branch, 4.2/cache-ocfvs-on-update, repushed

Jim Brandt jbrandt at bestpractical.com
Thu Sep 21 10:16:33 EDT 2017


The branch 4.2/cache-ocfvs-on-update was deleted and repushed:
       was a0c7b1207ca4909d0e46eddb7278015e2e5bed79
       now 177e890acb377dff5da7fc18569973fc7c8623a5

1:  97a3570 ! 1:  177e890 Cache OCFVs to improve performance searching for duplicates on add
    @@ -24,6 +24,19 @@
      
          my $ret = $oldval->Delete();
     
    +diff --git a/lib/RT/Interface/Web/Handler.pm b/lib/RT/Interface/Web/Handler.pm
    +--- a/lib/RT/Interface/Web/Handler.pm
    ++++ b/lib/RT/Interface/Web/Handler.pm
    +@@
    +     File::Temp::cleanup()
    +             unless $INC{'Test/WWW/Mechanize/PSGI.pm'};
    + 
    +-
    ++    RT::ObjectCustomFieldValues::ClearOCFVCache();
    + }
    + 
    + 
    +
     diff --git a/lib/RT/ObjectCustomFieldValue.pm b/lib/RT/ObjectCustomFieldValue.pm
     --- a/lib/RT/ObjectCustomFieldValue.pm
     +++ b/lib/RT/ObjectCustomFieldValue.pm
    @@ -97,7 +110,6 @@
     +        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 };
    @@ -108,6 +120,7 @@
     -    #TODO: this could cache and optimize a fair bit.
     -    foreach my $item ( @{$self->ItemsArrayRef} ) {
     -        my $cf = $item->CustomFieldObj;
    ++    my $item_id;
     +    foreach my $item ( @{$_OCFV_CACHE->{$ocfv_key}} ) {
     +        my $cf = $item->{'CustomFieldObj'};
              my $args = $canon_value{ $cf->Type };
    @@ -118,7 +131,7 @@
              if ( $cf->Type eq 'Select' ) {
                  # select is case insensitive
     -            return $item if lc $item->Content eq lc $args->{Content};
    -+            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->_Value('Content') // '') eq $args->{Content} ) {
    @@ -126,26 +139,38 @@
     -                    return $item
     +            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};
     +                      && $item->{'LargeContent'} eq $args->{LargeContent};
                      }
                      else {
     -                    return $item unless defined $args->{LargeContent};
    -+                    return $item->{'Object'} unless defined $args->{LargeContent};
    ++                    $item_id = $item->{'ObjectId'} unless defined $args->{LargeContent};
                      }
     -            } elsif ( $item->LargeContent && $args->{Content} ) {
     -                return $item if ($item->LargeContent eq $args->{Content});
     +            } 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;
    ++    }
    ++
    ++    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;
          }
    -+
    -     return undef;
    - }
    - 
    +-    return undef;
    + }
    + 
    + sub _DoSearch {
     
     diff --git a/lib/RT/Record.pm b/lib/RT/Record.pm
     --- a/lib/RT/Record.pm
    @@ -170,7 +195,6 @@
     +        # 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'} };
    @@ -189,7 +213,7 @@
     +        # 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'} };
    @@ -197,4 +221,3 @@
              if ( $args{'RecordTransaction'} ) {
                  my ( $tid, $msg ) = $self->_NewTransaction(
                      Type          => 'CustomField',
    -
2:  8b19740 < -:  ------- Don't store object in the cache
3:  a0c7b12 < -:  ------- Clear the OCFVCache



More information about the rt-commit mailing list