From c7a38e06585c00467447863504ee55a44dcf2aa9 Mon Sep 17 00:00:00 2001 From: maxpogonowski Date: Thu, 22 Jul 2021 16:48:01 +1000 Subject: [PATCH 1/8] demonstrate problem --- src/GraphQL/Execution/Executor.php | 1 + src/Plugin/GraphQL/Schema/SdlSchemaPluginBase.php | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/GraphQL/Execution/Executor.php b/src/GraphQL/Execution/Executor.php index c16ae5451..02e09acc9 100644 --- a/src/GraphQL/Execution/Executor.php +++ b/src/GraphQL/Execution/Executor.php @@ -300,6 +300,7 @@ protected function cachePrefix() { ksort($extensions); $hash = hash('sha256', serialize([ + 'server' => $this->context->getServer()->name, 'query' => DocumentSerializer::serializeDocument($this->document), 'variables' => $variables, 'extensions' => $extensions, diff --git a/src/Plugin/GraphQL/Schema/SdlSchemaPluginBase.php b/src/Plugin/GraphQL/Schema/SdlSchemaPluginBase.php index 47d1e7f2c..cb73dbce6 100644 --- a/src/Plugin/GraphQL/Schema/SdlSchemaPluginBase.php +++ b/src/Plugin/GraphQL/Schema/SdlSchemaPluginBase.php @@ -164,7 +164,7 @@ protected function getSchemaDocument(array $extensions = []) { // Only use caching of the parsed document if we aren't in development mode. $cid = "schema:{$this->getPluginId()}"; if (empty($this->inDevelopment) && $cache = $this->astCache->get($cid)) { - return $cache->data; +// return $cache->data; } $extensions = array_filter(array_map(function (SchemaExtensionPluginInterface $extension) { @@ -196,7 +196,7 @@ protected function getExtensionDocument(array $extensions = []) { // Only use caching of the parsed document if we aren't in development mode. $cid = "extension:{$this->getPluginId()}"; if (empty($this->inDevelopment) && $cache = $this->astCache->get($cid)) { - return $cache->data; +// return $cache->data; } $extensions = array_filter(array_map(function (SchemaExtensionPluginInterface $extension) { From d99470d4da81a695ea817df1c9de42646a713d18 Mon Sep 17 00:00:00 2001 From: maxpogonowski Date: Fri, 23 Jul 2021 12:24:45 +1000 Subject: [PATCH 2/8] pass server ID to plugin --- src/Entity/Server.php | 1 + .../GraphQL/Schema/SdlSchemaPluginBase.php | 24 +++++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/Entity/Server.php b/src/Entity/Server.php index e569ea343..0ca913bbf 100644 --- a/src/Entity/Server.php +++ b/src/Entity/Server.php @@ -211,6 +211,7 @@ public function configuration() { /** @var \Drupal\graphql\Plugin\SchemaPluginInterface $plugin */ $plugin = $manager->createInstance($schema); + $plugin->setServerId($this->name); if ($plugin instanceof ConfigurableInterface && $config = $this->get('schema_configuration')) { $plugin->setConfiguration($config[$schema] ?? []); } diff --git a/src/Plugin/GraphQL/Schema/SdlSchemaPluginBase.php b/src/Plugin/GraphQL/Schema/SdlSchemaPluginBase.php index cb73dbce6..f174e0a98 100644 --- a/src/Plugin/GraphQL/Schema/SdlSchemaPluginBase.php +++ b/src/Plugin/GraphQL/Schema/SdlSchemaPluginBase.php @@ -41,6 +41,13 @@ abstract class SdlSchemaPluginBase extends PluginBase implements SchemaPluginInt */ protected $inDevelopment; + /** + * The ID of the server using this plugin. + * + * @var string $serverId + */ + protected $serverId; + /** * The schema extension plugin manager. * @@ -108,6 +115,15 @@ public function __construct( $this->moduleHandler = $moduleHandler; } + /** + * Set the serverID, required for cache id generation. + * + * @param string $serverId + */ + public function setServerId(string $serverId) { + $this->serverId = $serverId; + } + /** * {@inheritdoc} * @@ -162,9 +178,9 @@ protected function getExtensions() { */ protected function getSchemaDocument(array $extensions = []) { // Only use caching of the parsed document if we aren't in development mode. - $cid = "schema:{$this->getPluginId()}"; + $cid = "server:{$this->serverId}:schema:{$this->getPluginId()}"; if (empty($this->inDevelopment) && $cache = $this->astCache->get($cid)) { -// return $cache->data; + return $cache->data; } $extensions = array_filter(array_map(function (SchemaExtensionPluginInterface $extension) { @@ -194,9 +210,9 @@ protected function getSchemaDocument(array $extensions = []) { */ protected function getExtensionDocument(array $extensions = []) { // Only use caching of the parsed document if we aren't in development mode. - $cid = "extension:{$this->getPluginId()}"; + $cid = "server:{$this->serverId}:extension:{$this->getPluginId()}"; if (empty($this->inDevelopment) && $cache = $this->astCache->get($cid)) { -// return $cache->data; + return $cache->data; } $extensions = array_filter(array_map(function (SchemaExtensionPluginInterface $extension) { From bed24737d3f0b35c423b5b0012c364e4a55a66dc Mon Sep 17 00:00:00 2001 From: maxpogonowski Date: Fri, 23 Jul 2021 12:33:27 +1000 Subject: [PATCH 3/8] satisfy phpstan --- src/Plugin/GraphQL/Schema/SdlSchemaPluginBase.php | 6 ++---- src/Plugin/SchemaPluginInterface.php | 10 ++++++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Plugin/GraphQL/Schema/SdlSchemaPluginBase.php b/src/Plugin/GraphQL/Schema/SdlSchemaPluginBase.php index f174e0a98..656208b71 100644 --- a/src/Plugin/GraphQL/Schema/SdlSchemaPluginBase.php +++ b/src/Plugin/GraphQL/Schema/SdlSchemaPluginBase.php @@ -116,11 +116,9 @@ public function __construct( } /** - * Set the serverID, required for cache id generation. - * - * @param string $serverId + * {@inheritdoc} */ - public function setServerId(string $serverId) { + public function setServerId(string $serverId): void { $this->serverId = $serverId; } diff --git a/src/Plugin/SchemaPluginInterface.php b/src/Plugin/SchemaPluginInterface.php index d13c1e71d..e3f0db18a 100644 --- a/src/Plugin/SchemaPluginInterface.php +++ b/src/Plugin/SchemaPluginInterface.php @@ -14,6 +14,16 @@ */ interface SchemaPluginInterface extends PluginInspectionInterface, DerivativeInspectionInterface { + /** + * Set the serverID, required for cache id generation. + * + * @param string + * The machine name of the server using this plugin. + * + * @return null + */ + public function setServerId(string $serverId): void; + /** * Retrieves the schema. * From 5ae3f29551c1ec06f6057f24c3309cdb818d3cb8 Mon Sep 17 00:00:00 2001 From: maxpogonowski Date: Fri, 23 Jul 2021 12:40:08 +1000 Subject: [PATCH 4/8] satisfy phpstan #2 --- src/Plugin/SchemaPluginInterface.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Plugin/SchemaPluginInterface.php b/src/Plugin/SchemaPluginInterface.php index e3f0db18a..887eb9157 100644 --- a/src/Plugin/SchemaPluginInterface.php +++ b/src/Plugin/SchemaPluginInterface.php @@ -17,10 +17,8 @@ interface SchemaPluginInterface extends PluginInspectionInterface, DerivativeIns /** * Set the serverID, required for cache id generation. * - * @param string + * @param string $serverId * The machine name of the server using this plugin. - * - * @return null */ public function setServerId(string $serverId): void; From b7d1f4cab568d3e235b338a3cf3da6525232a055 Mon Sep 17 00:00:00 2001 From: maxpogonowski Date: Fri, 23 Jul 2021 12:44:12 +1000 Subject: [PATCH 5/8] satisfy phpcs --- src/Plugin/SchemaPluginInterface.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Plugin/SchemaPluginInterface.php b/src/Plugin/SchemaPluginInterface.php index 887eb9157..46b22137f 100644 --- a/src/Plugin/SchemaPluginInterface.php +++ b/src/Plugin/SchemaPluginInterface.php @@ -17,7 +17,7 @@ interface SchemaPluginInterface extends PluginInspectionInterface, DerivativeIns /** * Set the serverID, required for cache id generation. * - * @param string $serverId + * @param string * The machine name of the server using this plugin. */ public function setServerId(string $serverId): void; From 0368ccfc04276a0daeb217d93c59b9a864854b03 Mon Sep 17 00:00:00 2001 From: Max Pogonowski Date: Thu, 5 Aug 2021 19:28:44 +1000 Subject: [PATCH 6/8] Update src/Plugin/SchemaPluginInterface.php Co-authored-by: Alexander Varwijk --- src/Plugin/SchemaPluginInterface.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Plugin/SchemaPluginInterface.php b/src/Plugin/SchemaPluginInterface.php index 46b22137f..887eb9157 100644 --- a/src/Plugin/SchemaPluginInterface.php +++ b/src/Plugin/SchemaPluginInterface.php @@ -17,7 +17,7 @@ interface SchemaPluginInterface extends PluginInspectionInterface, DerivativeIns /** * Set the serverID, required for cache id generation. * - * @param string + * @param string $serverId * The machine name of the server using this plugin. */ public function setServerId(string $serverId): void; From 8d1a98d72bfd80c5a6225431df12d546a032354a Mon Sep 17 00:00:00 2001 From: Max Pogonowski Date: Thu, 5 Aug 2021 19:28:50 +1000 Subject: [PATCH 7/8] Update src/Plugin/GraphQL/Schema/SdlSchemaPluginBase.php Co-authored-by: Alexander Varwijk --- src/Plugin/GraphQL/Schema/SdlSchemaPluginBase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Plugin/GraphQL/Schema/SdlSchemaPluginBase.php b/src/Plugin/GraphQL/Schema/SdlSchemaPluginBase.php index 656208b71..a0976cf20 100644 --- a/src/Plugin/GraphQL/Schema/SdlSchemaPluginBase.php +++ b/src/Plugin/GraphQL/Schema/SdlSchemaPluginBase.php @@ -44,7 +44,7 @@ abstract class SdlSchemaPluginBase extends PluginBase implements SchemaPluginInt /** * The ID of the server using this plugin. * - * @var string $serverId + * @var string */ protected $serverId; From 2ec7f03fe3c9880c9a55a33d455a4346ff96bdfa Mon Sep 17 00:00:00 2001 From: Max Pogonowski Date: Tue, 3 Sep 2024 12:11:00 +1000 Subject: [PATCH 8/8] Add server id to cache key in getFullSchemaDocument --- src/Plugin/GraphQL/Schema/SdlSchemaPluginBase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Plugin/GraphQL/Schema/SdlSchemaPluginBase.php b/src/Plugin/GraphQL/Schema/SdlSchemaPluginBase.php index 405f452d2..76e32ca7c 100644 --- a/src/Plugin/GraphQL/Schema/SdlSchemaPluginBase.php +++ b/src/Plugin/GraphQL/Schema/SdlSchemaPluginBase.php @@ -223,7 +223,7 @@ protected function getSchemaDocument(array $extensions = []) { */ private function getFullSchemaDocument(Schema $schema, array $extensions): ?DocumentNode { // Only use caching of the parsed document if we aren't in development mode. - $cid = "full:{$this->getPluginId()}"; + $cid = "server:{$this->serverId}:full:{$this->getPluginId()}"; if (empty($this->inDevelopment) && $cache = $this->astCache->get($cid)) { return $cache->data; }