Skip to content

Commit

Permalink
Revert "feat: add debounce"
Browse files Browse the repository at this point in the history
This reverts commit 42622fa.
  • Loading branch information
fox-john committed Nov 29, 2023
1 parent 42622fa commit 2b452bc
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 99 deletions.
16 changes: 5 additions & 11 deletions ps_eventbus.php
Original file line number Diff line number Diff line change
Expand Up @@ -1339,17 +1339,11 @@ private function sendLiveSync($shopContents, $shopContentId, $action)
if ((int) $shopContentId === 0) {
return;
}

/** @var \PrestaShop\Module\PsEventbus\Service\SynchronizationService $synchronizationService */
$synchronizationService = $this->getService(PrestaShop\Module\PsEventbus\Service\SynchronizationService::class);

if ($synchronizationService->debounceLiveSync($shopContents)) {
try {
/** @var \PrestaShop\Module\PsEventbus\Api\LiveSyncApiClient $liveSyncApiClient */
$liveSyncApiClient = $this->getService(\PrestaShop\Module\PsEventbus\Api\LiveSyncApiClient::class);
$liveSyncApiClient->liveSync($shopContents, (int) $shopContentId, $action);
} catch (\Exception $e) {
}
try {
/** @var \PrestaShop\Module\PsEventbus\Api\LiveSyncApiClient $liveSyncApiClient */
$liveSyncApiClient = $this->getService(\PrestaShop\Module\PsEventbus\Api\LiveSyncApiClient::class);
$liveSyncApiClient->liveSync($shopContents, (int) $shopContentId, $action);
} catch (\Exception $e) {
}
}

Expand Down
6 changes: 0 additions & 6 deletions sql/install.sql
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,3 @@ CREATE TABLE IF NOT EXISTS `PREFIX_eventbus_incremental_sync`
PRIMARY KEY (`type`, `id_object`, `id_shop`, `lang_iso`)
) ENGINE = ENGINE_TYPE
DEFAULT CHARSET = utf8;

CREATE TABLE IF NOT EXISTS `PREFIX_eventbus_live_sync`
(
`shop_content` VARCHAR(50) NOT NULL,
`last_change_at` DATETIME NOT NULL,
)
1 change: 0 additions & 1 deletion sql/uninstall.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ DROP TABLE IF EXISTS `PREFIX_eventbus_type_sync`;
DROP TABLE IF EXISTS `PREFIX_eventbus_job`;
DROP TABLE IF EXISTS `PREFIX_eventbus_deleted_objects`;
DROP TABLE IF EXISTS `PREFIX_eventbus_incremental_sync`;
DROP TABLE IF EXISTS `PREFIX_eventbus_live_sync`;
56 changes: 0 additions & 56 deletions src/Repository/LiveSyncRepository.php

This file was deleted.

25 changes: 0 additions & 25 deletions src/Service/SynchronizationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use PrestaShop\Module\PsEventbus\Provider\PaginatedApiDataProviderInterface;
use PrestaShop\Module\PsEventbus\Repository\EventbusSyncRepository;
use PrestaShop\Module\PsEventbus\Repository\IncrementalSyncRepository;
use PrestaShop\Module\PsEventbus\Repository\LiveSyncRepository;

class SynchronizationService
{
Expand All @@ -20,10 +19,6 @@ class SynchronizationService
* @var IncrementalSyncRepository
*/
private $incrementalSyncRepository;
/**
* @var LiveSyncRepository
*/
private $liveSyncRepository;
/**
* @var ProxyServiceInterface
*/
Expand All @@ -36,13 +31,11 @@ class SynchronizationService
public function __construct(
EventbusSyncRepository $eventbusSyncRepository,
IncrementalSyncRepository $incrementalSyncRepository,
LiveSyncRepository $liveSyncRepository,
ProxyServiceInterface $proxyService,
PayloadDecorator $payloadDecorator
) {
$this->eventbusSyncRepository = $eventbusSyncRepository;
$this->incrementalSyncRepository = $incrementalSyncRepository;
$this->liveSyncRepository = $liveSyncRepository;
$this->proxyService = $proxyService;
$this->payloadDecorator = $payloadDecorator;
}
Expand Down Expand Up @@ -136,24 +129,6 @@ public function handleIncrementalSync(PaginatedApiDataProviderInterface $dataPro
return $this->returnSyncResponse($data, $response, $remainingObjects);
}

public function debounceLiveSync($shopContents)
{
$dateNow = date('Y-m-d H:i:s');
$lastChangeAt = $this->liveSyncRepository->getLastChangeAtByShopContent($shopContents);

if ($lastChangeAt !== null) {
$lastChangeAt = strtotime($lastChangeAt);
$dateNow = strtotime($dateNow);
$diff = $dateNow - $lastChangeAt;

if ($diff < 60 * 5) {
return false;
}

return $this->liveSyncRepository->upsertDebounce($shopContents, $dateNow);
}
}

/**
* @param array $data
* @param array $syncResponse
Expand Down

0 comments on commit 2b452bc

Please sign in to comment.