[Rt-commit] rt branch, 5.0/cache-custom-field-values, created. rt-5.0.0-118-ga565a54480
Dianne Skoll
dianne at bestpractical.com
Wed Nov 18 15:00:49 EST 2020
The branch, 5.0/cache-custom-field-values has been created
at a565a544800538843f796e1f82b4724c3ad30af2 (commit)
- Log -----------------------------------------------------------------
commit a565a544800538843f796e1f82b4724c3ad30af2
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/Interface/Web.pm b/lib/RT/Interface/Web.pm
index de32934bbb..b2421397d8 100644
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -5059,6 +5059,28 @@ sub ProcessAuthToken {
return @results;
}
+=head3 CachedCustomFieldValues FIELD
+
+Similar to FIELD->Values, but caches the return value of FIELD->Values
+in $m->notes in anticipation of it being used again.
+
+=cut
+sub CachedCustomFieldValues {
+ my $cf = shift;
+
+ my $key = 'CF-' . $cf->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, $cf->Values);
+ return $m->notes($key);
+}
+
package RT::Interface::Web;
RT::Base->_ImportOverlays();
diff --git a/share/html/Elements/EditCustomFieldCombobox b/share/html/Elements/EditCustomFieldCombobox
index 54e14bd7eb..e7ddfa84cf 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} @{CachedCustomFieldValues($CustomField)->ItemsArrayRef}],
&>
<%INIT>
diff --git a/share/html/Elements/EditCustomFieldSelect b/share/html/Elements/EditCustomFieldSelect
index eccdbabd8f..13c4c1f2f3 100644
--- a/share/html/Elements/EditCustomFieldSelect
+++ b/share/html/Elements/EditCustomFieldSelect
@@ -67,7 +67,7 @@
</div>
% }
% }
-% my $CFVs = $CustomField->Values;
+% my $CFVs = CachedCustomFieldValues($CustomField);
% 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 = 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
@@ -183,7 +183,7 @@ $MaxValues => 1
% }
% $_ = lc $_ foreach @Default;
% my $selected;
-% my $CFVs = $CustomField->Values;
+% my $CFVs = CachedCustomFieldValues($CustomField);
% 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..a5ba438174 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 = CachedCustomFieldValues($CustomField);
<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 = CachedCustomFieldValues($CustomField);
% while (my $value = $values->Next) {
% push @options, {
% value => $value->Name,
-----------------------------------------------------------------------
More information about the rt-commit
mailing list