Skip to content

Commit

Permalink
Merge pull request #110 from beyondcode/updates
Browse files Browse the repository at this point in the history
2.0.0
  • Loading branch information
mechelon authored Oct 4, 2024
2 parents cdf0649 + b9dc996 commit 5e1d70b
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 97 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ composer.lock
vendor
coverage
.idea
nbproject
nbproject
.phpunit.result.cache
26 changes: 0 additions & 26 deletions .scrutinizer.yml

This file was deleted.

4 changes: 0 additions & 4 deletions .styleci.yml

This file was deleted.

60 changes: 0 additions & 60 deletions .travis.yml

This file was deleted.

2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# Laravel N+1 Query Detector

[![Latest Version on Packagist](https://img.shields.io/packagist/v/beyondcode/laravel-query-detector.svg?style=flat-square)](https://packagist.org/packages/beyondcode/laravel-query-detector)
[![Build Status](https://img.shields.io/travis/beyondcode/laravel-query-detector/master.svg?style=flat-square)](https://travis-ci.org/beyondcode/laravel-query-detector)
[![Quality Score](https://img.shields.io/scrutinizer/g/beyondcode/laravel-query-detector.svg?style=flat-square)](https://scrutinizer-ci.com/g/beyondcode/laravel-query-detector)
[![Total Downloads](https://img.shields.io/packagist/dt/beyondcode/laravel-query-detector.svg?style=flat-square)](https://packagist.org/packages/beyondcode/laravel-query-detector)

The Laravel N+1 query detector helps you to increase your application's performance by reducing the number of queries it executes. This package monitors your queries in real-time, while you develop your application and notify you when you should add eager loading (N+1 queries).
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
],
"require": {
"php": "^7.1 || ^8.0",
"illuminate/support": "^5.5 || ^6.0 || ^7.0 || ^8.0 || ^9.0|^10.0"
"illuminate/support": "^5.5 || ^6.0 || ^7.0 || ^8.0 || ^9.0|^10.0 || ^11.0"
},
"require-dev": {
"laravel/legacy-factories": "^1.0",
"orchestra/testbench": "^3.0 || ^4.0 || ^5.0 || ^6.0|^8.0",
"phpunit/phpunit": "^7.0 || ^8.0 || ^9.0"
"orchestra/testbench": "^3.0 || ^4.0 || ^5.0 || ^6.0|^8.0 || ^9.0",
"phpunit/phpunit": "^7.0 || ^8.0 || ^9.0 || ^10.5"
},
"autoload": {
"psr-4": {
Expand Down
5 changes: 5 additions & 0 deletions src/QueryDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,4 +233,9 @@ public function output($request, $response)

return $response;
}

public function emptyQueries()
{
$this->queries = Collection::make();
}
}
2 changes: 1 addition & 1 deletion src/QueryDetectorServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function boot()
if ($this->app->runningInConsole()) {
$this->publishes([
__DIR__.'/../config/config.php' => config_path('querydetector.php'),
], 'config');
], 'query-detector-config');
}

$this->registerMiddleware(QueryDetectorMiddleware::class);
Expand Down
23 changes: 23 additions & 0 deletions tests/QueryDetectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -336,4 +336,27 @@ public function it_uses_the_trace_line_to_detect_queries()
$this->assertSame(Author::class, $queries[0]['model']);
$this->assertSame('profile', $queries[0]['relation']);
}

/** @test */
public function it_empty_queries()
{
Route::get('/', function (){
$authors = Author::all();

foreach ($authors as $author) {
$author->profile;
}
});

$this->get('/');

$queryDetector = app(QueryDetector::class);

$queries = $queryDetector->getDetectedQueries();
$this->assertCount(1, $queries);

$queryDetector->emptyQueries();
$queries = $queryDetector->getDetectedQueries();
$this->assertCount(0, $queries);
}
}

0 comments on commit 5e1d70b

Please sign in to comment.