@@ -84,7 +84,7 @@ async function doAutoImport() {
8484 importStatus .value .isWorking = true ;
8585 importStatus .value .failed = [];
8686
87- // 遍历所有需要添加的站点
87+ // 遍历所有需要添加的站点,在遍历过程中我们不更新 siteHostMap 和 siteNameMap
8888 for (const site of importStatus .value .toWork ) {
8989 if (importStatus .value .success .includes (site )) {
9090 continue ; // 如果已经添加成功,则跳过
@@ -101,13 +101,15 @@ async function doAutoImport() {
101101
102102 // 对于 public 站点,不需要额外测试是否能够搜索
103103 if (siteMetadata .type === " public" ) {
104- await metadataStore .addSite (site , siteUserConfig ); // 直接将该站点设置存入 metadataStore
104+ // 直接将该站点设置存入 metadataStore
105+ await metadataStore .addSite (site , siteUserConfig , { reBuildMap: false }); // 抑制 site{Name, Host}Map 更新
105106 isThisSiteSuccess = true ;
106107 } else {
107108 // 遍历所有 private site 预设的 urls ,找到用户实际使用的 url
108109 for (const siteUrl of siteMetadata .urls ) {
109110 siteUserConfig .url = siteUrl ;
110- await metadataStore .addSite (site , siteUserConfig ); // 临时将该设置存入 metadataStore
111+ // 临时将该设置存入 metadataStore
112+ await metadataStore .addSite (site , siteUserConfig , { reBuildMap: false });
111113 const { status : testStatus } = await sendMessage (" getSiteSearchResult" , { siteId: site });
112114 if (testStatus === EResultParseStatus .success ) {
113115 isThisSiteSuccess = true ; // 如果搜索成功,说明该站点可以自动添加
@@ -120,7 +122,8 @@ async function doAutoImport() {
120122 importStatus .value .success .push (site );
121123 } else {
122124 importStatus .value .failed .push (site );
123- await metadataStore .removeSite (site ); // 如果搜索失败,说明该站点不能自动添加,移除在 metadataStore 中临时添加的配置项
125+ // 如果搜索失败,说明该站点不能自动添加,移除在 metadataStore 中临时添加的配置项
126+ await metadataStore .removeSite (site , { reBuildMap: false });
124127 }
125128 } catch (e ) {
126129 importStatus .value .failed .push (site );
@@ -131,7 +134,13 @@ async function doAutoImport() {
131134 importStatus .value .isWorking = false ;
132135 importStatus .value .toWork = [];
133136
134- runtimeStore .showSnakebar (t (" SetSite.oneClickImportDialog.importComplete" , { count: importStatus .value .success .length }), { color: " success" });
137+ // 所有导入完成,重构 site{Host, Name}Map
138+ await metadataStore .buildSiteMapCache (true );
139+
140+ runtimeStore .showSnakebar (
141+ t (" SetSite.oneClickImportDialog.importComplete" , { count: importStatus .value .success .length }),
142+ { color: " success" },
143+ );
135144}
136145
137146async function dialogEnter() {
0 commit comments