From 618922db47ef5dee06fa43051c80a9ab7a6ffd0c Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Tue, 31 Mar 2026 12:50:14 +0200 Subject: [PATCH 1/5] Improve typings for `objectTypeProvider` --- .../endpoint/controller/core/reactions/SetReaction.class.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/wcfsetup/install/files/lib/system/endpoint/controller/core/reactions/SetReaction.class.php b/wcfsetup/install/files/lib/system/endpoint/controller/core/reactions/SetReaction.class.php index f7b5e963ee..377e44ed27 100644 --- a/wcfsetup/install/files/lib/system/endpoint/controller/core/reactions/SetReaction.class.php +++ b/wcfsetup/install/files/lib/system/endpoint/controller/core/reactions/SetReaction.class.php @@ -5,6 +5,7 @@ use Laminas\Diactoros\Response\JsonResponse; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; +use wcf\data\like\ILikeObjectTypeProvider; use wcf\data\like\IRestrictedLikeObjectTypeProvider; use wcf\data\like\Like; use wcf\data\like\object\ILikeObject; @@ -49,6 +50,8 @@ public function __invoke(ServerRequestInterface $request, array $variables): Res } $objectTypeProvider = $objectType->getProcessor(); + \assert($objectTypeProvider instanceof ILikeObjectTypeProvider); + $likeable = $objectTypeProvider->getObjectByID($parameters->objectID); \assert($likeable instanceof ILikeObject); $likeable->setObjectType($objectType); From 8db4df591b713ca2cd9595448b4341b594379fa0 Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Tue, 31 Mar 2026 13:35:16 +0200 Subject: [PATCH 2/5] Deprecate `ReactionHandler::$likeableObjectsCache` These objects were only used for the creation of the data-attributes (`getDataAttributes`), which are no longer needed with the new Reaction button. --- .../files/lib/system/reaction/ReactionHandler.class.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/wcfsetup/install/files/lib/system/reaction/ReactionHandler.class.php b/wcfsetup/install/files/lib/system/reaction/ReactionHandler.class.php index 11a97a3775..30a2c541ca 100644 --- a/wcfsetup/install/files/lib/system/reaction/ReactionHandler.class.php +++ b/wcfsetup/install/files/lib/system/reaction/ReactionHandler.class.php @@ -43,6 +43,7 @@ final class ReactionHandler extends SingletonFactory /** * @var ILikeObject[][] + * @deprecated 6.3 */ private array $likeableObjectsCache = []; @@ -90,6 +91,8 @@ public function getReactionTypeByID(int $reactionID): ?ReactionType /** * Builds the data attributes for the object container. + * + * @deprecated 6.3 */ public function getDataAttributes(string $objectTypeName, int $objectID): string { @@ -122,6 +125,8 @@ public function getDataAttributes(string $objectTypeName, int $objectID): string /** * @param list $objectIDs + * + * @deprecated 6.3 */ public function cacheLikeableObjects(string $objectTypeName, array $objectIDs): void { @@ -148,6 +153,8 @@ public function cacheLikeableObjects(string $objectTypeName, array $objectIDs): /** * Get an likeable object from the internal cache. + * + * @deprecated 6.3 */ public function getLikeableObject(string $objectTypeName, int $objectID): ILikeObject { From 22c423fc8901064842a43935670716365b1a896c Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Tue, 31 Mar 2026 13:38:19 +0200 Subject: [PATCH 3/5] Skip loading of likeable objects in `TCollectionReactions` --- .../install/files/lib/data/TCollectionReactions.class.php | 2 +- .../files/lib/system/reaction/ReactionHandler.class.php | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/wcfsetup/install/files/lib/data/TCollectionReactions.class.php b/wcfsetup/install/files/lib/data/TCollectionReactions.class.php index 0bd62ed17d..2db706d714 100644 --- a/wcfsetup/install/files/lib/data/TCollectionReactions.class.php +++ b/wcfsetup/install/files/lib/data/TCollectionReactions.class.php @@ -41,7 +41,7 @@ private function loadReactionData(): void $this->reactionData = []; $objectType = ReactionHandler::getInstance()->getObjectType($this->getReactionObjectType()); - ReactionHandler::getInstance()->loadLikeObjects($objectType, $this->getObjectIDs()); + ReactionHandler::getInstance()->loadLikeObjects($objectType, $this->getObjectIDs(), false); foreach ($this->getObjectIDs() as $objectID) { $likeObject = ReactionHandler::getInstance()->getLikeObject($objectType, $objectID); diff --git a/wcfsetup/install/files/lib/system/reaction/ReactionHandler.class.php b/wcfsetup/install/files/lib/system/reaction/ReactionHandler.class.php index 30a2c541ca..b5ac090182 100644 --- a/wcfsetup/install/files/lib/system/reaction/ReactionHandler.class.php +++ b/wcfsetup/install/files/lib/system/reaction/ReactionHandler.class.php @@ -215,13 +215,15 @@ public function getLikeObjects(ObjectType $objectType): array * * @param list $objectIDs */ - public function loadLikeObjects(ObjectType $objectType, array $objectIDs): int + public function loadLikeObjects(ObjectType $objectType, array $objectIDs, bool $loadLikeableObjects = true): int { if (empty($objectIDs)) { return 0; } - $this->cacheLikeableObjects($objectType->objectType, $objectIDs); + if ($loadLikeableObjects) { + $this->cacheLikeableObjects($objectType->objectType, $objectIDs); + } $i = 0; From 196bc39b9fb54cf35a7bae7a6418adc89a735a06 Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Tue, 31 Mar 2026 13:52:04 +0200 Subject: [PATCH 4/5] Fix an issue where non-existent Like objects were being queried again --- .../system/reaction/ReactionHandler.class.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/wcfsetup/install/files/lib/system/reaction/ReactionHandler.class.php b/wcfsetup/install/files/lib/system/reaction/ReactionHandler.class.php index b5ac090182..dbe88c6856 100644 --- a/wcfsetup/install/files/lib/system/reaction/ReactionHandler.class.php +++ b/wcfsetup/install/files/lib/system/reaction/ReactionHandler.class.php @@ -32,7 +32,7 @@ final class ReactionHandler extends SingletonFactory { /** - * @var LikeObject[][] + * @var array> */ private array $likeObjectCache = []; @@ -188,7 +188,10 @@ public function getObjectType(string $objectName): ?ObjectType public function getLikeObject(ObjectType $objectType, int $objectID): ?LikeObject { - if (!isset($this->likeObjectCache[$objectType->objectTypeID][$objectID])) { + if ( + !isset($this->likeObjectCache[$objectType->objectTypeID]) + || !\array_key_exists($objectID, $this->likeObjectCache[$objectType->objectTypeID]) + ) { $this->loadLikeObjects($objectType, [$objectID]); } @@ -203,7 +206,8 @@ public function getLikeObject(ObjectType $objectType, int $objectID): ?LikeObjec public function getLikeObjects(ObjectType $objectType): array { if (isset($this->likeObjectCache[$objectType->objectTypeID])) { - return $this->likeObjectCache[$objectType->objectTypeID]; + // Use `array_filter` to filter `null` values. + return \array_filter($this->likeObjectCache[$objectType->objectTypeID]); } return []; @@ -257,6 +261,12 @@ public function loadLikeObjects(ObjectType $objectType, array $objectIDs, bool $ $i++; } + foreach ($objectIDs as $objectID) { + if (!isset($this->likeObjectCache[$objectType->objectTypeID][$objectID])) { + $this->likeObjectCache[$objectType->objectTypeID][$objectID] = null; + } + } + return $i; } From fe38730286d33d8c7e76b3840553963ba0651dc9 Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Tue, 31 Mar 2026 17:19:52 +0200 Subject: [PATCH 5/5] Apply suggestions from code review --- .../files/lib/system/reaction/ReactionHandler.class.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/wcfsetup/install/files/lib/system/reaction/ReactionHandler.class.php b/wcfsetup/install/files/lib/system/reaction/ReactionHandler.class.php index dbe88c6856..966cf6c4df 100644 --- a/wcfsetup/install/files/lib/system/reaction/ReactionHandler.class.php +++ b/wcfsetup/install/files/lib/system/reaction/ReactionHandler.class.php @@ -262,9 +262,7 @@ public function loadLikeObjects(ObjectType $objectType, array $objectIDs, bool $ } foreach ($objectIDs as $objectID) { - if (!isset($this->likeObjectCache[$objectType->objectTypeID][$objectID])) { - $this->likeObjectCache[$objectType->objectTypeID][$objectID] = null; - } + $this->likeObjectCache[$objectType->objectTypeID][$objectID] ??= null; } return $i;