Jake Vanderwerf
2026-08-28 5b50afdcafd150186ea5c7b0e1cad98065590b35
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
@@ -174,7 +181,7 @@
      unset($data['id']);
      error_log('[CONTENT]:'.print_r($data, true));
      $queue = JVB()->queue();
      $queue = Queue::getInstance();
      $queue->queueOperation(
         'content_update',
         $user_id,
@@ -270,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;
      }
@@ -299,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
   {
@@ -335,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
@@ -382,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
@@ -395,7 +399,7 @@
      // Search term is already in $args['s'] from earlier
      // Get all taxonomies registered to this post type
      $taxonomies = get_object_taxonomies($this->post_type, 'names');
      $taxonomies = get_object_taxonomies($this->post_type);
      if (empty($taxonomies)) {
         return $args;
@@ -510,8 +514,9 @@
   }
   /**
    * @param WP_Post $post the post object
    *
    * @param WP_Post $post
    * @param bool $skip
    * @param bool $fields
    * @return array
    */
   protected function preparePost(WP_Post $post, bool $skip = false, bool $fields = true): array
@@ -551,8 +556,8 @@
   }
   /**
    * @param WP_Term $post the post object
    *
    * @param WP_Term $post
    * @param bool $fields
    * @return array
    */
   protected function prepareTerm(WP_Term $post, bool $fields = true): array