From d38d825e3484d822ea3c1f0fb1df37ecf386b18a Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Sun, 04 Jan 2026 19:54:16 +0000
Subject: [PATCH] =TaxonomyCreator.js debugging

---
 inc/rest/routes/QueueRoutes.php |   97 ++++++++++--------------------------------------
 1 files changed, 21 insertions(+), 76 deletions(-)

diff --git a/inc/rest/routes/QueueRoutes.php b/inc/rest/routes/QueueRoutes.php
index a5070db..8ea77cd 100644
--- a/inc/rest/routes/QueueRoutes.php
+++ b/inc/rest/routes/QueueRoutes.php
@@ -1,7 +1,9 @@
 <?php
 namespace JVBase\rest\routes;
 
+use Exception;
 use JVBase\JVB;
+use JVBase\managers\CacheManager;
 use JVBase\rest\RestRouteManager;
 use WP_REST_Request;
 use WP_REST_Response;
@@ -92,20 +94,13 @@
 		$ids = $request->get_param('ids');
 		$limit = intval($request->get_param('limit'));
 
-		// User-specific caching (keep this)
-		$user_queue_timestamp = $this->getUserQueueTimestamp($user_id);
-
-		$if_modified_since = $request->get_header('If-Modified-Since');
-		if ($if_modified_since) {
-			$if_modified_timestamp = strtotime($if_modified_since);
-			if ($user_queue_timestamp <= $if_modified_timestamp) {
-				return new WP_REST_Response(null, 304);
-			}
+		// Use base class user-specific header checking
+		// This checks both 'queue' and 'user_{$user_id}' timestamps
+		$cache_check = $this->checkUserHeaders($request, $user_id, 'queue');
+		if ($cache_check) {
+			return $cache_check; // Returns 304 Not Modified
 		}
 
-		header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $user_queue_timestamp) . ' GMT');
-		header('Cache-Control: private, max-age=30');
-
 		global $wpdb;
 		$table = $wpdb->prefix . $this->table;
 
@@ -135,19 +130,22 @@
 
 		$operations = $wpdb->get_results($wpdb->prepare($sql, $params), ARRAY_A);
 
-		// Format operations with improved data structure
+		// Format operations
 		foreach ($operations as &$op) {
 			$op = $this->formatOperation($op);
 		}
 
-		return new WP_REST_Response([
+		$response = new WP_REST_Response([
 			'items' => $operations,
 			'total' => count($operations),
-			'timestamp' => date('c'), // ISO format
+			'timestamp' => date('c'),
 			'has_more' => count($operations) === $limit,
 			'queue_stats' => $this->getQueueStats($user_id),
-			'server_time' => date('c') // Helpful for frontend time sync
+			'server_time' => date('c')
 		]);
+
+		// Add cache headers (ETag, Last-Modified)
+		return $this->addCacheHeaders($response);
 	}
 
 
@@ -195,7 +193,8 @@
 			'progress_count' => intval($operation['progress_count'] ?? 0),
 			'count' => intval($operation['count'] ?? 1),
 			'retries' => intval($operation['retries'] ?? 0),
-			'data' => json_decode($operation['request_data'] ?? '{}', true)
+			'data' => json_decode($operation['request_data'] ?? '{}', true),
+			'result'	=> json_decode($operation['result']??'{}', true)
 		];
 
 		// Convert timestamps to ISO 8601 format with proper timezone
@@ -230,38 +229,6 @@
 	}
 
 	/**
-	 * Update user's queue timestamp when any operation changes
-	 * This should be called whenever an operation status changes
-	 */
-	public function updateUserQueueTimestamp(int $user_id): void
-	{
-		$key = "{$user_id}_queue_timestamp";
-		$this->cache->set($key, time());
-	}
-
-	/**
-	 * Convert MySQL datetime to ISO 8601 timestamp with proper timezone
-	 */
-	protected function formatTimestamp(?string $mysql_datetime): ?string
-	{
-		if (empty($mysql_datetime)) {
-			return null;
-		}
-
-		try {
-			// Create DateTime object from MySQL datetime (assuming UTC storage)
-			$date = new DateTime($mysql_datetime, new DateTimeZone('UTC'));
-
-			// Return ISO 8601 format with UTC timezone indicator
-			return $date->format('c'); // e.g., "2025-07-23T22:57:35+00:00"
-
-		} catch (Exception $e) {
-			// Fallback: return null if datetime is invalid
-			return null;
-		}
-	}
-
-	/**
 	 * Get human-readable operation title
 	 */
 	protected function getOperationTitle(string $type, array $data): string
@@ -292,24 +259,6 @@
 		return $base_title;
 	}
 
-	/**
-	 * Get user's queue last update timestamp from cache
-	 */
-	protected function getUserQueueTimestamp(int $user_id): int
-	{
-		$key = "{$user_id}_queue_timestamp";
-
-		// Use CacheManager for consistency
-		$timestamp = $this->cache->get($key);
-
-		if ($timestamp === false) {
-			$timestamp = time();
-			$this->cache->set($key, $timestamp);
-		}
-
-		return $timestamp;
-	}
-
     /**
      * Update operation status (dismiss or retry)
      *
@@ -321,7 +270,9 @@
 		$data = $request->get_json_params();
 		$ids = $data['ids'] ?? [];
 		$action = $data['action'] ?? '';
-		$user_id = get_current_user_id();
+
+		$user_id = (int)$data['user'];
+
 
 		// Validate input
 		if (empty($ids) || !is_array($ids)) {
@@ -362,19 +313,13 @@
 		$result = $this->processQueueAction($action, $valid_operations, $user_id);
 
 		if ($result['success']) {
-			$this->invalidateUserCache($user_id);
+			// Update timestamp for this user's queue
+			CacheManager::updateTimestamp("user_{$user_id}");
 		}
 
 		return new WP_REST_Response($result);
 	}
 
-	protected function invalidateUserCache(int $user_id): void
-	{
-		$key = "{$user_id}_queue_timestamp";
-		$this->cache->invalidate($key);
-		$this->cache->set($key, time());
-	}
-
 	protected function processQueueAction(string $action, array $operations, int $user_id): array
 	{
 		global $wpdb;

--
Gitblit v1.10.0