Skip to content
Commits on Source (2)
...@@ -70,7 +70,8 @@ class Manager ...@@ -70,7 +70,8 @@ class Manager
if ($opts['useElastic']) { if ($opts['useElastic']) {
$response = $this->elasticRepository->getList($opts); $response = $this->elasticRepository->getList($opts);
if ($this->optStateIsUsedAndValid($opts)) { // TODO: Check if it is *really* necessary to re fetch the boosts from cassandra ??
if ($this->optStateIsUsedAndValid($opts) && $opts['state'] !== self::OPT_STATEQUERY_APPROVED) {
$opts['guids'] = array_map(function ($boost) { $opts['guids'] = array_map(function ($boost) {
return $boost->getGuid(); return $boost->getGuid();
}, $response->toArray()); }, $response->toArray());
...@@ -114,7 +115,7 @@ class Manager ...@@ -114,7 +115,7 @@ class Manager
protected function optStateIsValid(array $opts): bool protected function optStateIsValid(array $opts): bool
{ {
return in_array($opts['state'], self::VALID_OPT_STATEQUERY); return in_array($opts['state'], self::VALID_OPT_STATEQUERY, true);
} }
/** /**
......
...@@ -19,7 +19,7 @@ use Minds\Core\Di\Di; ...@@ -19,7 +19,7 @@ use Minds\Core\Di\Di;
class ManagerSpec extends ObjectBehavior class ManagerSpec extends ObjectBehavior
{ {
/** @var CassandraRepository */ /** @var CassandraRepository */
private $repository; private $cassandraRepository;
/** @var ElasticRepository */ /** @var ElasticRepository */
private $elasticRepository; private $elasticRepository;
/** @var EntitiesBuilder */ /** @var EntitiesBuilder */
...@@ -28,13 +28,13 @@ class ManagerSpec extends ObjectBehavior ...@@ -28,13 +28,13 @@ class ManagerSpec extends ObjectBehavior
private $guidBuilder; private $guidBuilder;
public function let( public function let(
CassandraRepository $repository, CassandraRepository $cassandraRepository,
ElasticRepository $elasticRepository, ElasticRepository $elasticRepository,
EntitiesBuilder $entitiesBuilder, EntitiesBuilder $entitiesBuilder,
GuidBuilder $guidBuilder GuidBuilder $guidBuilder
) { ) {
$this->beConstructedWith($repository, $elasticRepository, $entitiesBuilder, $guidBuilder); $this->beConstructedWith($cassandraRepository, $elasticRepository, $entitiesBuilder, $guidBuilder);
$this->repository = $repository; $this->cassandraRepository = $cassandraRepository;
$this->elasticRepository = $elasticRepository; $this->elasticRepository = $elasticRepository;
$this->entitiesBuilder = $entitiesBuilder; $this->entitiesBuilder = $entitiesBuilder;
$this->guidBuilder = $guidBuilder; $this->guidBuilder = $guidBuilder;
...@@ -47,7 +47,7 @@ class ManagerSpec extends ObjectBehavior ...@@ -47,7 +47,7 @@ class ManagerSpec extends ObjectBehavior
public function it_should_return_a_list_of_boosts_to_review() public function it_should_return_a_list_of_boosts_to_review()
{ {
$response = new Response([ $responseObj = new Response([
(new Boost) (new Boost)
->setGuid(1) ->setGuid(1)
->setEntityGuid(123) ->setEntityGuid(123)
...@@ -61,19 +61,19 @@ class ManagerSpec extends ObjectBehavior ...@@ -61,19 +61,19 @@ class ManagerSpec extends ObjectBehavior
]); ]);
$this->elasticRepository->getList([ $this->elasticRepository->getList([
'state' => 'review', 'state' => Manager::OPT_STATEQUERY_REVIEW,
'useElastic' => true, 'useElastic' => true,
]) ])
->shouldBeCalled() ->shouldBeCalled()
->willReturn($response); ->willReturn($responseObj);
$this->repository->getList([ $this->cassandraRepository->getList([
'state' => 'review', 'state' => Manager::OPT_STATEQUERY_REVIEW,
'useElastic' => true, 'useElastic' => true,
'guids' => [1, 2], 'guids' => [1, 2],
]) ])
->shouldBeCalled() ->shouldBeCalled()
->willReturn($response); ->willReturn($responseObj);
$this->entitiesBuilder->single(123)->shouldBeCalled()->willReturn((new Activity)->set('guid', 123)); $this->entitiesBuilder->single(123)->shouldBeCalled()->willReturn((new Activity)->set('guid', 123));
$this->entitiesBuilder->single(1)->shouldBeCalled()->willReturn((new User)->set('guid', 1)); $this->entitiesBuilder->single(1)->shouldBeCalled()->willReturn((new User)->set('guid', 1));
...@@ -81,7 +81,7 @@ class ManagerSpec extends ObjectBehavior ...@@ -81,7 +81,7 @@ class ManagerSpec extends ObjectBehavior
$this->entitiesBuilder->single(2)->shouldBeCalled()->willReturn((new User)->set('guid', 2)); $this->entitiesBuilder->single(2)->shouldBeCalled()->willReturn((new User)->set('guid', 2));
$response = $this->getList([ $response = $this->getList([
'state' => 'review', 'state' => Manager::OPT_STATEQUERY_REVIEW,
]); ]);
$response[0]->getEntity()->getGuid()->shouldBe(123); $response[0]->getEntity()->getGuid()->shouldBe(123);
...@@ -95,7 +95,7 @@ class ManagerSpec extends ObjectBehavior ...@@ -95,7 +95,7 @@ class ManagerSpec extends ObjectBehavior
public function it_should_return_a_list_of_boosts_to_deliver() public function it_should_return_a_list_of_boosts_to_deliver()
{ {
$response = new Response([ $responseObj = new Response([
(new Boost) (new Boost)
->setEntityGuid(123) ->setEntityGuid(123)
->setImpressions(1000) ->setImpressions(1000)
...@@ -105,12 +105,11 @@ class ManagerSpec extends ObjectBehavior ...@@ -105,12 +105,11 @@ class ManagerSpec extends ObjectBehavior
->setImpressions(100) ->setImpressions(100)
->setOwnerGuid(2) ->setOwnerGuid(2)
]); ]);
$this->elasticRepository->getList([ $this->elasticRepository->getList([
'state' => 'approved', 'state' => Manager::OPT_STATEQUERY_APPROVED,
'useElastic' => true, 'useElastic' => true,
]) ])->shouldBeCalled()->willReturn($responseObj);
->shouldBeCalled()
->willReturn($response);
$this->entitiesBuilder->single(123)->shouldBeCalled()->willReturn((new Activity)->set('guid', 123)); $this->entitiesBuilder->single(123)->shouldBeCalled()->willReturn((new Activity)->set('guid', 123));
$this->entitiesBuilder->single(1)->shouldBeCalled()->willReturn((new User)->set('guid', 1)); $this->entitiesBuilder->single(1)->shouldBeCalled()->willReturn((new User)->set('guid', 1));
...@@ -118,7 +117,7 @@ class ManagerSpec extends ObjectBehavior ...@@ -118,7 +117,7 @@ class ManagerSpec extends ObjectBehavior
$this->entitiesBuilder->single(2)->shouldBeCalled()->willReturn((new User)->set('guid', 2)); $this->entitiesBuilder->single(2)->shouldBeCalled()->willReturn((new User)->set('guid', 2));
$response = $this->getList([ $response = $this->getList([
'state' => 'approved', 'state' => Manager::OPT_STATEQUERY_APPROVED,
'useElastic' => true, 'useElastic' => true,
]); ]);
...@@ -144,7 +143,7 @@ class ManagerSpec extends ObjectBehavior ...@@ -144,7 +143,7 @@ class ManagerSpec extends ObjectBehavior
->setOwnerGuid(2) ->setOwnerGuid(2)
]); ]);
$this->repository->getList([ $this->cassandraRepository->getList([
'state' => null, 'state' => null,
'guids' => [123, 456], 'guids' => [123, 456],
'useElastic' => false, 'useElastic' => false,
...@@ -177,7 +176,7 @@ class ManagerSpec extends ObjectBehavior ...@@ -177,7 +176,7 @@ class ManagerSpec extends ObjectBehavior
$boost->getGuid()->shouldbeCalled()->willReturn(null); $boost->getGuid()->shouldbeCalled()->willReturn(null);
$boost->setGuid(1)->shouldBeCalled(); $boost->setGuid(1)->shouldBeCalled();
$this->repository->add($boost)->shouldBeCalled(); $this->cassandraRepository->add($boost)->shouldBeCalled();
$this->elasticRepository->add($boost)->shouldBeCalled(); $this->elasticRepository->add($boost)->shouldBeCalled();
$this->add($boost)->shouldReturn(true); $this->add($boost)->shouldReturn(true);
...@@ -185,7 +184,7 @@ class ManagerSpec extends ObjectBehavior ...@@ -185,7 +184,7 @@ class ManagerSpec extends ObjectBehavior
public function it_should_update_a_boost(Boost $boost) public function it_should_update_a_boost(Boost $boost)
{ {
$this->repository->update($boost, ['@timestamp'])->shouldBeCalled(); $this->cassandraRepository->update($boost, ['@timestamp'])->shouldBeCalled();
$this->elasticRepository->update($boost, ['@timestamp'])->shouldBeCalled(); $this->elasticRepository->update($boost, ['@timestamp'])->shouldBeCalled();
$this->update($boost, ['@timestamp']); $this->update($boost, ['@timestamp']);
...@@ -210,7 +209,7 @@ class ManagerSpec extends ObjectBehavior ...@@ -210,7 +209,7 @@ class ManagerSpec extends ObjectBehavior
$this->elasticRepository->getList($params)->shouldBeCalled()->willReturn($response); $this->elasticRepository->getList($params)->shouldBeCalled()->willReturn($response);
$response->toArray()->shouldbeCalled()->willReturn([$boost]); $response->toArray()->shouldbeCalled()->willReturn([$boost]);
$this->repository->getList(Argument::any())->shouldBeCalled()->willReturn($response); $this->cassandraRepository->getList(Argument::any())->shouldBeCalled()->willReturn($response);
$boost->getGuid()->shouldBeCalled()->willReturn('9012'); $boost->getGuid()->shouldBeCalled()->willReturn('9012');
$boost->getType()->shouldBeCalled()->willReturn('newsfeed'); $boost->getType()->shouldBeCalled()->willReturn('newsfeed');
...@@ -250,7 +249,7 @@ class ManagerSpec extends ObjectBehavior ...@@ -250,7 +249,7 @@ class ManagerSpec extends ObjectBehavior
]; ];
$this->elasticRepository->getList($params)->shouldBeCalled()->willReturn($response); $this->elasticRepository->getList($params)->shouldBeCalled()->willReturn($response);
$response->toArray()->shouldbeCalled()->willReturn([$boost]); $response->toArray()->shouldbeCalled()->willReturn([$boost]);
$this->repository->getList(Argument::any())->shouldBeCalled()->willReturn($response); $this->cassandraRepository->getList(Argument::any())->shouldBeCalled()->willReturn($response);
$boost->getGuid()->shouldBeCalled()->willReturn('9012'); $boost->getGuid()->shouldBeCalled()->willReturn('9012');
$boost->getEntityGuid()->shouldBeCalled()->willReturn('1234'); $boost->getEntityGuid()->shouldBeCalled()->willReturn('1234');
...@@ -350,7 +349,7 @@ class ManagerSpec extends ObjectBehavior ...@@ -350,7 +349,7 @@ class ManagerSpec extends ObjectBehavior
->shouldBeCalled() ->shouldBeCalled()
->willReturn(new Response($existingBoosts, '')); ->willReturn(new Response($existingBoosts, ''));
$this->repository->getList(Argument::any()) $this->cassandraRepository->getList(Argument::any())
->shouldBeCalled() ->shouldBeCalled()
->willReturn(new Response($existingBoosts)); ->willReturn(new Response($existingBoosts));
......