perf(app): 添加登录状态检查并优化性能
- 在多个页面添加 isLoggedIn 检查,防止未登录时进行不必要的数据获取 - 使用 React.memo 和 useMemo 优化个人页面徽章渲染性能 - 为 badges API 添加节流机制,避免频繁请求 - 优化图片缓存策略和字符串处理 - 移除调试日志并改进推送通知的认证检查
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { getAuthToken } from '@/services/api';
|
||||
import { logger } from '@/utils/logger';
|
||||
import Constants from 'expo-constants';
|
||||
import * as Notifications from 'expo-notifications';
|
||||
@@ -167,8 +168,12 @@ export class PushNotificationManager {
|
||||
if (!isRegistered || storedToken !== token) {
|
||||
await this.registerDeviceToken(token);
|
||||
} else {
|
||||
// 令牌已注册且未变化,更新用户ID绑定关系
|
||||
await this.updateTokenUserId(token);
|
||||
// 令牌已注册且未变化
|
||||
// 只有在用户已登录的情况下才更新用户ID绑定关系
|
||||
const authToken = await getAuthToken();
|
||||
if (authToken) {
|
||||
await this.updateTokenUserId(token);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('检查和注册设备令牌失败:', error);
|
||||
|
||||
Reference in New Issue
Block a user