Skip to content

Commit 2777120

Browse files
authored
Fix related users saving (#29)
1 parent a0059c9 commit 2777120

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

src/DB/Managers/ParallelRunningStateManager.php

+8-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
class ParallelRunningStateManager
1212
{
13+
private const EXPIRES = 3600 * 24 * 180;
14+
1315
private ParallelRunningStateCachedRepository $parallelRunningStateCachedRepository;
1416
private KvStorageConfigAccessor $kvStorageConfigAccessor;
1517

@@ -25,7 +27,8 @@ public function setReadyToServe()
2527
{
2628
$this->kvStorageConfigAccessor->getKvStorage()->put(
2729
ParallelRunningDictionary::IS_RUNNING_KEY,
28-
ParallelRunningDictionary::IS_RUNNING_VALUE_TRUE
30+
ParallelRunningDictionary::IS_RUNNING_VALUE_TRUE,
31+
self::EXPIRES
2932
);
3033
$this->parallelRunningStateCachedRepository->clearCacheServing();
3134
}
@@ -34,7 +37,8 @@ public function setStopServing()
3437
{
3538
$this->kvStorageConfigAccessor->getKvStorage()->put(
3639
ParallelRunningDictionary::IS_RUNNING_KEY,
37-
ParallelRunningDictionary::IS_RUNNING_VALUE_STOPPED
40+
ParallelRunningDictionary::IS_RUNNING_VALUE_STOPPED,
41+
self::EXPIRES
3842
);
3943
$this->parallelRunningStateCachedRepository->clearCacheServing();
4044
}
@@ -43,7 +47,8 @@ public function setInitialized()
4347
{
4448
$this->kvStorageConfigAccessor->getKvStorage()->put(
4549
ParallelRunningDictionary::IS_INITIAZLIED_KEY,
46-
ParallelRunningDictionary::IS_INITIAZLIED_TRUE_VALUE
50+
ParallelRunningDictionary::IS_INITIAZLIED_TRUE_VALUE,
51+
self::EXPIRES
4752
);
4853
$this->parallelRunningStateCachedRepository->clearCacheInitialized();
4954
}

src/DB/Managers/RelatedUsersCacheManager.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
class RelatedUsersCacheManager
1212
{
13+
private const EXPIRES = 3600 * 24 * 180;
14+
1315
private KvStorageConfigAccessor $kvStorage;
1416

1517
public function __construct(
@@ -23,6 +25,10 @@ public function store(array $relatedUsers): void
2325
$this
2426
->kvStorage
2527
->getKvStorage()
26-
->put(ParallelRunningDictionary::RELATED_USERS_KEY, json_encode($relatedUsers));
28+
->put(
29+
ParallelRunningDictionary::RELATED_USERS_KEY,
30+
json_encode($relatedUsers),
31+
self::EXPIRES
32+
);
2733
}
2834
}

src/Events/Handlers/RelatedUsersStatisticsInterceptor.php

+9-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Abrouter\Client\Contracts\TaskContract;
88
use Abrouter\Client\DB\Managers\RelatedUsersCacheManager;
99
use Abrouter\Client\DB\RelatedUsersStore;
10+
use Abrouter\Client\DB\Repositories\RelatedUsersCacheRepository;
1011
use Abrouter\Client\Events\HandlerInterface;
1112
use Abrouter\Client\Services\ExperimentsParallelRun\ParallelRunSwitch;
1213
use Abrouter\Client\Services\Statistics\SendEventTask;
@@ -19,14 +20,18 @@ class RelatedUsersStatisticsInterceptor implements HandlerInterface
1920

2021
private RelatedUsersCacheManager $relatedUsersCacheManager;
2122

23+
private RelatedUsersCacheRepository $relatedUsersCacheRepository;
24+
2225
public function __construct(
2326
ParallelRunSwitch $parallelRunSwitch,
2427
RelatedUsersStore $relatedUsersStore,
25-
RelatedUsersCacheManager $relatedUsersCacheManager
28+
RelatedUsersCacheManager $relatedUsersCacheManager,
29+
RelatedUsersCacheRepository $relatedUsersCacheRepository
2630
) {
2731
$this->parallelRunSwitch = $parallelRunSwitch;
2832
$this->relatedUsersStore = $relatedUsersStore;
2933
$this->relatedUsersCacheManager = $relatedUsersCacheManager;
34+
$this->relatedUsersCacheRepository = $relatedUsersCacheRepository;
3035
}
3136

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

50+
$this->relatedUsersStore::load($this->relatedUsersCacheRepository->getAll());
51+
4552
$this->relatedUsersStore->get()->append($userId, $temporaryUserId);
53+
4654
$this->relatedUsersCacheManager->store(
4755
$this->relatedUsersStore->get()->getAll()
4856
);
4957

50-
5158
return true;
5259
}
5360
}

0 commit comments

Comments
 (0)