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/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); diff --git a/wcfsetup/install/files/lib/system/reaction/ReactionHandler.class.php b/wcfsetup/install/files/lib/system/reaction/ReactionHandler.class.php index 11a97a3775..966cf6c4df 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 = []; @@ -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 { @@ -181,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]); } @@ -196,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 []; @@ -208,13 +219,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; @@ -248,6 +261,10 @@ public function loadLikeObjects(ObjectType $objectType, array $objectIDs): int $i++; } + foreach ($objectIDs as $objectID) { + $this->likeObjectCache[$objectType->objectTypeID][$objectID] ??= null; + } + return $i; }