From 58e8ae0759ccfa97c478ccae4e0778bdce70966f Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Thu, 22 Jan 2026 22:40:02 +0000
Subject: [PATCH] =DirectoryManager.php updates, some javascript tweaks for CRUD.js, and minor style changes
---
inc/rest/routes/NotificationsRoutes.php | 53 +++++++++++++++++++++++++++++------------------------
1 files changed, 29 insertions(+), 24 deletions(-)
diff --git a/inc/rest/routes/NotificationsRoutes.php b/inc/rest/routes/NotificationsRoutes.php
index cbf36fc..eb39e8b 100644
--- a/inc/rest/routes/NotificationsRoutes.php
+++ b/inc/rest/routes/NotificationsRoutes.php
@@ -198,7 +198,6 @@
*/
protected function getItemLink(int $ID, string $content):string
{
- error_log('Type: '.print_r($content, true));
switch ($content) {
case BASE.'artist':
case BASE.'artwork':
@@ -379,15 +378,19 @@
{
$data = $request->get_params();
$user_id = $data['user'];
- if (!$this->userCheck($user_id)) {
- $this->logError("Invalid user ID for notifications", [
- 'user' => $user_id
- ], 'warning');
- return new WP_REST_Response([
- 'success' => false,
- 'message' => 'User doesn\'t match. Are you a bot?'
- ]);
- }
+ if (!$this->userCheck($user_id)) {
+ $this->logError("Invalid user ID for notifications", ['user' => $user_id], 'warning');
+ return new WP_REST_Response([
+ 'success' => false,
+ 'message' => 'User doesn\'t match. Are you a bot?'
+ ]);
+ }
+
+ // Check HTTP cache headers (includes notification types in timestamp check)
+ $cache_check = $this->checkUserHeaders($request, $user_id, 'notifications');
+ if ($cache_check) {
+ return $cache_check;
+ }
// Step 1: Build status/order/filter params
$params = $this->getSanitizedData($user_id, $data);
@@ -400,7 +403,8 @@
$cache_key = "user_{$user_id}_merged_notifications_{$status}_{$type}_{$limit}_{$offset}";
$cached = $this->cache->get($cache_key);
if ($cached) {
- return new WP_REST_Response($cached);
+ $response = new WP_REST_Response($cached);
+ return $this->addCacheHeaders($response);
}
try {
@@ -437,14 +441,15 @@
'total' => $total_count,
'page' => $offset,
'per_page' => $limit,
- 'pages' => ceil($total_count / $limit),
- 'has_more' => ($offset * $limit + count($notifications)) < $total_count
- ]
+ 'pages' => ceil($total_count / $limit)
+ ],
+ 'has_more' => ($offset * $limit + count($notifications)) < $total_count
];
// Cache the result
$this->cache->set($cache_key, $response, 'notifications_' . $user_id);
- return new WP_REST_Response($response);
+ $response = new WP_REST_Response($response);
+ return $this->addCacheHeaders($response);
} catch (Exception $e) {
$this->logError("Error retrieving notifications", [
'user_id' => $user_id,
@@ -457,9 +462,9 @@
'total' => 0,
'page' => $offset,
'per_page' => $limit,
- 'pages' => 0,
- 'has_more' => false
- ]
+ 'pages' => 0
+ ],
+ 'has_more' => false
]);
}
}
@@ -830,9 +835,9 @@
'total' => (int)$total_count,
'page' => $offset,
'per_page' => $limit,
- 'pages' => ceil($total_count / $limit),
- 'has_more' => ($offset + $limit) < $total_count
- ]
+ 'pages' => ceil($total_count / $limit)
+ ],
+ 'has_more' => ($offset + $limit) < $total_count
];
// Cache the results
@@ -852,9 +857,9 @@
'total' => 0,
'page' => $offset,
'per_page' => $limit,
- 'pages' => 0,
- 'has_more' => false
- ]
+ 'pages' => 0
+ ],
+ 'has_more' => false
];
}
}
--
Gitblit v1.10.0