Jake Vanderwerf
2026-08-25 3d25ad7de4fdbb3eba2cde2a62422e6be5d79a0a
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,21 @@
   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();
      $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();
      if (JVB_TESTING) {
         $this->cache->flush();
      }
      $this->cache->connect('post', true);
      $this->cache->connect('term', true);
      add_action('init', [$this, 'registerContentExecutors'], 5);
   }
@@ -51,7 +60,7 @@
    */
   public function registerContentExecutors(): void
   {
      $registry = JVB()->queue()->registry();
      $registry = Queue::getInstance()->registry();
      $executor = new ContentExecutor();
      // Content updates - chunked at 10 posts
@@ -88,12 +97,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 +171,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 +180,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,
@@ -273,7 +280,7 @@
      }
      $key = $this->cache->generateKey($args);
      $cached = $this->checkCache($key, $request);
      $cached = $this->cache->get($key);
      if ($cached) {
         return $cached;
      }
@@ -303,8 +310,7 @@
      $this->cache->set($key, $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
   {
@@ -339,15 +345,14 @@
      $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_check = $this->checkHeaders($request, $key);
//    if ($cache_check) {
//       return $cache_check;
//    }
      $cache = $this->cache->get($key);
      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
@@ -386,8 +391,7 @@
      $this->cache->set($key, $data);
      $response = Response::success($data);
      return $this->addCacheHeaders($response);
      return Response::success($data);
   }
   protected function applySearchFilters(array $args, array $params): array
@@ -598,7 +602,7 @@
      $item['fields'] = $mainMeta->getAll($this->timelineSharedFields);
      //Step 2: Get the fields for each individual posts
      $children = get_children(['post_parent' => $post->ID, 'orderby' => 'date', 'order' => 'ASC', 'post_status' => ['publish', 'draft'], 'fields' => 'ids']);
      $children = jvbTimelinePoints($post->ID, $post->post_type,['publish', 'draft']);
      array_unshift($children, $post->ID);
      $subFields = [];