Skip to content

Commit

Permalink
Fix related users saving (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
yatsenkolesh authored Aug 10, 2022
1 parent a0059c9 commit 2777120
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
11 changes: 8 additions & 3 deletions src/DB/Managers/ParallelRunningStateManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

class ParallelRunningStateManager
{
private const EXPIRES = 3600 * 24 * 180;

private ParallelRunningStateCachedRepository $parallelRunningStateCachedRepository;
private KvStorageConfigAccessor $kvStorageConfigAccessor;

Expand All @@ -25,7 +27,8 @@ public function setReadyToServe()
{
$this->kvStorageConfigAccessor->getKvStorage()->put(
ParallelRunningDictionary::IS_RUNNING_KEY,
ParallelRunningDictionary::IS_RUNNING_VALUE_TRUE
ParallelRunningDictionary::IS_RUNNING_VALUE_TRUE,
self::EXPIRES
);
$this->parallelRunningStateCachedRepository->clearCacheServing();
}
Expand All @@ -34,7 +37,8 @@ public function setStopServing()
{
$this->kvStorageConfigAccessor->getKvStorage()->put(
ParallelRunningDictionary::IS_RUNNING_KEY,
ParallelRunningDictionary::IS_RUNNING_VALUE_STOPPED
ParallelRunningDictionary::IS_RUNNING_VALUE_STOPPED,
self::EXPIRES
);
$this->parallelRunningStateCachedRepository->clearCacheServing();
}
Expand All @@ -43,7 +47,8 @@ public function setInitialized()
{
$this->kvStorageConfigAccessor->getKvStorage()->put(
ParallelRunningDictionary::IS_INITIAZLIED_KEY,
ParallelRunningDictionary::IS_INITIAZLIED_TRUE_VALUE
ParallelRunningDictionary::IS_INITIAZLIED_TRUE_VALUE,
self::EXPIRES
);
$this->parallelRunningStateCachedRepository->clearCacheInitialized();
}
Expand Down
8 changes: 7 additions & 1 deletion src/DB/Managers/RelatedUsersCacheManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

class RelatedUsersCacheManager
{
private const EXPIRES = 3600 * 24 * 180;

private KvStorageConfigAccessor $kvStorage;

public function __construct(
Expand All @@ -23,6 +25,10 @@ public function store(array $relatedUsers): void
$this
->kvStorage
->getKvStorage()
->put(ParallelRunningDictionary::RELATED_USERS_KEY, json_encode($relatedUsers));
->put(
ParallelRunningDictionary::RELATED_USERS_KEY,
json_encode($relatedUsers),
self::EXPIRES
);
}
}
11 changes: 9 additions & 2 deletions src/Events/Handlers/RelatedUsersStatisticsInterceptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Abrouter\Client\Contracts\TaskContract;
use Abrouter\Client\DB\Managers\RelatedUsersCacheManager;
use Abrouter\Client\DB\RelatedUsersStore;
use Abrouter\Client\DB\Repositories\RelatedUsersCacheRepository;
use Abrouter\Client\Events\HandlerInterface;
use Abrouter\Client\Services\ExperimentsParallelRun\ParallelRunSwitch;
use Abrouter\Client\Services\Statistics\SendEventTask;
Expand All @@ -19,14 +20,18 @@ class RelatedUsersStatisticsInterceptor implements HandlerInterface

private RelatedUsersCacheManager $relatedUsersCacheManager;

private RelatedUsersCacheRepository $relatedUsersCacheRepository;

public function __construct(
ParallelRunSwitch $parallelRunSwitch,
RelatedUsersStore $relatedUsersStore,
RelatedUsersCacheManager $relatedUsersCacheManager
RelatedUsersCacheManager $relatedUsersCacheManager,
RelatedUsersCacheRepository $relatedUsersCacheRepository
) {
$this->parallelRunSwitch = $parallelRunSwitch;
$this->relatedUsersStore = $relatedUsersStore;
$this->relatedUsersCacheManager = $relatedUsersCacheManager;
$this->relatedUsersCacheRepository = $relatedUsersCacheRepository;
}

public function handle(TaskContract $taskContract): bool
Expand All @@ -42,12 +47,14 @@ public function handle(TaskContract $taskContract): bool
$userId = $taskContract->getEventDTO()->getBaseEventDTO()->getUserId();
$temporaryUserId = $taskContract->getEventDTO()->getBaseEventDTO()->getTemporaryUserId();

$this->relatedUsersStore::load($this->relatedUsersCacheRepository->getAll());

$this->relatedUsersStore->get()->append($userId, $temporaryUserId);

$this->relatedUsersCacheManager->store(
$this->relatedUsersStore->get()->getAll()
);


return true;
}
}

0 comments on commit 2777120

Please sign in to comment.