Jake Vanderwerf
2026-08-26 ccf5e61a075c35d24befc175994b5cb8957ca322
inc/rest/routes/ContentRoutes.php
@@ -2,7 +2,10 @@
namespace JVBase\rest\routes;
use JVBase\Instance;
use JVBase\managers\Cache;
use JVBase\managers\queue\executors\ContentExecutor;
use JVBase\managers\queue\Queue;
use JVBase\managers\queue\TypeConfig;
use JVBase\meta\Meta;
use JVBase\registrar\Registrar;
@@ -23,6 +26,7 @@
class ContentRoutes extends Rest
{
   use Instance;
   protected array $fields = [];
   protected array $taxonomies = [];
   protected string $post_type = '';
@@ -33,16 +37,19 @@
   protected array $timelineUniqueFields = [];
   protected static ?string $action = 'dash-';
   protected Meta $meta;
   protected Cache $termCache;
   public function __construct()
   {
      $this->cacheName = 'user_content_' . get_current_user_id();
      $this->cacheName = 'user_content';
      parent::__construct();
      if (JVB_TESTING) {
         $this->cache->flush();
      }
      $this->cache->connect('post', true);
      $this->cache->connect('term', true);
      $this->cache = Cache::for($this->cacheName, 'post', DAY_IN_SECONDS);
      $this->cache->user();
      $this->termCache = Cache::for($this->cacheName.'_terms', 'term', DAY_IN_SECONDS);
      $this->termCache->user();
      add_action('init', [$this, 'registerContentExecutors'], 5);
   }
@@ -51,7 +58,7 @@
    */
   public function registerContentExecutors(): void
   {
      $registry = JVB()->queue()->registry();
      $registry = Queue::getInstance()->registry();
      $executor = new ContentExecutor();
      // Content updates - chunked at 10 posts
@@ -88,12 +95,11 @@
            'dateFrom' => 'string',
            'dateTo' => 'string',
         ])
         ->rateLimit(20)
         ->rateLimit(30)
         ->post([$this, 'postContent'])
         ->auth(PermissionHandler::combine(['user', 'nonce', ['actionNonce'=>'dash-']]))
         ->rateLimit(30)
         ->rateLimit()
         ->args([
            'user'   => 'int|required',
            'posts' => 'required',
            'content' => 'string',
         ])
@@ -163,7 +169,7 @@
   public function postContent(WP_REST_Request $request): WP_REST_Response
   {
      $data = $request->get_params();
      $user_id = $data['user'];
      $user_id = get_current_user_id();
      if (!array_key_exists('posts', $data) || !is_array($data['posts'])) {
         return Response::success(['message'=>'No posts found in request']);
@@ -172,11 +178,10 @@
      $count = count($data['posts']);
      $operationId = $data['id'];
      unset($data['user']);
      unset($data['id']);
      error_log('[CONTENT]:'.print_r($data, true));
      $queue = JVB()->queue();
      $queue = Queue::getInstance();
      $queue->queueOperation(
         'content_update',
         $user_id,
@@ -272,8 +277,8 @@
         $args['s'] = sanitize_text_field($params['search']);
      }
      $key = $this->cache->generateKey($args);
      $cached = $this->checkCache($key, $request);
      $cached = $this->cache->get($args);
      if ($cached) {
         return $cached;
      }
@@ -301,10 +306,9 @@
      ];
      $this->cache->set($key, $data);
      $this->cache->set($args, $data);
      $response = Response::success($data);
      return $this->addCacheHeaders($response);
      return Response::success($data);
   }
   public function getTerms(WP_REST_Request $request, array $params, Registrar $registrar):WP_REST_Response
   {
@@ -337,17 +341,16 @@
         $args['s'] = sanitize_text_field($params['search']);
      }
      $key = $this->cache->generateKey($args);
      // Check HTTP cache headers with the specific content type
      $cache_check = $this->checkHeaders($request, $key);
      if ($cache_check) {
         return $cache_check;
      }
      $cache = $this->cache->get($key);
      // Check HTTP cache headers with the specific content type
//    $cache_check = $this->checkHeaders($request, $key);
//    if ($cache_check) {
//       return $cache_check;
//    }
      $cache = $this->cache->get($args);
      if ($cache) {
         $response = Response::success($cache);
         return $this->addCacheHeaders($response);
         return Response::success($cache);
      }
      $this->post_type = jvbCheckBase($params['content'] ?? $params['type']);
      // Only expand search to taxonomies if we're actually going to query
@@ -384,10 +387,9 @@
      $this->taxonomies = [];
      $data['items'] =array_map([$this, 'prepareTerm'], $terms);
      $this->cache->set($key, $data);
      $this->cache->set($args, $data);
      $response = Response::success($data);
      return $this->addCacheHeaders($response);
      return Response::success($data);
   }
   protected function applySearchFilters(array $args, array $params): array