From 42fa8304ddb811b0f725f245130f70c0f5e86a6c Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Tue, 04 Nov 2025 06:12:02 +0000
Subject: [PATCH] =Refactored LoginManager to be more extensible and configurable, as well as an AjaxRateLimiter
---
inc/rest/routes/NotificationsRoutes.php | 28 +++++++++++++++++-----------
1 files changed, 17 insertions(+), 11 deletions(-)
diff --git a/inc/rest/routes/NotificationsRoutes.php b/inc/rest/routes/NotificationsRoutes.php
index cbf36fc..ea6fa2c 100644
--- a/inc/rest/routes/NotificationsRoutes.php
+++ b/inc/rest/routes/NotificationsRoutes.php
@@ -379,15 +379,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 +404,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 {
@@ -444,7 +449,8 @@
// 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,
--
Gitblit v1.10.0