In my project I have 2 API endpoints, one using slug (web) and other one db ids (mobile). I'm using Slugeable package. I have a Post model, User model and Comment model. I don't want to use slugs for mobile because of network performances that are really importants in my app (regular poor network).
I have a transformer for comments, returning 2 fields : "content", "post_id" (could be a slug or an id, depends of the endpoint).
I want to list all comments of a user. But when I respond to the web endpoint I have to make a lot of SQL resquests:
$user->comments; // To have all comments
// and for each comment
Comment::find($comment->id); // To get the slug to return
Using homestead, SQL response for 300 comments take about 3-4s with slugs and 600ms without. Indexes are set. How could I improve performances in that case ?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire