[rt-devel] help solving ObjectCustomFieldValue performance problem (maybe impact RT 4.4 upgrade)

Christian Loos cloos at netcologne.de
Wed Jan 27 08:32:00 EST 2016


Hi,

we have a external CF (type Select) where we don't want that users can
add the same value to different tickets.

I implemented this by building a list of the used values:

my %used_values;
my $ocfvs = RT::ObjectCustomFieldValues->new(RT->SystemUser);
$ocfvs->LimitToCustomField(1);
while (my $ocfv = $ocfvs->Next) {
    $used_values{ $ocfv->Content } = 1;
}

After this I noticed much slower page loadtimes for the ticket create
and modify pages.
Investigating this with the, by the way wonderful and very helpful, "SQL
Queries" tool, it shows that for every create/modify page load RT runs
900 queries against the Tickets table.
The 900 comes from 900 tickets which have a CF.1 value (select
count(distinct ObjectId) from ObjectCustomFieldValues where CustomField
= 1 and Disabled = 0;)
Investigating further shows that Content [1] calls CustomFieldObj [2]
which SetContextObject based on Object [3] which loads, in my case, the
ticket.

I was really surprised to see queries against the Tickets table because
I used the RT::ObjectCustomFieldValues to fetch the values directly,
without going the other way around starting from tickets.

Actually removing SetContextObject from the CustomFieldObj method avoids
the queries against the Tickets table. This was introduced by [4], but
the commit message says nothing about the reason for this. I assume this
was necessary for the right check in Content [5] to also account for
ticket or queue role level rights.

If you look at the Content method [1], there are also multiple calls for
"$self->CustomFieldObj->Type" to fetch the CF type. This also involves
loading the object, which isn't necessary, as CF can't have a different
type depending on the object they are applied to.

I hope to get some feedback from the RT developers regarding this.

I think this could also have an impact on the RT 4.4 upgrade, because
the 4.3.6 upgrade step [6] calls RT::ObjectCustomFieldValues->Content
which maybe slow down the upgrade if you have many CF values with Category.

Chris

[1]
https://github.com/bestpractical/rt/blob/stable/lib/RT/ObjectCustomFieldValue.pm#L221
[2]
https://github.com/bestpractical/rt/blob/stable/lib/RT/ObjectCustomFieldValue.pm#L202
[3]
https://github.com/bestpractical/rt/blob/stable/lib/RT/ObjectCustomFieldValue.pm#L274
[4]
https://github.com/bestpractical/rt/commit/d0d1530b8229d3d01b40f82af1c95ec263dec3f2
[5]
https://github.com/bestpractical/rt/blob/stable/lib/RT/ObjectCustomFieldValue.pm#L224
[6]
https://github.com/bestpractical/rt/blob/master/etc/upgrade/4.3.6/content


More information about the rt-devel mailing list