vendredi 17 avril 2020

Extremely slow filtering by ID collection

I have a simple Message model. When I do Message::get() it works okay.

There is a total of ~800 records in the database.

When I do

Message::whereIn('id', $messageIds)->get();

This takes ~6 seconds to run. $messageIds is an array, consisting of around 60-70 IDs.

I've tried:

  • Using scopes.
  • Fetching all() and then filter() on the Collection.
  • Using a whereRaw with the ID,
  • Using a whereRaw on the whole thing while selecting the IDs from there

Every time it tries to filter by ID, either the DB or the Collection it takes more than 6 seconds. What could slow this down so much? And what could I provide to make answering easier?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire