feat: 添加 认证检查 和 首页渲染 的性能标记
This commit is contained in:
@@ -2,8 +2,9 @@
|
||||
import React, { createContext, useContext, useState, useEffect } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { useToast } from '@chakra-ui/react';
|
||||
import { logger } from '../utils/logger';
|
||||
import { useNotification } from '../contexts/NotificationContext';
|
||||
import { logger } from '@utils/logger';
|
||||
import { performanceMonitor } from '@utils/performanceMonitor';
|
||||
import { useNotification } from '@contexts/NotificationContext';
|
||||
import { identifyUser, resetUser, trackEvent } from '@lib/posthog';
|
||||
import { SPECIAL_EVENTS } from '@lib/constants';
|
||||
|
||||
@@ -37,6 +38,9 @@ export const AuthProvider = ({ children }) => {
|
||||
|
||||
// 检查Session状态
|
||||
const checkSession = async () => {
|
||||
// ⚡ 性能标记:认证检查开始
|
||||
performanceMonitor.mark('auth-check-start');
|
||||
|
||||
// 节流检查
|
||||
const now = Date.now();
|
||||
const timeSinceLastCheck = now - lastCheckTimeRef.current;
|
||||
@@ -47,6 +51,8 @@ export const AuthProvider = ({ children }) => {
|
||||
minInterval: `${MIN_CHECK_INTERVAL}ms`,
|
||||
reason: '距离上次请求间隔太短'
|
||||
});
|
||||
// ⚡ 性能标记:认证检查结束(节流情况)
|
||||
performanceMonitor.mark('auth-check-end');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -125,6 +131,8 @@ export const AuthProvider = ({ children }) => {
|
||||
setUser((prev) => prev === null ? prev : null);
|
||||
setIsAuthenticated((prev) => prev === false ? prev : false);
|
||||
} finally {
|
||||
// ⚡ 性能标记:认证检查结束
|
||||
performanceMonitor.mark('auth-check-end');
|
||||
// ⚡ 只在 isLoading 为 true 时才设置为 false,避免不必要的状态更新
|
||||
setIsLoading((prev) => prev === false ? prev : false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user