From f8ff91fd274911cd8f3e2cac70e2cfc2a0d05b37 Mon Sep 17 00:00:00 2001 From: Yee Kit Date: Mon, 20 May 2024 20:44:08 +0800 Subject: [PATCH] =?UTF-8?q?V.0.3.1.6=20=F0=9F=8C=B6=EF=B8=8F=20Hotfixes=20?= =?UTF-8?q?(#35)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fixed filtering only returning 1 row * Hotfix: Revalidate cache after 10s Added cache revalidation after 10s to fix data being cached permanently --- frontend/app/api/admin/collections-requests/route.ts | 7 ++++--- frontend/app/api/admin/collections/route.ts | 2 +- frontend/app/api/admin/users/route.ts | 2 +- frontend/app/api/public/collections/route.ts | 2 +- frontend/app/api/user/collections-requests/route.ts | 2 +- frontend/app/api/user/collections/route.ts | 2 +- .../app/components/ui/admin/admin-manage-collections.tsx | 1 - frontend/app/components/ui/admin/admin-manage-requests.tsx | 3 ++- frontend/app/components/ui/admin/admin-manage-users.tsx | 3 ++- frontend/app/components/ui/chat/chat-selection.tsx | 1 - frontend/app/components/ui/query/query-manage.tsx | 5 ----- frontend/app/components/ui/query/query-selection.tsx | 1 - frontend/app/components/ui/search/search-selection.tsx | 1 - 13 files changed, 13 insertions(+), 19 deletions(-) diff --git a/frontend/app/api/admin/collections-requests/route.ts b/frontend/app/api/admin/collections-requests/route.ts index 72aedbb..88cc2e4 100644 --- a/frontend/app/api/admin/collections-requests/route.ts +++ b/frontend/app/api/admin/collections-requests/route.ts @@ -1,4 +1,4 @@ -export const dynamic = 'force-dynamic'; +export const revalidate = 10; import { createClient } from '@supabase/supabase-js'; import { NextRequest, NextResponse } from "next/server"; @@ -34,14 +34,15 @@ export async function GET(request: NextRequest) { ) ) `) - .eq('is_pending', true); + .eq('is_pending', true) + .limit(1000); if (collErr) { console.error('Error fetching collection request data from database:', collErr.message); return NextResponse.json({ error: collErr.message }, { status: 500 }); } - // console.log('Collections Request:', collectionsReq); + // console.log('New Collections Request:', collectionsReq); return NextResponse.json({ collectionsReq: collectionsReq }); } diff --git a/frontend/app/api/admin/collections/route.ts b/frontend/app/api/admin/collections/route.ts index 4077210..332dccc 100644 --- a/frontend/app/api/admin/collections/route.ts +++ b/frontend/app/api/admin/collections/route.ts @@ -1,4 +1,4 @@ -export const dynamic = 'force-dynamic'; +export const revalidate = 10; import { createClient } from '@supabase/supabase-js'; import { NextRequest, NextResponse } from "next/server"; diff --git a/frontend/app/api/admin/users/route.ts b/frontend/app/api/admin/users/route.ts index af4f242..4b0ce7f 100644 --- a/frontend/app/api/admin/users/route.ts +++ b/frontend/app/api/admin/users/route.ts @@ -1,4 +1,4 @@ -export const dynamic = 'force-dynamic'; +export const revalidate = 10; import { createClient } from '@supabase/supabase-js'; import { NextRequest, NextResponse } from "next/server"; diff --git a/frontend/app/api/public/collections/route.ts b/frontend/app/api/public/collections/route.ts index c45a7d9..cbcf7aa 100644 --- a/frontend/app/api/public/collections/route.ts +++ b/frontend/app/api/public/collections/route.ts @@ -1,4 +1,4 @@ -export const dynamic = 'force-dynamic'; +export const revalidate = 10; import { createClient } from '@supabase/supabase-js'; import { NextRequest, NextResponse } from "next/server"; diff --git a/frontend/app/api/user/collections-requests/route.ts b/frontend/app/api/user/collections-requests/route.ts index 9f9d92f..44d26be 100644 --- a/frontend/app/api/user/collections-requests/route.ts +++ b/frontend/app/api/user/collections-requests/route.ts @@ -1,4 +1,4 @@ -export const dynamic = 'force-dynamic'; +export const revalidate = 10; import { createClient } from '@supabase/supabase-js'; import { NextRequest, NextResponse } from "next/server"; diff --git a/frontend/app/api/user/collections/route.ts b/frontend/app/api/user/collections/route.ts index 09dca4b..87b9420 100644 --- a/frontend/app/api/user/collections/route.ts +++ b/frontend/app/api/user/collections/route.ts @@ -1,4 +1,4 @@ -export const dynamic = 'force-dynamic'; +export const revalidate = 10; import { createClient } from '@supabase/supabase-js'; import { NextRequest, NextResponse } from "next/server"; diff --git a/frontend/app/components/ui/admin/admin-manage-collections.tsx b/frontend/app/components/ui/admin/admin-manage-collections.tsx index d2ddb33..814bff6 100644 --- a/frontend/app/components/ui/admin/admin-manage-collections.tsx +++ b/frontend/app/components/ui/admin/admin-manage-collections.tsx @@ -20,7 +20,6 @@ export default function AdminManageCollections() { method: 'GET', headers: { 'Content-Type': 'application/json', - 'Cache-Control': 'no-cache', // Disable cache to get the latest data }, } ); diff --git a/frontend/app/components/ui/admin/admin-manage-requests.tsx b/frontend/app/components/ui/admin/admin-manage-requests.tsx index a73799a..4e17629 100644 --- a/frontend/app/components/ui/admin/admin-manage-requests.tsx +++ b/frontend/app/components/ui/admin/admin-manage-requests.tsx @@ -1,5 +1,6 @@ "use client"; +import { unstable_noStore as noStore } from 'next/cache'; import { useEffect, useState } from 'react'; import { Eye, EyeOff, X, Check, RefreshCw } from 'lucide-react'; import { IconSpinner } from '@/app/components/ui/icons'; @@ -7,6 +8,7 @@ import { toast } from 'react-toastify'; import Swal from 'sweetalert2'; export default function AdminManageRequests() { + noStore(); const [userRequests, setUserRequests] = useState([]); const [loading, setLoading] = useState(true); const [isRefreshed, setIsRefreshed] = useState(true); // Track whether the data has been refreshed @@ -20,7 +22,6 @@ export default function AdminManageRequests() { method: 'GET', headers: { 'Content-Type': 'application/json', - 'Cache-Control': 'no-cache', // Disable cache to get the latest data }, } ); diff --git a/frontend/app/components/ui/admin/admin-manage-users.tsx b/frontend/app/components/ui/admin/admin-manage-users.tsx index 51c9584..e799971 100644 --- a/frontend/app/components/ui/admin/admin-manage-users.tsx +++ b/frontend/app/components/ui/admin/admin-manage-users.tsx @@ -1,5 +1,6 @@ "use client"; +import { unstable_noStore as noStore } from 'next/cache'; import { useEffect, useState } from "react"; import { toast } from "react-toastify"; import { RefreshCw, UserCheck, UserX } from "lucide-react"; @@ -7,6 +8,7 @@ import { IconSpinner } from "@/app/components/ui/icons"; import Swal from "sweetalert2"; export default function AdminManageUsers() { + noStore(); const [users, setUsers] = useState([]); const [loading, setLoading] = useState(true); const [isRefreshed, setIsRefreshed] = useState(true); // Track whether the data has been refreshed @@ -20,7 +22,6 @@ export default function AdminManageUsers() { method: 'GET', headers: { 'Content-Type': 'application/json', - 'Cache-Control': 'no-cache', // Disable cache to get the latest data }, } ); diff --git a/frontend/app/components/ui/chat/chat-selection.tsx b/frontend/app/components/ui/chat/chat-selection.tsx index eee9cbe..1590599 100644 --- a/frontend/app/components/ui/chat/chat-selection.tsx +++ b/frontend/app/components/ui/chat/chat-selection.tsx @@ -23,7 +23,6 @@ export default function ChatSelection( method: 'GET', headers: { 'Content-Type': 'application/json', - 'Cache-Control': 'no-cache', // Disable caching }, }); diff --git a/frontend/app/components/ui/query/query-manage.tsx b/frontend/app/components/ui/query/query-manage.tsx index 0210bb3..b105932 100644 --- a/frontend/app/components/ui/query/query-manage.tsx +++ b/frontend/app/components/ui/query/query-manage.tsx @@ -24,7 +24,6 @@ export default function QueryCollectionManage() { method: 'GET', headers: { 'Content-Type': 'application/json', - 'Cache-Control': 'no-cache', // Disable caching }, } ) @@ -125,7 +124,6 @@ export default function QueryCollectionManage() { method: 'PUT', headers: { 'Content-Type': 'application/json', - 'Cache-Control': 'no-cache', // Disable caching }, body: JSON.stringify({ collection_id: collectionId, is_make_public: isPublic }), } @@ -177,7 +175,6 @@ export default function QueryCollectionManage() { method: 'POST', headers: { 'Content-Type': 'application/json', - 'Cache-Control': 'no-cache', // Disable caching }, body: JSON.stringify({ collection_id: collectionId, is_make_public: isPublic }), } @@ -246,7 +243,6 @@ export default function QueryCollectionManage() { method: 'DELETE', headers: { 'Content-Type': 'application/json', - 'Cache-Control': 'no-cache', // Disable caching }, body: JSON.stringify({ collection_id: collectionId }), } @@ -314,7 +310,6 @@ export default function QueryCollectionManage() { method: 'DELETE', headers: { 'Content-Type': 'application/json', - 'Cache-Control': 'no-cache', // Disable caching 'Authorization': `Bearer ${supabaseAccessToken}`, // Add the access token to the request headers }, body: JSON.stringify({ collection_id: collectionId }), diff --git a/frontend/app/components/ui/query/query-selection.tsx b/frontend/app/components/ui/query/query-selection.tsx index 6a93927..f609e42 100644 --- a/frontend/app/components/ui/query/query-selection.tsx +++ b/frontend/app/components/ui/query/query-selection.tsx @@ -22,7 +22,6 @@ export default function QuerySelection( method: 'GET', headers: { 'Content-Type': 'application/json', - 'Cache-Control': 'no-cache', // Disable caching }, }); diff --git a/frontend/app/components/ui/search/search-selection.tsx b/frontend/app/components/ui/search/search-selection.tsx index 4fd62f1..8dee28b 100644 --- a/frontend/app/components/ui/search/search-selection.tsx +++ b/frontend/app/components/ui/search/search-selection.tsx @@ -23,7 +23,6 @@ export default function SearchSelection( method: 'GET', headers: { 'Content-Type': 'application/json', - 'Cache-Control': 'no-cache', // Disable caching }, });