Skip to content

Commit b978359

Browse files
authored
prepare 3.4.1 release (launchdarkly#110)
1 parent b475838 commit b978359

File tree

4 files changed

+62
-3
lines changed

4 files changed

+62
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
All notable changes to the LaunchDarkly PHP SDK will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org).
44

5+
## [3.4.1] - 2018-09-25
6+
### Fixed:
7+
- Improved the performance of `allFlags`/`allFlagsState` by not making redundant individual requests for prerequisite flags, when a flag is being evaluated that has prerequisites. Instead it will reuse the same flag data that it already obtained from LaunchDarkly in the "get all the flags" request.
8+
59
## [3.4.0] - 2018-09-04
610
### Added:
711
- The new `LDClient` method `variationDetail` allows you to evaluate a feature flag (using the same parameters as you would for `variation`) and receive more information about how the value was calculated. This information is returned in an object that contains both the result value and a "reason" object which will tell you, for instance, if the user was individually targeted for the flag or was matched by one of the flag's rules, or if the flag returned the default value due to an error.

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.4.0
1+
3.4.1

src/LaunchDarkly/LDClient.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class LDClient
1212
{
1313
const DEFAULT_BASE_URI = 'https://app.launchdarkly.com';
1414
const DEFAULT_EVENTS_URI = 'https://events.launchdarkly.com';
15-
const VERSION = '3.4.0';
15+
const VERSION = '3.4.1';
1616

1717
/** @var string */
1818
protected $_sdkKey;
@@ -350,14 +350,17 @@ public function allFlagsState($user, $options = array())
350350
return new FeatureFlagsState(false);
351351
}
352352

353+
$preloadedRequester = new PreloadedFeatureRequester($this->_featureRequester, $flags);
354+
// This saves us from doing repeated queries for prerequisite flags during evaluation
355+
353356
$state = new FeatureFlagsState(true);
354357
$clientOnly = isset($options['clientSideOnly']) && $options['clientSideOnly'];
355358
$withReasons = isset($options['withReasons']) && $options['withReasons'];
356359
foreach ($flags as $key => $flag) {
357360
if ($clientOnly && !$flag->isClientSide()) {
358361
continue;
359362
}
360-
$result = $flag->evaluate($user, $this->_featureRequester);
363+
$result = $flag->evaluate($user, $preloadedRequester);
361364
$state->addFlag($flag, $result->getDetail(), $withReasons);
362365
}
363366
return $state;
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
namespace LaunchDarkly;
3+
4+
class PreloadedFeatureRequester implements FeatureRequester
5+
{
6+
/** @var FeatureRequester */
7+
private $_baseRequester;
8+
9+
/** @var array */
10+
private $_knownFeatures;
11+
12+
public function __construct($baseRequester, $knownFeatures)
13+
{
14+
$this->_baseRequester = $baseRequester;
15+
$this->_knownFeatures = $knownFeatures;
16+
}
17+
18+
/**
19+
* Gets feature data from cached values
20+
*
21+
* @param $key string feature key
22+
* @return FeatureFlag|null The decoded FeatureFlag, or null if missing
23+
*/
24+
public function getFeature($key)
25+
{
26+
if (isset($this->_knownFeatures[$key])) {
27+
return $this->_knownFeatures[$key];
28+
}
29+
return null;
30+
}
31+
32+
/**
33+
* Gets segment data from the regular feature requester
34+
*
35+
* @param $key string segment key
36+
* @return Segment|null The decoded Segment, or null if missing
37+
*/
38+
public function getSegment($key)
39+
{
40+
return $this->_baseRequester->getSegment($key);
41+
}
42+
43+
/**
44+
* Gets all features from cached values
45+
*
46+
* @return array()|null The decoded FeatureFlags, or null if missing
47+
*/
48+
public function getAllFeatures()
49+
{
50+
return $this->_knownFeatures;
51+
}
52+
}

0 commit comments

Comments
 (0)