Jake Vanderwerf
2026-02-17 a24a06002081ad71a78ffeff9072725ba39cf121
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);