MorphToSelect is too slow

MorphToSelect for reading from large database is too slow. Is there any better alternative or any approach i can apply for chunking here. I have Member model which has MorphOne relationship with Company and User models. I need to select member in lets say LeadResource. Below is the code:-
Group::make()
->relationship('member')
->schema([
MorphToSelect::make('memberable')
->types([
MorphToSelect\Type::make(User::class)
->titleAttribute('name'),
MorphToSelect\Type::make(Company::class)
->titleAttribute('name')
])
->label('Member')
->required()
->searchable()
->preload()
->optionsLimit(5),
]),
Group::make()
->relationship('member')
->schema([
MorphToSelect::make('memberable')
->types([
MorphToSelect\Type::make(User::class)
->titleAttribute('name'),
MorphToSelect\Type::make(Company::class)
->titleAttribute('name')
])
->label('Member')
->required()
->searchable()
->preload()
->optionsLimit(5),
]),
3 Replies
toeknee
toeknee3mo ago
Have you got indexes setup?
Pritbor
PritborOP3mo ago
yes i have name field set as index in both Company and User model. I realised using Preload() is the problem. I removed and I see significant jump. But still i was wondering if i am using preload() with ->optionsLimit(5), then there should not be an issue but i see my page just hangs when i try typing .
toeknee
toeknee3mo ago
No there shouldn't really, use telescope and inspect the slow downs etc
Want results from more Discord servers?
Add your server