From 3d11577eed8bd6001d9e923f8a8e0f07f8b28011 Mon Sep 17 00:00:00 2001 From: Floorb <132411956+Neetpone@users.noreply.github.com> Date: Mon, 18 Apr 2022 13:34:00 -0400 Subject: [PATCH] Try to fix password field, cache ajax_pastes output for awhile. --- api/ajax_pastes.php | 12 +++++++++++- index.php | 2 ++ theme/bulma/main.php | 2 +- theme/bulma/view.php | 2 +- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/api/ajax_pastes.php b/api/ajax_pastes.php index db81e0d..02912ba 100644 --- a/api/ajax_pastes.php +++ b/api/ajax_pastes.php @@ -4,6 +4,12 @@ require_once('../includes/common.php'); use PonePaste\Models\Paste; +if (empty($_GET['q']) && $redis->exists('ajax_pastes')) { + header('Content-Type: application/json; charset=UTF-8'); + echo $redis->get('ajax_pastes'); + die; +} + $pastes = Paste::with([ 'user' => function($query) { $query->select('users.id', 'username'); @@ -24,7 +30,7 @@ $pastes = $pastes->get(); header('Content-Type: application/json; charset=UTF-8'); -echo json_encode(['data' => $pastes->map(function($paste) { +$pastes_json = json_encode(['data' => $pastes->map(function($paste) { return [ 'id' => $paste->id, 'title' => $paste->title, @@ -34,3 +40,7 @@ echo json_encode(['data' => $pastes->map(function($paste) { }) ]; })]); + +$redis->setEx('ajax_pastes', 3600, $pastes_json); + +echo $pastes_json; diff --git a/index.php b/index.php index ae619a7..a1ae1ea 100644 --- a/index.php +++ b/index.php @@ -140,6 +140,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { ]); $paste->replaceTags(Tag::parseTagInput($tag_input)); + $redis->del('ajax_pastes'); /* Expire from Redis so the edited paste shows up */ } else { $error = 'You must be logged in to do that.'; } @@ -167,6 +168,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { if ($p_visible == '0') { addToSitemap($paste, $priority, $changefreq); } + $redis->del('ajax_pastes'); /* Expire from Redis so the new paste shows up */ } // Redirect to paste on successful entry, or on successful edit redirect back to edited paste diff --git a/theme/bulma/main.php b/theme/bulma/main.php index 30be30b..dae9cc0 100644 --- a/theme/bulma/main.php +++ b/theme/bulma/main.php @@ -269,7 +269,7 @@