From a24a06002081ad71a78ffeff9072725ba39cf121 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Tue, 17 Feb 2026 20:05:31 +0000
Subject: [PATCH] =minor changes, particularly around the JVB_CHILD_URL pattern

---
 inc/managers/queue/Storage.php |   24 +++++++++++++++++-------
 1 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/inc/managers/queue/Storage.php b/inc/managers/queue/Storage.php
index 3c580df..40426e6 100644
--- a/inc/managers/queue/Storage.php
+++ b/inc/managers/queue/Storage.php
@@ -266,14 +266,24 @@
 		return $row ? $this->rowToOperation($row) : null;
 	}
 
-	public function findMergeable(string $type, int $userId): ?Operation
+	public function findMergeable(string $type, int $userId, array $criteria = []): ?Operation
 	{
-		$row = $this->wpdb->get_row($this->wpdb->prepare(
-			"SELECT * FROM {$this->table}
-             WHERE type = %s AND user_id = %d AND state IN ('pending', 'scheduled')
-             ORDER BY created_at DESC LIMIT 1",
-			$type, $userId
-		));
+		$sql = "SELECT * FROM {$this->table}
+            WHERE type = %s AND user_id = %d AND state IN ('pending', 'scheduled')";
+		$params = [$type, $userId];
+
+		foreach ($criteria as $key => $value) {
+			if ($value === null) {
+				continue;
+			}
+			$sql .= " AND JSON_UNQUOTE(JSON_EXTRACT(request_data, %s)) = %s";
+			$params[] = '$.' . $key;
+			$params[] = (string) $value;
+		}
+
+		$sql .= " ORDER BY created_at DESC LIMIT 1";
+
+		$row = $this->wpdb->get_row($this->wpdb->prepare($sql, ...$params));
 
 		$this->invalidateUser($userId);
 

--
Gitblit v1.10.0