tfrere commited on
Commit
c36214e
Β·
1 Parent(s): dc01b2f

remove client side result cache to fix local storage size limitation

Browse files
frontend/src/pages/LeaderboardPage/components/Leaderboard/hooks/useLeaderboardData.js CHANGED
@@ -4,9 +4,6 @@ import { useSearchParams } from "react-router-dom";
4
  import { useLeaderboard } from "../context/LeaderboardContext";
5
  import { useDataProcessing } from "../components/Table/hooks/useDataProcessing";
6
 
7
- const CACHE_KEY = "leaderboardData";
8
- const CACHE_DURATION = 5 * 60 * 1000; // 5 minutes
9
-
10
  export const useLeaderboardData = () => {
11
  const queryClient = useQueryClient();
12
  const [searchParams] = useSearchParams();
@@ -15,44 +12,41 @@ export const useLeaderboardData = () => {
15
  const { data, isLoading, error } = useQuery({
16
  queryKey: ["leaderboard"],
17
  queryFn: async () => {
 
18
  try {
19
- const cachedData = localStorage.getItem(CACHE_KEY);
20
- if (cachedData) {
21
- const { data: cached, timestamp } = JSON.parse(cachedData);
22
- const age = Date.now() - timestamp;
23
- if (age < CACHE_DURATION) {
24
- return cached;
25
- }
26
- }
27
-
28
  const response = await fetch("/api/leaderboard/formatted");
 
 
29
  if (!response.ok) {
 
 
 
 
 
 
30
  throw new Error(`HTTP error! status: ${response.status}`);
31
  }
32
 
33
  const newData = await response.json();
34
- localStorage.setItem(
35
- CACHE_KEY,
36
- JSON.stringify({
37
- data: newData,
38
- timestamp: Date.now(),
39
- })
40
- );
41
-
42
  return newData;
43
  } catch (error) {
44
- console.error("Detailed error:", error);
 
 
 
 
45
  throw error;
46
  }
47
  },
48
- staleTime: CACHE_DURATION,
49
- cacheTime: CACHE_DURATION * 2,
50
  refetchOnWindowFocus: false,
51
  enabled: isInitialLoadRef.current || !!searchParams.toString(),
52
  });
53
 
54
  useMemo(() => {
55
  if (data && isInitialLoadRef.current) {
 
56
  isInitialLoadRef.current = false;
57
  }
58
  }, [data]);
 
4
  import { useLeaderboard } from "../context/LeaderboardContext";
5
  import { useDataProcessing } from "../components/Table/hooks/useDataProcessing";
6
 
 
 
 
7
  export const useLeaderboardData = () => {
8
  const queryClient = useQueryClient();
9
  const [searchParams] = useSearchParams();
 
12
  const { data, isLoading, error } = useQuery({
13
  queryKey: ["leaderboard"],
14
  queryFn: async () => {
15
+ console.log("πŸ”„ Starting API fetch attempt...");
16
  try {
17
+ console.log("🌐 Fetching from API...");
 
 
 
 
 
 
 
 
18
  const response = await fetch("/api/leaderboard/formatted");
19
+ console.log("πŸ“‘ API Response status:", response.status);
20
+
21
  if (!response.ok) {
22
+ const errorText = await response.text();
23
+ console.error("🚨 API Error:", {
24
+ status: response.status,
25
+ statusText: response.statusText,
26
+ body: errorText,
27
+ });
28
  throw new Error(`HTTP error! status: ${response.status}`);
29
  }
30
 
31
  const newData = await response.json();
32
+ console.log("πŸ“₯ Received data size:", JSON.stringify(newData).length);
 
 
 
 
 
 
 
33
  return newData;
34
  } catch (error) {
35
+ console.error("πŸ”₯ Detailed error:", {
36
+ name: error.name,
37
+ message: error.message,
38
+ stack: error.stack,
39
+ });
40
  throw error;
41
  }
42
  },
 
 
43
  refetchOnWindowFocus: false,
44
  enabled: isInitialLoadRef.current || !!searchParams.toString(),
45
  });
46
 
47
  useMemo(() => {
48
  if (data && isInitialLoadRef.current) {
49
+ console.log("🎯 Initial load complete");
50
  isInitialLoadRef.current = false;
51
  }
52
  }, [data]);