Skip to content

Commit 19e85bb

Browse files
committed
Optimize UI loading speed
1 parent 7f650aa commit 19e85bb

1 file changed

Lines changed: 1 addition & 99 deletions

File tree

src/pages/appstore.js

Lines changed: 1 addition & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -655,15 +655,10 @@ const AppStore = () => {
655655
try {
656656
// 清理过期的本地缓存
657657
cleanupExpiredCache();
658-
659658
// 使用统一的配置管理器,一次性获取所有配置
660-
console.time('[AppStore] Config initialization');
661659
const config = await configManager.initialize();
662660
baseURL = config.baseURL;
663-
console.timeEnd('[AppStore] Config initialization');
664-
console.log('[AppStore] BaseURL configured:', baseURL);
665661
} catch (error) {
666-
console.error('[AppStore] 配置初始化失败:', error);
667662
setDataError(true);
668663
const errorText = [error.problem, error.reason, error.message]
669664
.filter(item => typeof item === 'string')
@@ -690,7 +685,6 @@ const AppStore = () => {
690685
if (age > 60 * 60 * 1000) {
691686
localStorage.removeItem(key);
692687
localStorage.removeItem(key + '_timestamp');
693-
console.log(`[AppStore] Cleaned expired cache: ${key}`);
694688
}
695689
}
696690
});
@@ -702,7 +696,6 @@ const AppStore = () => {
702696
//获取用户收藏的apps (优化:API优先+本地缓存)
703697
const getFavoriteApps = async () => {
704698
try {
705-
console.time('[AppStore] Get favorite apps');
706699

707700
// 先尝试本地缓存(1分钟有效期,收藏数据变化较频繁)
708701
const cacheKey = 'favorite_apps_cache';
@@ -713,9 +706,7 @@ const AppStore = () => {
713706
if (cachedFavorites && cacheTimestamp) {
714707
const age = Date.now() - parseInt(cacheTimestamp);
715708
if (age < cacheTimeout) {
716-
console.log('[AppStore] Using cached favorite apps');
717709
setFavoriteApps(cachedFavorites);
718-
console.timeEnd('[AppStore] Get favorite apps');
719710
return;
720711
}
721712
}
@@ -732,25 +723,15 @@ const AppStore = () => {
732723
} catch (e) {
733724
console.warn('[AppStore] Failed to cache favorite apps:', e);
734725
}
735-
736-
console.timeEnd('[AppStore] Get favorite apps');
737-
console.log('[AppStore] Favorite apps loaded via API:', favoriteKeys);
738726
} catch (error) {
739-
console.timeEnd('[AppStore] Get favorite apps');
740-
console.warn('[AppStore] Failed to load favorite apps via API:', error);
741-
742727
// 尝试使用缓存的数据作为备选
743728
const cachedFavorites = localStorage.getItem('favorite_apps_cache');
744729
if (cachedFavorites) {
745-
console.log('[AppStore] Using stale cache as fallback');
746730
setFavoriteApps(cachedFavorites);
747731
} else {
748732
// 设置为空字符串,不影响主要功能
749733
setFavoriteApps("");
750734
}
751-
752-
// 不设置错误状态,收藏功能失败不应阻塞整个页面
753-
console.log('[AppStore] Page will continue to work without favorites');
754735
}
755736
};
756737

@@ -761,19 +742,13 @@ const AppStore = () => {
761742
const favoriteString = Array.isArray(updatedFavorites) ? updatedFavorites.join(',') : updatedFavorites;
762743
const finalValue = favoriteString || ""; // 如果为空,传递空字符串
763744

764-
console.log('[AppStore] Updating favorite apps via API:', finalValue);
765-
766745
// 使用API helper更新收藏列表
767746
const result = await UpdateSettingsBySection("favorite_apps", "keys", finalValue);
768-
console.log('[AppStore] Favorite apps updated successfully via API:', result);
769-
770747
// 更新成功后,清除收藏数据缓存,确保下次获取最新数据
771748
localStorage.removeItem('favorite_apps_cache');
772749
localStorage.removeItem('favorite_apps_cache_timestamp');
773750

774751
} catch (error) {
775-
console.error('[AppStore] Failed to update favorite apps via API:', error);
776-
777752
// API失败时的处理,可以选择显示错误或忽略
778753
setDataError(true);
779754
setErrorMessage(`Failed to update favorites: ${error.message}`);
@@ -845,7 +820,6 @@ const AppStore = () => {
845820
//获取所有apps(增强缓存机制)
846821
const getData = async () => {
847822
try {
848-
console.time('[AppStore] Apps data fetching');
849823

850824
// 检查是否有缓存的应用数据(5分钟有效期)
851825
const cacheKey = 'appstore_data';
@@ -856,18 +830,15 @@ const AppStore = () => {
856830
if (cachedData && cacheTimestamp) {
857831
const age = Date.now() - parseInt(cacheTimestamp);
858832
if (age < cacheTimeout) {
859-
console.log('[AppStore] Using cached apps data');
860833
const { catalogs, apps: cachedApps } = JSON.parse(cachedData);
861834
setMainCatalogs(catalogs);
862835
setApps(cachedApps);
863836
setAppList(cachedApps);
864-
console.timeEnd('[AppStore] Apps data fetching');
865837
return;
866838
}
867839
}
868840

869841
// 缓存失效或不存在,重新获取数据
870-
console.log('[AppStore] Fetching fresh apps data');
871842
const responses = await Promise.all([
872843
AppCatalog(language === "zh_CN" ? "zh" : "en"),
873844
AppAvailable(language === "zh_CN" ? "zh" : "en")
@@ -898,14 +869,11 @@ const AppStore = () => {
898869
apps: productResponse
899870
}));
900871
localStorage.setItem(cacheKey + '_timestamp', Date.now().toString());
901-
console.log('[AppStore] Apps data cached successfully');
902872
} catch (e) {
903873
console.warn('[AppStore] Failed to cache apps data:', e);
904874
}
905875

906-
console.timeEnd('[AppStore] Apps data fetching');
907876
} catch (error) {
908-
console.timeEnd('[AppStore] Apps data fetching');
909877
setDataError(true);
910878
setErrorMessage(error.message);
911879
}
@@ -916,28 +884,20 @@ const AppStore = () => {
916884
setLoading(true);
917885

918886
try {
919-
console.time('[AppStore] Total page load time');
920-
921887
// 第一阶段:预热配置缓存(快速执行)
922888
await initializeConfig();
923889

924890
// 第二阶段:优先获取应用数据,让用户快速看到内容
925-
console.time('[AppStore] Core data fetching');
926891
await getData(); // 优先加载应用列表,让页面快速显示
927-
console.timeEnd('[AppStore] Core data fetching');
928892

929893
setLoading(false); // 主要数据加载完成,立即显示页面
930-
console.timeEnd('[AppStore] Total page load time');
931894

932895
// 第三阶段:异步加载收藏数据,不阻塞页面显示
933-
console.time('[AppStore] Favorite apps loading');
934896
getFavoriteApps().finally(() => {
935-
console.timeEnd('[AppStore] Favorite apps loading');
936-
console.log('[AppStore] Favorite apps loaded asynchronously');
897+
937898
});
938899

939900
} catch (error) {
940-
console.error("[AppStore] Error loading core data:", error);
941901
setDataError(true);
942902
setErrorMessage(error.message || "Fetch Data Error");
943903
setLoading(false);
@@ -974,11 +934,6 @@ const AppStore = () => {
974934
}
975935
}, [apps, favoriteApps, searchValue]);
976936

977-
978-
979-
//if (loading) return <Spinner className='dis_mid' />
980-
// if (dataError) return <p>Error : {errorMesage || "Fetch Data Error"} </p>;
981-
982937
//用于显示应用详情的弹窗
983938
const handleClick = (product, isAppFavorite) => {
984939
setSelectedProduct(product);
@@ -992,59 +947,6 @@ const AppStore = () => {
992947
setSelectedProduct(null);
993948
};
994949

995-
//当主目录改变时
996-
// const changeMainCatalog = (selectedMainCatalog) => {
997-
// setSelectedMainCatalogKey(selectedMainCatalog);
998-
// // setSelectedSubCatalog("All");
999-
// setFavoriteAppsIsVisible(selectedMainCatalog === "All" && favoriteApps.length > 0);
1000-
// // 查询主目录下的二级目录
1001-
// let updatedData = null;
1002-
// // filter
1003-
// updatedData =
1004-
// selectedMainCatalog === 'All'
1005-
// ? []
1006-
// : mainCatalogs.filter(c => c.key === selectedMainCatalog)?.[0]?.linkedFrom?.catalogCollection?.items;
1007-
// const data = updatedData.sort(function (a, b) {
1008-
// if (a.position === null && b.position === null) {
1009-
// return 0;
1010-
// } else if (a.position === null) {
1011-
// return 1;
1012-
// } else if (b.position === null) {
1013-
// return -1;
1014-
// } else {
1015-
// return a.position - b.position;
1016-
// }
1017-
// });
1018-
// setSubCatalogs(data);
1019-
1020-
// //根据主目录过滤app数据
1021-
// let subCatalogApps = null;
1022-
// let mainCatalogAllApps = null;
1023-
// mainCatalogAllApps = apps.filter(app => app?.catalogCollection?.items.some(sub => sub?.catalogCollection?.items.some(subsub => subsub.key === selectedMainCatalog)));
1024-
// subCatalogApps =
1025-
// selectedMainCatalog === "All"
1026-
// ? /*apps*/ nonFavoriteApps
1027-
// : mainCatalogAllApps;
1028-
// setAppList(subCatalogApps);
1029-
// setAllMainCatalogApps(mainCatalogAllApps);
1030-
// setIsAllSelected(false);
1031-
// setSearchValue("");
1032-
// };
1033-
1034-
// //当子目录改变时,过滤应用数据
1035-
// const changeSubCatalog = (selectedSubCatalog) => {
1036-
// setSelectedSubCatalogKey(selectedSubCatalog);
1037-
// let updatedData = null;
1038-
// updatedData =
1039-
// selectedSubCatalog === "All"
1040-
// ? allMainCatalogApps
1041-
// : apps.filter(app => app?.catalogCollection?.items.some(c => c.key === selectedSubCatalog));
1042-
// setAppList(updatedData);
1043-
// setSearchValue("");
1044-
1045-
// console.log("subCatalogAllApps", updatedData);
1046-
// };
1047-
1048950
const changeMainCatalog = (selectedMainCatalog) => {
1049951
return new Promise((resolve) => {
1050952
setSelectedMainCatalogKey(selectedMainCatalog);

0 commit comments

Comments
 (0)