From dc0e4c1bbb80dba702fe0e281d919b65f30ca39d Mon Sep 17 00:00:00 2001 From: Kavin <20838718+FireMasterK@users.noreply.github.com> Date: Thu, 7 Apr 2022 02:42:48 +0100 Subject: [PATCH] Cache based on playlistId length. --- src/main/java/me/kavin/piped/ServerLauncher.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/me/kavin/piped/ServerLauncher.java b/src/main/java/me/kavin/piped/ServerLauncher.java index 40af327..45f6ea4 100644 --- a/src/main/java/me/kavin/piped/ServerLauncher.java +++ b/src/main/java/me/kavin/piped/ServerLauncher.java @@ -17,6 +17,7 @@ import me.kavin.piped.utils.*; import me.kavin.piped.utils.resp.ErrorResponse; import me.kavin.piped.utils.resp.LoginRequest; import me.kavin.piped.utils.resp.SubscriptionUpdateRequest; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.exception.ExceptionUtils; import org.hibernate.Session; import org.jetbrains.annotations.NotNull; @@ -129,8 +130,10 @@ public class ServerLauncher extends MultithreadedHttpServerLauncher { } })).map(GET, "/playlists/:playlistId", AsyncServlet.ofBlocking(executor, request -> { try { - return getJsonResponse(ResponseHelper.playlistResponse(request.getPathParameter("playlistId")), - "public, max-age=600", true); + var playlistId = request.getPathParameter("playlistId"); + var cache = StringUtils.isBlank(playlistId) || playlistId.length() != 36 ? + "public, max-age=600" : "private"; + return getJsonResponse(ResponseHelper.playlistResponse(playlistId), cache, true); } catch (Exception e) { return getErrorResponse(e, request.getPath()); }