[Rt-commit] rt branch, 5.0/cache-custom-field-values, created. rt-5.0.0-118-gf4162ca336
Dianne Skoll
dianne at bestpractical.com
Tue Nov 17 15:44:36 EST 2020
The branch, 5.0/cache-custom-field-values has been created
at f4162ca3369437efa3d8d9a34bbbcd272dd9274d (commit)
- Log -----------------------------------------------------------------
commit f4162ca3369437efa3d8d9a34bbbcd272dd9274d
Author: Dianne Skoll <dianne at bestpractical.com>
Date: Tue Nov 17 15:43:24 2020 -0500
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
index ae1ac0bd19..13d2b9393e 100644
--- a/lib/RT/CustomField.pm
+++ b/lib/RT/CustomField.pm
@@ -647,6 +647,29 @@ sub Values {
return ($cf_values);
}
+=head3 CachedValues FIELD, REQUEST_OBJ
+
+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.
+
+=cut
+sub CachedValues {
+ my $self = shift;
+ my $m = shift;
+
+ my $key = 'CF-' . $self->Id . '-Values';
+
+ if ($m->notes($key)) {
+ # Reset the iterator so we always start from the beginning
+ $m->notes($key)->GotoFirstItem;
+ return $m->notes($key);
+ }
+
+ # Wasn't in the cache; grab it and cache it.
+ $m->notes($key, $self->Values);
+ return $m->notes($key);
+}
=head3 AddValue HASH
diff --git a/share/html/Elements/EditCustomFieldCombobox b/share/html/Elements/EditCustomFieldCombobox
index 54e14bd7eb..ac27480975 100644
--- a/share/html/Elements/EditCustomFieldCombobox
+++ b/share/html/Elements/EditCustomFieldCombobox
@@ -56,7 +56,7 @@
Default => $Default,
Rows => $Rows,
Class => "CF-".$CustomField->id."-Edit",
- Values => [map {$_->Name} @{$CustomField->Values->ItemsArrayRef}],
+ Values => [map {$_->Name} @{$CustomField->CachedValues($m)->ItemsArrayRef}],
&>
<%INIT>
diff --git a/share/html/Elements/EditCustomFieldSelect b/share/html/Elements/EditCustomFieldSelect
index eccdbabd8f..ed09d69053 100644
--- a/share/html/Elements/EditCustomFieldSelect
+++ b/share/html/Elements/EditCustomFieldSelect
@@ -67,7 +67,7 @@
</div>
% }
% }
-% my $CFVs = $CustomField->Values;
+% my $CFVs = $CustomField->CachedValues($m);
% while ( my $value = $CFVs->Next ) {
% my $content = $value->Name;
% my $labelid = "$name-". $value->id;
@@ -153,7 +153,7 @@ else {
}
}
-my $use_chosen = $CustomField->Values->Count >= 10 ? 1 : 0;
+my $use_chosen = $CustomField->CachedValues($m)->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
@@ -183,7 +183,7 @@ $MaxValues => 1
% }
% $_ = lc $_ foreach @Default;
% my $selected;
-% my $CFVs = $CustomField->Values;
+% my $CFVs = $CustomField->CachedValues($m);
% my @levels;
% while ( my $value = $CFVs->Next ) {
% my $name = $value->Name;
diff --git a/share/html/Elements/SelectCustomFieldValue b/share/html/Elements/SelectCustomFieldValue
index 18af1e7a0d..64651ea978 100644
--- a/share/html/Elements/SelectCustomFieldValue
+++ b/share/html/Elements/SelectCustomFieldValue
@@ -48,7 +48,7 @@
% $m->callback( Name => $Name, CustomField => $CustomField, Default => \$Default );
% $Default = "" unless defined $Default;
% if ($CustomField->Type =~ /Select/i) {
-% my $values = $CustomField->Values;
+% my $values = $CustomField->CachedValues($m);
<select name="<%$Name%>" class="form-control selectpicker">
<option value="" selected="selected">-</option>
<option value="NULL"><&|/l&>(no value)</&></option>
@@ -62,7 +62,7 @@
<input type="text" id="CF-<% $CustomField->id %>" name="<% $Name %>" size="20" value="<% $Default %>" />
<script type="text/javascript">
% my @options;
-% my $values = $CustomField->Values;
+% my $values = $CustomField->CachedValues($m);
% while (my $value = $values->Next) {
% push @options, {
% value => $value->Name,
-----------------------------------------------------------------------
More information about the rt-commit
mailing list