Category : optimization

Hope you are doing good! I have a code that fetches posts from friends’ posts and also from mutual friends’ posts. The rule is:- 70% Results must be from direct friends posts 10% From mutual friends/ friends of friends posts function feedUpdate() { $friends = Auth::user()->profile->following; //Fetch friends posts $posts = Post::whereIn(‘profile_id’, $friends->pluck(‘following_id’)); //Fetch mutual ..

Read more

Writing comments for Laravel functions with phpdoc requires to add classes. For example /** * Add item to cart and redirect back * * @return Response */ Automatically adds "IlluminateHttpResponse" to the top of class. My question is: does it make it (at least a tiny bit) slower if I’m not using the class in ..

Read more

Here is my code: $clashes = $clashes->where(function (Builder $query) use ($times) { // Booking clashes with a booking which starts inside of it $query->orWhereBetween("start_timestamp", [$times["start_timestamp"], $times["end_timestamp"]]); // Booking clashes with a booking which stops inside it $query->orWhereBetween("end_timestamp", [$times["start_timestamp"], $times["end_timestamp"]]); // Booking clashes with a large booking and is entirely inside of it $query->orWhere(function (Builder $query) ..

Read more

We have a site (https://www.supercheapsigns.com) on Laravel and VueJS. We spent pretty much time on Pagespeed recommendation optimization and much improved the result (around 23-25 audits are usually passed) but the score is still unbelievably low (around 30 for Desktop and 1-4 for Mobile). Now we’re not sure what steps we should do to get ..

Read more

Laravel code: $posts = array(); $allPosts = DB::table(‘post_categories’) ->Join(‘posts’, ‘posts.id’, ‘=’, ‘post_categories.posts_id’) ->select(‘posts.title’,’posts.id’,’posts.body’,’posts.created_at’) ->where(‘post_categories.categories_id’,’!=’,5) ->orderBy(‘posts.created_at’,’desc’) ->get(); foreach ($allPosts as $post){ $categories = DB::table(‘post_categories’) ->Join(‘categories’, ‘categories.id’, ‘=’, ‘post_categories.categories_id’) ->select(‘categories.name’,’categories.id’) ->where(‘post_categories.posts_id’,’=’,$post->id) ->get(); $post->categories = $categories; array_push($posts,$post); } Model relations: Posts 1 – m post_categories m – 1 categories first query is used fetch posts without category number ..

Read more

I’m trying to optimize my query because it takes far, far too long to execute. My model consists of 6 tables, see ER diagram: ER Schema This is my Query builder: $events = Event::orderBy(‘date’,’DESC’)->with([‘person’, ‘person.country’, ‘person.topics’, ‘train’, ‘station’])->get(); I have also already indexed the different tables. Between topic and person there is a pivot table: ..

Read more

I’m having a bit of an issue with the old N+1 problem. I’m running Lighthouse 4.8, Laravel 5.8, and have batched_queries and batchload_relations set to true in my config. I have the hasMany and hasOne set in my schema (anonymised a little): type Team { id: Int! Y_resource_id: Int X_resource_id: Int name: String description: String ..

Read more