From aff2096065f8f6851fe23da059397dde9cb29abb Mon Sep 17 00:00:00 2001 From: Daniel Beardsley Date: Tue, 30 Jun 2026 11:47:13 -0700 Subject: [PATCH 1/2] Scope: Delete key when deleting scope Previously, to "delete" a scope, we immediately generated a new value and set() it overtop of the previous one. 1. This isn't really needed. Sometimes we deleteScope() and don't immediately access it, so doing it eagerly was un-needed 2. When using McRouter, delete() is guaranteed to be propagated while set() has a less strong guarantee Yes, this means that in some cases (hard to tell how common) delete is followed by a set() of the scope key shortly afterward and this change adds a delete where one wasn't present before. However, I think this is outweighed by point 1 above and point 2 shows that this change is important. The code as it was meant that in our odd case with a bifurcated cache, we had to issue a delete() with every set() because deleteScope() only did a set(). There is a bunch of nuance here (see https://github.com/iFixit/ifixit/pull/62768). --- library/iFixit/Matryoshka/Scope.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/library/iFixit/Matryoshka/Scope.php b/library/iFixit/Matryoshka/Scope.php index bbea6b2..1e9a7ff 100644 --- a/library/iFixit/Matryoshka/Scope.php +++ b/library/iFixit/Matryoshka/Scope.php @@ -9,7 +9,7 @@ class Scope extends Prefix { private $scopePrefix; public function __construct(Backend $backend, $scopeName) { - // The prefix we pass along to the Prefix() constructor is never used, so + // The prefix we pass along to the Prefix() constructor is never used, so // it doesn't matter. parent::__construct($backend, /* $prefix = */ null); @@ -47,10 +47,12 @@ public function getScopeName() { * this scope. */ public function deleteScope(): bool { - // Delete the scope by setting a new value for it. - $prefix = $this->getScopePrefix($reset = true); + // Explicitly delete the scope key from the backend to ensure that it is + // removed. + $this->backend->delete($this->getScopeKey()); + $this->scopePrefix = null; - return $prefix !== self::MISS; + return true; } private function getScopeKey() { From a88bd087b169b7f2a2c369701170317d63cf9617 Mon Sep 17 00:00:00 2001 From: Daniel Beardsley Date: Tue, 30 Jun 2026 12:42:06 -0700 Subject: [PATCH 2/2] Scope: Remove unused reset parameter from getScopePrefix No caller ever passed reset, so drop the dead parameter and the branches that only ran when it was true. Co-Authored-By: Claude Opus 4.8 (1M context) --- library/iFixit/Matryoshka/Scope.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/library/iFixit/Matryoshka/Scope.php b/library/iFixit/Matryoshka/Scope.php index 1e9a7ff..4700f9a 100644 --- a/library/iFixit/Matryoshka/Scope.php +++ b/library/iFixit/Matryoshka/Scope.php @@ -21,9 +21,9 @@ public function getPrefix() { return $this->scopePrefix ?: $this->getScopePrefix(); } - public function getScopePrefix(bool $reset = false, bool $generateOnMiss = true) { - if ($this->scopePrefix === null || $reset) { - $scopeValue = $reset ? self::MISS : $this->backend->get($this->getScopeKey()); + public function getScopePrefix(bool $generateOnMiss = true) { + if ($this->scopePrefix === null) { + $scopeValue = $this->backend->get($this->getScopeKey()); if ($scopeValue === self::MISS) { if ($generateOnMiss) { $scopeValue = substr(md5(microtime() . $this->scopeName), 0, 16);