generated from spatie/package-skeleton-laravel
-
-
Notifications
You must be signed in to change notification settings - Fork 26
Support parameters #39
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
618c6e7
Add migration, support for parameters, add truncate command
svenbw dbb4fa6
Fix styling errors
svenbw b636591
Add parameters to README file
svenbw 4886958
Fix missing parameters entry in console stats command
svenbw bf93e20
Return phpdoc comment, use array casting, select columns by function
svenbw 8923ec6
Removed truncate command from PR
svenbw 7f8d608
Improve column remapping code for route:stats command
svenbw f78491b
Removed LaravelRouteTruncateCommand from the service provider
svenbw c1521ad
Add a protected function
bilfeldt 251f0fc
Skip json encoding
bilfeldt 6119ed8
Change config key
bilfeldt fb5eec0
StyleCI
bilfeldt b0cf353
Merge pull request #1 from bilfeldt/parameters
svenbw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
.php_cs | ||
.php_cs.cache | ||
.phpunit.result.cache | ||
.phpunit.cache | ||
build | ||
composer.lock | ||
coverage | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
database/migrations/add_parameters_to_route_statistics_table.php.stub
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class extends Migration | ||
{ | ||
public function up() | ||
{ | ||
Schema::table('route_statistics', function (Blueprint $table) { | ||
$table->json('parameters')->after('route')->nullable(); | ||
}); | ||
} | ||
|
||
public function down() | ||
{ | ||
Schema::table('route_statistics', function (Blueprint $table) { | ||
$table->dropColumn('parameters'); | ||
}); | ||
} | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace Bilfeldt\LaravelRouteStatistics\Commands; | ||
|
||
use Illuminate\Console\Command; | ||
use TypeError; | ||
|
||
class LaravelRouteTruncateCommand extends Command | ||
{ | ||
public $signature = 'route:truncate-stats'; | ||
|
||
public $description = 'Prune route usage statistics'; | ||
|
||
public function handle(): int | ||
{ | ||
try { | ||
call_user_func_array([config('route-statistics.model'), 'truncate'], []); | ||
svenbw marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} catch (TypeError $ex) { | ||
$this->components->error('Failed to truncate route usage statistics: '.$ex->getMessage()); | ||
} | ||
|
||
$this->components->info('Route usage statistics truncated'); | ||
|
||
return Command::SUCCESS; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get that this is in theory a small performance improvement, but it does break if you start adding fields that are not nessesarely DB fields but accessors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't include it for the performance it was rather that I used a selector that was not in the table. I have a local change that splits up successors (e.g. for grouping) and real column names. In this change I also did some checks if other options where valid. Since it was out of scope of this PR I didn't add it. I will revert this to the original code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is where you ment to post this @svenbw :)
Instead of only selecting the fields in the query, then I suggest that we just pluck those fields AFTER query execution (which will then include all fields). That way it would work with accessors as well + solve your issue with arrays?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forgetting the
parameters
key by looping over the collection works ifparameters
is not enabled. However if they are still there it still needs to be casted to a string for table.or
This is less efficient because php has to loop though each entry, else the data is collected by the database.
Can you explain why you would include other columns that are not in the fields? The table will be faulty because the headers of the table are generated by the
getFields()
function. If there is an additional column in the database the table will included empty headers and depending on the order even a field name above another column.And @bilfeldt thanks for keeping the discussion going, I think we are getting there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe something like:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pluck doesn't work, since it will only pluck items with specific keys from an array, and at that point there are still rows.
I filtered each row with
only
which will eliminate theparameters
column.I think the idea of
pluck
is the same as usingselect
, where select has the benefit of offloading the complexity to the database, and thus slightly more performant.