Skip to content

Commit

Permalink
CC-33982: P&S optimisation (#11033)
Browse files Browse the repository at this point in the history
P&S optimisation
  • Loading branch information
dmiseev authored Sep 11, 2024
1 parent 0c39222 commit 55a297f
Show file tree
Hide file tree
Showing 16 changed files with 816 additions and 4 deletions.
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
"php": ">=8.1",
"spryker/elastica": "^2.0.0 || ^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0",
"spryker/kernel": "^3.49.0",
"spryker/log": "^3.0.0",
"spryker/propel-orm": "^1.16.0",
"spryker/queue": "^1.0.0",
"spryker/search": "^8.3.0",
"spryker/storage": "^3.4.1",
"spryker/store": "^1.19.0",
"spryker/symfony": "^3.1.0",
"spryker/synchronization-extension": "^1.3.0",
"spryker/transfer": "^3.25.0",
"spryker/transfer": "^3.27.0",
"spryker/util-encoding": "^2.0.0"
},
"require-dev": {
Expand All @@ -27,6 +28,7 @@
"spryker/cms-page-search": "*",
"spryker/cms-storage": "*",
"spryker/code-sniffer": "*",
"spryker/container": "*",
"spryker/glossary-storage": "*",
"spryker/navigation-storage": "*",
"spryker/price-product-storage": "*",
Expand Down
2 changes: 1 addition & 1 deletion dependency.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"include": {
"spryker/transfer": "Provides transfer objects definition with `::get*OrFail()` functionality."
"spryker/transfer": "Provides transfer objects definition with strict types."
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,14 @@
<property name="name" type="string"/>
</transfer>

<transfer name="SynchronizationMessage" strict="true">
<property name="data" type="array" singular="data"/>
<property name="fallbackQueueMessage" type="QueueSendMessage"/>
<property name="fallbackQueueName" type="string"/>
<property name="syncDestinationType" type="string"/>
<property name="operationType" type="string"/>
<property name="locale" type="string"/>
<property name="resource" type="string"/>
</transfer>

</transfers>
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ class SynchronizationSearch implements SynchronizationInterface
*/
protected const STORE = 'store';

/**
* @var string
*/
protected const DESTINATION_TYPE = 'search';

/**
* @var \Spryker\Zed\Synchronization\Dependency\Client\SynchronizationToSearchClientInterface
*/
Expand Down Expand Up @@ -249,6 +254,16 @@ public function deleteBulk(array $data): void
$this->searchClient->deleteBulk($searchDocumentTransfers);
}

/**
* @param string $destinationType
*
* @return bool
*/
public function isDestinationTypeApplicable(string $destinationType): bool
{
return $destinationType === static::DESTINATION_TYPE;
}

/**
* @param array<string, mixed> $data
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ class SynchronizationStorage implements SynchronizationInterface
*/
public const VALUE = 'value';

/**
* @var string
*/
protected const DESTINATION_TYPE = 'storage';

/**
* @var \Spryker\Zed\Synchronization\Dependency\Client\SynchronizationToStorageClientInterface
*/
Expand Down Expand Up @@ -174,4 +179,14 @@ public function deleteBulk(array $data): void

$this->storageClient->deleteMulti($keysToDelete);
}

/**
* @param string $destinationType
*
* @return bool
*/
public function isDestinationTypeApplicable(string $destinationType): bool
{
return $destinationType === static::DESTINATION_TYPE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,11 @@ public function delete(array $data, $queueName);
* @return void
*/
public function deleteBulk(array $data): void;

/**
* @param string $destinationType
*
* @return bool
*/
public function isDestinationTypeApplicable(string $destinationType): bool;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
use Spryker\Zed\Synchronization\Business\Message\QueueMessageProcessorInterface;
use Spryker\Zed\Synchronization\Business\Search\SynchronizationSearch;
use Spryker\Zed\Synchronization\Business\Storage\SynchronizationStorage;
use Spryker\Zed\Synchronization\Business\Synchronizer\InMemoryMessageSynchronizer;
use Spryker\Zed\Synchronization\Business\Synchronizer\MessageSynchronizerInterface;
use Spryker\Zed\Synchronization\Business\Validation\OutdatedValidator;
use Spryker\Zed\Synchronization\Dependency\Facade\SynchronizationToStoreFacadeInterface;
use Spryker\Zed\Synchronization\SynchronizationDependencyProvider;
Expand All @@ -29,6 +31,11 @@
*/
class SynchronizationBusinessFactory extends AbstractBusinessFactory
{
/**
* @var \Spryker\Zed\Synchronization\Business\Synchronizer\MessageSynchronizerInterface|null
*/
protected static $inMemoryMessageSynchronizer;

/**
* @return \Spryker\Zed\Synchronization\Business\Synchronization\SynchronizationInterface
*/
Expand Down Expand Up @@ -153,6 +160,32 @@ protected function createQueueMessageCreator()
);
}

/**
* @return \Spryker\Zed\Synchronization\Business\Synchronizer\MessageSynchronizerInterface
*/
public function createInMemoryMessageSynchronizer(): MessageSynchronizerInterface
{
if (!static::$inMemoryMessageSynchronizer) {
static::$inMemoryMessageSynchronizer = new InMemoryMessageSynchronizer(
$this->getQueueClient(),
$this->createSynchronizationWriters(),
);
}

return static::$inMemoryMessageSynchronizer;
}

/**
* @return list<\Spryker\Zed\Synchronization\Business\Synchronization\SynchronizationInterface>
*/
public function createSynchronizationWriters(): array
{
return [
$this->createStorageManager(),
$this->createSearchManager(),
];
}

/**
* @return \Spryker\Zed\Synchronization\Dependency\Client\SynchronizationToStorageClientInterface
*/
Expand Down
27 changes: 27 additions & 0 deletions src/Spryker/Zed/Synchronization/Business/SynchronizationFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace Spryker\Zed\Synchronization\Business;

use Generated\Shared\Transfer\SynchronizationMessageTransfer;
use Spryker\Zed\Kernel\Business\AbstractFacade;

/**
Expand Down Expand Up @@ -148,4 +149,30 @@ public function getAvailableResourceNames(): array
{
return $this->getFactory()->createExporterPluginResolver()->getAvailableResourceNames();
}

/**
* {@inheritDoc}
*
* @api
*
* @param \Generated\Shared\Transfer\SynchronizationMessageTransfer $synchronizationMessage
*
* @return void
*/
public function addSynchronizationMessageToBuffer(SynchronizationMessageTransfer $synchronizationMessage): void
{
$this->getFactory()->createInMemoryMessageSynchronizer()->addSynchronizationMessage($synchronizationMessage);
}

/**
* {@inheritDoc}
*
* @api
*
* @return void
*/
public function flushSynchronizationMessagesFromBuffer(): void
{
$this->getFactory()->createInMemoryMessageSynchronizer()->flushSynchronizationMessages();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

namespace Spryker\Zed\Synchronization\Business;

use Generated\Shared\Transfer\SynchronizationMessageTransfer;

interface SynchronizationFacadeInterface
{
/**
Expand Down Expand Up @@ -135,4 +137,29 @@ public function executeResolvedPluginsBySourcesWithIds(array $resources, array $
* @return array<string>
*/
public function getAvailableResourceNames(): array;

/**
* Specification:
* - Adds a message to buffer storage.
* - The message will be synchronized to storage/search when {@link flushSynchronizationMessagesFromBuffer()} is called.
*
* @api
*
* @param \Generated\Shared\Transfer\SynchronizationMessageTransfer $synchronizationMessage
*
* @return void
*/
public function addSynchronizationMessageToBuffer(SynchronizationMessageTransfer $synchronizationMessage): void;

/**
* Specification:
* - Syncs the buffered messages to storage/search.
* - Marks the messages as failed if error occurs.
* - Sends failed messages to queue as a fallback.
*
* @api
*
* @return void
*/
public function flushSynchronizationMessagesFromBuffer(): void;
}
Loading

0 comments on commit 55a297f

Please sign in to comment.