From 8b82035f3f8be1462a7125ad7eafb990ca17fa94 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Sat, 07 Feb 2026 17:37:23 +0000
Subject: [PATCH] =Port over to jakevan

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

diff --git a/inc/managers/queue/Storage.php b/inc/managers/queue/Storage.php
index e565146..e4a5397 100644
--- a/inc/managers/queue/Storage.php
+++ b/inc/managers/queue/Storage.php
@@ -34,24 +34,19 @@
 	{
 		$now = current_time('mysql');
 
-		$rows = $this->wpdb->get_results($this->wpdb->prepare("
-			SELECT oq.* FROM {$this->table} oq
-			WHERE oq.state IN ('pending', 'scheduled')
-			  AND oq.scheduled_at <= %s
-			  AND NOT EXISTS (
-				  SELECT 1
-				  FROM JSON_TABLE(
-					  COALESCE(NULLIF(oq.dependencies, 'null'), '[]'),
-					  '\$[*]' COLUMNS (dep_id VARCHAR(64) PATH '\$')
-				  ) AS deps
-				  JOIN {$this->table} dep ON dep.id = deps.dep_id
-				  WHERE dep.state != 'completed'
-					 OR dep.outcome NOT IN ('success', 'partial')
-			  )
-			ORDER BY FIELD(oq.priority, 'high', 'normal', 'low'), oq.scheduled_at
-			LIMIT %d
-			FOR UPDATE SKIP LOCKED
-		", $now, $limit));
+		$rows = $this->wpdb->get_results(
+			$this->wpdb->prepare("
+            SELECT *
+            FROM {$this->table}
+            WHERE state IN ('pending', 'scheduled')
+              AND scheduled_at <= %s
+            ORDER BY
+              FIELD(priority, 'high', 'normal', 'low'),
+              scheduled_at
+            LIMIT %d
+            FOR UPDATE SKIP LOCKED
+        ", $now, $limit)
+		);
 
 		return array_map([$this, 'rowToOperation'], $rows ?: []);
 	}
@@ -143,6 +138,9 @@
 			return false;
 		}
 
+		Cache::invalidateGroup('queue');
+//		$this->invalidateUser($op->userId);
+
 		return true;
 	}
 
@@ -177,7 +175,6 @@
 		];
 
 		$updated = $wpdb->update($table, $data, $where);
-		$this->invalidateQueueCache();
 
 		if ($updated === 0) {
 			return true;
@@ -187,6 +184,9 @@
 			error_log('[Storage::saveFinal] DB error: ' . $wpdb->last_error);
 			return false;
 		}
+		Cache::invalidateGroup('queue');
+//		$this->invalidateQueueCache();
+//		$this->invalidateUser($op->userId);
 
 		return true;
 	}
@@ -219,7 +219,8 @@
 		]);
 
 		if ($result) {
-			$this->invalidateUser($op->userId);
+//			$this->invalidateUser($op->userId);
+			Cache::invalidateGroup('queue');
 		}
 
 		return $result !== false;
@@ -244,6 +245,8 @@
 			$type, $userId
 		));
 
+		$this->invalidateUser($userId);
+
 		return $row ? $this->rowToOperation($row) : null;
 	}
 
@@ -448,6 +451,7 @@
 	private function invalidateUser(int $userId): void
 	{
 		$this->cache->forget($userId);
+		Cache::touch($userId);
 	}
 	public function getLastError(): string
 	{

--
Gitblit v1.10.0