Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.0.0 #110

Merged
merged 8 commits into from
Oct 4, 2024
Merged

2.0.0 #110

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}