diff --git a/app/(tabs)/memo-list.tsx b/app/(tabs)/memo-list.tsx
index 4b23114..5ceb55a 100644
--- a/app/(tabs)/memo-list.tsx
+++ b/app/(tabs)/memo-list.tsx
@@ -109,6 +109,9 @@ const MemoList = () => {
ItemSeparatorComponent={() => (
)}
+ getItemLayout={(data, index) => (
+ { length: 80, offset: 80 * index, index }
+ )}
renderItem={({ item }) => (
{
- // const interval = setInterval(() => {
- // getCountData();
- // }, 1000);
- // return () => clearInterval(interval);
- // }, []);
+ useEffect(() => {
+ // 将轮询间隔增加到5秒,减少服务器压力和电池消耗
+ const interval = setInterval(() => {
+ getCountData();
+ }, 5000);
+ return () => clearInterval(interval);
+ }, []);
// 初始化获取用户信息
useEffect(() => {
@@ -107,6 +108,10 @@ export default function OwnerPage() {
}
+ // 优化性能:添加 getItemLayout
+ getItemLayout={(data, index) => (
+ { length: 1000, offset: 1000 * index, index }
+ )}
/>
{/* 设置弹窗 - 使用条件渲染避免层级冲突 */}
{modalVisible && (
diff --git a/assets/images/png/placeholder.png b/assets/images/png/placeholder.png
new file mode 100644
index 0000000..5371d4a
--- /dev/null
+++ b/assets/images/png/placeholder.png
@@ -0,0 +1 @@
+iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg==
\ No newline at end of file
diff --git a/components/ask/aiChat.tsx b/components/ask/aiChat.tsx
index 5e0a5e3..b0ff2fd 100644
--- a/components/ask/aiChat.tsx
+++ b/components/ask/aiChat.tsx
@@ -84,6 +84,7 @@ const MessageItem = ({ t, insets, item, sessionId, setModalVisible, modalVisible
borderRadius: 12,
}}
resizeMode="cover"
+ loadingIndicatorSource={require('@/assets/images/png/placeholder.png')}
/>
))}
@@ -218,6 +219,7 @@ const MessageItem = ({ t, insets, item, sessionId, setModalVisible, modalVisible
style={detailsStyles.image}
onError={(error) => console.log('Image load error:', error.nativeEvent.error)}
onLoad={() => console.log('Image loaded successfully')}
+ loadingIndicatorSource={require('@/assets/images/png/placeholder.png')}
/>
{
if (userMessages.length > 0) {
- setTimeout(() => {
+ // 延迟滚动以确保渲染完成
+ const timer = setTimeout(() => {
flatListRef.current?.scrollToEnd({ animated: true });
- }, 100);
+ }, 150);
+ return () => clearTimeout(timer);
}
}, [userMessages]);
+ // 优化 FlatList 性能 - 提供 getItemLayout 方法
+ const getItemLayout = useCallback((data: Message[] | null | undefined, index: number) => {
+ // 假设每个消息项的高度大约为 100(可根据实际情况调整)
+ const averageItemHeight = 100;
+ return {
+ length: averageItemHeight,
+ offset: averageItemHeight * index,
+ index,
+ };
+ }, []);
+
return (
MessageItem({ t, setSelectedImages, selectedImages, insets, item, sessionId, modalVisible, setModalVisible, setModalDetailsVisible, modalDetailsVisible })}
/>
diff --git a/components/file-upload/files-uploader.tsx b/components/file-upload/files-uploader.tsx
index 4938efa..15794cd 100644
--- a/components/file-upload/files-uploader.tsx
+++ b/components/file-upload/files-uploader.tsx
@@ -216,26 +216,30 @@ export const ImagesUploader: React.FC = ({
const CONCURRENCY_LIMIT = 3;
const results: UploadResult[] = [];
- // 分批处理资源
- for (let i = 0; i < assets.length; i += CONCURRENCY_LIMIT) {
- const batch = assets.slice(i, i + CONCURRENCY_LIMIT);
-
- // 并行处理当前批次的所有资源
+ // 分批处理资源,优化并发处理
+ const processBatch = async (batch: ImagePicker.ImagePickerAsset[]) => {
const batchResults = await Promise.allSettled(
batch.map(asset => processSingleAsset(asset))
);
-
+
// 收集成功的结果
for (const result of batchResults) {
if (result.status === 'fulfilled' && result.value) {
results.push(result.value);
}
}
+ };
- // 添加小延迟,避免过多占用系统资源
- if (i + CONCURRENCY_LIMIT < assets.length) {
- await new Promise(resolve => setTimeout(resolve, 100));
- }
+ // 使用 Promise.all 并行处理所有批次
+ const batches = [];
+ for (let i = 0; i < assets.length; i += CONCURRENCY_LIMIT) {
+ batches.push(assets.slice(i, i + CONCURRENCY_LIMIT));
+ }
+
+ // 并行处理所有批次,但限制并发数量
+ for (let i = 0; i < batches.length; i += CONCURRENCY_LIMIT) {
+ const batchGroup = batches.slice(i, i + CONCURRENCY_LIMIT);
+ await Promise.all(batchGroup.map(processBatch));
}
return results;
diff --git a/hooks/useUploadManager.ts b/hooks/useUploadManager.ts
index b19ff11..dd7dc8c 100644
--- a/hooks/useUploadManager.ts
+++ b/hooks/useUploadManager.ts
@@ -60,7 +60,8 @@ export const useUploadManager = () => {
console.log('useUploadManager focused, existing session found. Monitoring progress.');
// If a session exists, just start monitoring.
manageUploadState(true); // Initial check
- interval = setInterval(manageUploadState, 2000);
+ // 将轮询间隔从2秒增加到3秒,减少资源消耗
+ interval = setInterval(manageUploadState, 3000);
} else {
// If no session, then try to trigger a new upload.
console.log('useUploadManager focused, no existing session. Triggering foreground media upload check.');
@@ -73,7 +74,8 @@ export const useUploadManager = () => {
console.log(`New upload session started with time: ${newSessionStartTimeStr}, beginning to monitor...`);
// A new session was started, so start monitoring.
manageUploadState(); // Initial check
- interval = setInterval(manageUploadState, 2000);
+ // 将轮询间隔从2秒增加到3秒,减少资源消耗
+ interval = setInterval(manageUploadState, 3000);
}
}
};