-
Notifications
You must be signed in to change notification settings - Fork 58
Improve performance of setting multiple feature values at once #157
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| <?php | ||
|
|
||
| namespace Laravel\Pennant\Contracts; | ||
|
|
||
| interface CanSetManyFeaturesForScopes | ||
| { | ||
| /** | ||
| * Set multiple feature flag values. | ||
| * | ||
| * @param list<array{ feature: string, scope: mixed, value: mixed }> $features | ||
| */ | ||
| public function setAll(array $features): void; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -249,9 +249,12 @@ public function unless($feature, $whenInactive, $whenActive = null) | |
| */ | ||
| public function activate($feature, $value = true) | ||
| { | ||
| Collection::wrap($feature) | ||
| $features = Collection::wrap($feature) | ||
| ->crossJoin($this->scope()) | ||
| ->each(fn ($bits) => $this->driver->set($bits[0], $bits[1], $value)); | ||
| ->map(fn ($bits) => ['feature' => $bits[0], 'scope' => $bits[1], 'value' => $value]) | ||
| ->all(); | ||
|
|
||
| $this->driver->setAll($features); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
|
|
||
| /** | ||
|
|
@@ -262,9 +265,12 @@ public function activate($feature, $value = true) | |
| */ | ||
| public function deactivate($feature) | ||
| { | ||
| Collection::wrap($feature) | ||
| $features = Collection::wrap($feature) | ||
| ->crossJoin($this->scope()) | ||
| ->each(fn ($bits) => $this->driver->set($bits[0], $bits[1], false)); | ||
| ->map(fn ($bits) => ['feature' => $bits[0], 'scope' => $bits[1], 'value' => false]) | ||
| ->all(); | ||
|
|
||
| $this->driver->setAll($features); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
|
|
||
| /** | ||
|
|
||
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.
Marked as internal so it doesn't show up on the Facade. This isn't meant to be called directly by the consuming application.