From 75a097a018a0090f5902758353c578fce4aa2a25 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Sat, 23 May 2026 18:43:42 +0000
Subject: [PATCH] =CustomBlocks.php overhaul relatively complete. Also refactored the gallery in gallery.min.js and the jvbRenderGallery.

---
 inc/managers/queue/Locker.php |   42 ++++++++++++++----------------------------
 1 files changed, 14 insertions(+), 28 deletions(-)

diff --git a/inc/managers/queue/Locker.php b/inc/managers/queue/Locker.php
index a048942..4d4b5d6 100644
--- a/inc/managers/queue/Locker.php
+++ b/inc/managers/queue/Locker.php
@@ -1,43 +1,24 @@
 <?php
 namespace JVBase\managers\queue;
-use wpdb;
 
 if (!defined('ABSPATH')) {
 	exit;
 }
-
 class Locker
 {
 	private string $lockKey;
 	private int $timeout;
-	protected wpdb $wpdb;
 	private ?string $token = null;
 
-	public function __construct(string $key = 'queue', int $timeout = 0)
+	public function __construct(string $key = 'queue', int $timeout = 60)
 	{
 		$this->lockKey = BASE . $key . '_lock';
 		$this->timeout = $timeout;
-		global $wpdb;
-		$this->wpdb = $wpdb;
 	}
 
-	/**
-	 * Execute callback with lock, auto-release after
-	 */
 	public function withLock(callable $callback): void
 	{
-		$acquired = $this->wpdb->get_var(
-			$this->wpdb->prepare(
-				'SELECT GET_LOCK(%s, %d)',
-				$this->lockKey,
-				$this->timeout
-			)
-		);
-
-		if ((int) $acquired !== 1) {
-			// Lock already held — just exit quietly
-			return;
-		}
+		if (!$this->acquire()) return;
 
 		try {
 			$callback();
@@ -46,13 +27,18 @@
 		}
 	}
 
-	public function unlock():void
+	private function acquire(): bool
 	{
-		$this->wpdb->get_var(
-			$this->wpdb->prepare(
-				'SELECT RELEASE_LOCK(%s)',
-				$this->lockKey
-			)
-		);
+		$this->token = bin2hex(random_bytes(8));
+		return (bool) wp_cache_add($this->lockKey, $this->token, 'locks', $this->timeout);
+	}
+
+	public function unlock(): void
+	{
+		$current = wp_cache_get($this->lockKey, 'locks');
+		if ($current === $this->token) {
+			wp_cache_delete($this->lockKey, 'locks');
+		}
+		$this->token = null;
 	}
 }

--
Gitblit v1.10.0