[Rt-commit] rt branch, 5.0/cache-custom-field-values, repushed
Dianne Skoll
dianne at bestpractical.com
Wed Nov 18 15:00:58 EST 2020
The branch 5.0/cache-custom-field-values was deleted and repushed:
was f4162ca3369437efa3d8d9a34bbbcd272dd9274d
now a565a544800538843f796e1f82b4724c3ad30af2
1: f4162ca336 ! 1: a565a54480 Cache custom field values to improve performance when displaying many tickets with editable custom fields.
@@ -2,25 +2,23 @@
Cache custom field values to improve performance when displaying many tickets with editable custom fields.
-diff --git a/lib/RT/CustomField.pm b/lib/RT/CustomField.pm
---- a/lib/RT/CustomField.pm
-+++ b/lib/RT/CustomField.pm
+diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
+--- a/lib/RT/Interface/Web.pm
++++ b/lib/RT/Interface/Web.pm
@@
- return ($cf_values);
+ return @results;
}
-+=head3 CachedValues FIELD, REQUEST_OBJ
++=head3 CachedCustomFieldValues FIELD
+
-+Similar to Values, but additionally passed an HTML::Mason request object
-+$m. Caches the return value of Values in $m->notes in anticipation of
-+it being used again.
++Similar to FIELD->Values, but caches the return value of FIELD->Values
++in $m->notes in anticipation of it being used again.
+
+=cut
-+sub CachedValues {
-+ my $self = shift;
-+ my $m = shift;
++sub CachedCustomFieldValues {
++ my $cf = shift;
+
-+ my $key = 'CF-' . $self->Id . '-Values';
++ my $key = 'CF-' . $cf->Id . '-Values';
+
+ if ($m->notes($key)) {
+ # Reset the iterator so we always start from the beginning
@@ -29,11 +27,12 @@
+ }
+
+ # Wasn't in the cache; grab it and cache it.
-+ $m->notes($key, $self->Values);
++ $m->notes($key, $cf->Values);
+ return $m->notes($key);
+}
-
- =head3 AddValue HASH
++
+ package RT::Interface::Web;
+ RT::Base->_ImportOverlays();
diff --git a/share/html/Elements/EditCustomFieldCombobox b/share/html/Elements/EditCustomFieldCombobox
@@ -44,7 +43,7 @@
Rows => $Rows,
Class => "CF-".$CustomField->id."-Edit",
- Values => [map {$_->Name} @{$CustomField->Values->ItemsArrayRef}],
-+ Values => [map {$_->Name} @{$CustomField->CachedValues($m)->ItemsArrayRef}],
++ Values => [map {$_->Name} @{CachedCustomFieldValues($CustomField)->ItemsArrayRef}],
&>
<%INIT>
@@ -57,7 +56,7 @@
% }
% }
-% my $CFVs = $CustomField->Values;
-+% my $CFVs = $CustomField->CachedValues($m);
++% my $CFVs = CachedCustomFieldValues($CustomField);
% while ( my $value = $CFVs->Next ) {
% my $content = $value->Name;
% my $labelid = "$name-". $value->id;
@@ -66,7 +65,7 @@
}
-my $use_chosen = $CustomField->Values->Count >= 10 ? 1 : 0;
-+my $use_chosen = $CustomField->CachedValues($m)->Count >= 10 ? 1 : 0;
++my $use_chosen = CachedCustomFieldValues($CustomField)->Count >= 10 ? 1 : 0;
$m->callback( CallbackName => 'Chosen', UseChosen => \$use_chosen, CustomField => $CustomField );
# it's weird to see "(no value) X" in the input when selecting multiple values
@@ -75,7 +74,7 @@
% $_ = lc $_ foreach @Default;
% my $selected;
-% my $CFVs = $CustomField->Values;
-+% my $CFVs = $CustomField->CachedValues($m);
++% my $CFVs = CachedCustomFieldValues($CustomField);
% my @levels;
% while ( my $value = $CFVs->Next ) {
% my $name = $value->Name;
@@ -88,7 +87,7 @@
% $Default = "" unless defined $Default;
% if ($CustomField->Type =~ /Select/i) {
-% my $values = $CustomField->Values;
-+% my $values = $CustomField->CachedValues($m);
++% my $values = CachedCustomFieldValues($CustomField);
<select name="<%$Name%>" class="form-control selectpicker">
<option value="" selected="selected">-</option>
<option value="NULL"><&|/l&>(no value)</&></option>
@@ -97,7 +96,7 @@
<script type="text/javascript">
% my @options;
-% my $values = $CustomField->Values;
-+% my $values = $CustomField->CachedValues($m);
++% my $values = CachedCustomFieldValues($CustomField);
% while (my $value = $values->Next) {
% push @options, {
% value => $value->Name,
More information about the rt-commit
mailing list