perf(app): 添加登录状态检查并优化性能

- 在多个页面添加 isLoggedIn 检查,防止未登录时进行不必要的数据获取
- 使用 React.memo 和 useMemo 优化个人页面徽章渲染性能
- 为 badges API 添加节流机制,避免频繁请求
- 优化图片缓存策略和字符串处理
- 移除调试日志并改进推送通知的认证检查
This commit is contained in:
richarjiang
2025-11-25 15:35:30 +08:00
parent 6f2b7eb45e
commit 3ad0e08d58
9 changed files with 138 additions and 67 deletions

View File

@@ -48,7 +48,7 @@ export default function MedicationsScreen() {
const theme = (useColorScheme() ?? 'light') as 'light' | 'dark';
const colors: ThemeColors = Colors[theme];
const userProfile = useAppSelector((state) => state.user.profile);
const { ensureLoggedIn } = useAuthGuard();
const { ensureLoggedIn, isLoggedIn } = useAuthGuard();
const { checkServiceAccess } = useVipService();
const { openMembershipModal } = useMembershipModal();
const [selectedDate, setSelectedDate] = useState<Dayjs>(dayjs());
@@ -144,9 +144,11 @@ export default function MedicationsScreen() {
// 加载药物和记录数据
useEffect(() => {
if (!isLoggedIn) return;
dispatch(fetchMedications());
dispatch(fetchMedicationRecords({ date: selectedKey }));
}, [dispatch, selectedKey]);
}, [dispatch, selectedKey, isLoggedIn]);
useEffect(() => {
return () => {
@@ -159,6 +161,8 @@ export default function MedicationsScreen() {
// 页面聚焦时刷新数据,确保从添加页面返回时能看到最新数据
useFocusEffect(
useCallback(() => {
if (!isLoggedIn) return;
// 重新安排药品通知并刷新数据
const refreshDataAndRescheduleNotifications = async () => {
try {
@@ -188,7 +192,7 @@ export default function MedicationsScreen() {
};
refreshDataAndRescheduleNotifications();
}, [dispatch, selectedKey])
}, [dispatch, selectedKey, isLoggedIn])
);
useEffect(() => {