mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
fix: use spl_object_hash for lock keys instead of WeakMap
Replace WeakMap with a plain array keyed by spl_object_hash($utopia) as suggested in review. Entry is cleaned up in the finally block to prevent leaks.
This commit is contained in:
@@ -18,9 +18,9 @@ class Resolvers
|
||||
/**
|
||||
* Request-scoped locks keyed by the per-request GraphQL Http instance.
|
||||
*
|
||||
* @var \WeakMap<Http, ResolverLock>|null
|
||||
* @var array<string, ResolverLock>
|
||||
*/
|
||||
private static ?\WeakMap $locks = null;
|
||||
private static array $locks = [];
|
||||
|
||||
/**
|
||||
* Clone the shared GraphQL response so each resolver writes into an
|
||||
@@ -88,12 +88,12 @@ class Resolvers
|
||||
*/
|
||||
private static function getLock(Http $utopia): ResolverLock
|
||||
{
|
||||
self::$locks ??= new \WeakMap();
|
||||
if (!isset(self::$locks[$utopia])) {
|
||||
self::$locks[$utopia] = new ResolverLock();
|
||||
$key = \spl_object_hash($utopia);
|
||||
if (!isset(self::$locks[$key])) {
|
||||
self::$locks[$key] = new ResolverLock();
|
||||
}
|
||||
|
||||
return self::$locks[$utopia];
|
||||
return self::$locks[$key];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -468,6 +468,7 @@ class Resolvers
|
||||
}
|
||||
|
||||
self::releaseLock($lock);
|
||||
unset(self::$locks[\spl_object_hash($utopia)]);
|
||||
}
|
||||
|
||||
if ($statusCode < 200 || $statusCode >= 400) {
|
||||
|
||||
Reference in New Issue
Block a user