Forum

Thread tagged as: Runway

Related item fields indexing

Hello,

I'm working with a big Collection of properties (1000+ items) so I'm paying more attention to indexing and what might affect performance.

In my master (edit form) template I have a couple of related fields:

<perch:related id="agent" collection="Agents" label="Agent"></perch:related>
<perch:related id="community" collection="Communities" label="Community"></perch:related>

In all of these Collections (Properties, Agents and Communities) I'm only indexing the fields I need to filter/sort by for that particular Collection.

When it comes to related fields, I've noticed that Runway indexes the related item fields based on the item's master template.

So if the Agents Collection master template has fields with no-index set, these won't be indexed when relating an agent to a property (in the property edit form). Looking at the collection_index table all other agent fields seem to get indexed by default including _order and _date.

I have fields that I need to be indexed to filter through the Agents Collection, but I don't need to filter the Properties Collection by them - but they are indexed by default anyway. And I don't necessarily need to index a related item's _order value.

I have tried the following, but the field role still gets indexed:

<perch:related id="agent" collection="Agents" label="Agent" >
<perch:content id="role" type="text" no-index="true">
</perch:related>

Is there any way to control what related item fields get indexed at the moment? If not, will there be a way to do so in a future release?

I think it makes sense to be able to specify what related item fields get indexed. Perhaps with an attribute like this:

<perch:related id="agent" collection="Agents" label="Agent" index="slug,agentID"></perch:related>
Hussein Al Hammad

Hussein Al Hammad 105 points

  • 3 years ago

I have also been in this situation, and definitely would've used this functionality if it was available. So just wanted to give my "vote" to it as a feature request if not available.

Drew McLellan

Drew McLellan 2638 points
Perch Support

1000 items shouldn't require special treatment - I wouldn't consider it a big collection - but yes, it's always wise to only index what you need to.

Do you need to index the related items at all? Do you filter or sort by them?

Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

1000 items shouldn't require special treatment - I wouldn't consider it a big collection

I've been experiencing some slow DB queries with this one, so I thought it might be particularly because I have not experienced the same with smaller Collections.

Do you need to index the related items at all? Do you filter or sort by them?

I need to filter by some related items, but I'd only need a single field per related item really.

So something like this is all I'd need when it comes to the Properties collection:

perch_collection('Properties', [
'filter' => 'agent.slug',
'value' => 'some-agent'
]);

But I have other fields I need to use to filter the Agents collection by. So I'm indexing them per agent (I need to), but they also get indexed per property when I relate an agent to it even though they are not needed.

So if I can only index one related item field, the collection_index table will have a few thousands fewer rows which I thought might improve the performance. Would it?

Drew McLellan

Drew McLellan 2638 points
Perch Support

The smaller the table the more chance the index can be held in cache between queries, so yes, the fewer rows the better generally.

I'll have a look and see if there's a practical way to limit the related item index at the point of indexing. I don't know if that's going to be simple, but I'll take a look.

Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

Thanks, Drew.