Skip to content

Commit deafd73

Browse files
committed
Optimize RemoveInvalidServerResult
1 parent 317a5da commit deafd73

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

v2rayN/ServiceLib/Handler/ConfigHandler.cs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ public static async Task<int> AddVMessServer(Config config, ProfileItem profileI
294294
/// <param name="config"></param>
295295
/// <param name="indexes"></param>
296296
/// <returns></returns>
297-
public static async Task<int> RemoveServer(Config config, List<ProfileItem> indexes)
297+
public static async Task<int> RemoveServers(Config config, List<ProfileItem> indexes)
298298
{
299299
var subid = "TempRemoveSubId";
300300
foreach (var item in indexes)
@@ -303,7 +303,7 @@ public static async Task<int> RemoveServer(Config config, List<ProfileItem> inde
303303
}
304304

305305
await SQLiteHelper.Instance.UpdateAllAsync(indexes);
306-
await RemoveServerViaSubid(config, subid, false);
306+
await RemoveServersViaSubid(config, subid, false);
307307

308308
return 0;
309309
}
@@ -886,7 +886,7 @@ public static async Task<Tuple<int, int>> DedupServerList(Config config, string
886886
lstRemove.Add(item);
887887
}
888888
}
889-
await RemoveServer(config, lstRemove);
889+
await RemoveServers(config, lstRemove);
890890

891891
return new Tuple<int, int>(lstProfile.Count, lstKeep.Count);
892892
}
@@ -1062,12 +1062,9 @@ public static async Task<int> RemoveInvalidServerResult(Config config, string su
10621062
var lstProfile = (from t in lstModel
10631063
join t2 in lstProfileExs on t.IndexId equals t2.IndexId
10641064
where t2.Delay == -1
1065-
select t.IndexId).ToList();
1065+
select t).ToList();
10661066

1067-
foreach (var item in lstProfile)
1068-
{
1069-
await RemoveProfileItem(config, item);
1070-
}
1067+
await RemoveServers(config, JsonUtils.Deserialize<List<ProfileItem>>(JsonUtils.Serialize(lstProfile)));
10711068

10721069
return lstProfile.Count;
10731070
}
@@ -1094,7 +1091,7 @@ private static async Task<int> AddBatchServersCommon(Config config, string strDa
10941091
//remove sub items
10951092
if (isSub && Utils.IsNotEmpty(subid))
10961093
{
1097-
await RemoveServerViaSubid(config, subid, isSub);
1094+
await RemoveServersViaSubid(config, subid, isSub);
10981095
subFilter = (await AppHandler.Instance.GetSubItem(subid))?.Filter ?? "";
10991096
}
11001097

@@ -1188,7 +1185,7 @@ private static async Task<int> AddBatchServers4Custom(Config config, string strD
11881185
{
11891186
if (isSub && Utils.IsNotEmpty(subid))
11901187
{
1191-
await RemoveServerViaSubid(config, subid, isSub);
1188+
await RemoveServersViaSubid(config, subid, isSub);
11921189
}
11931190
int count = 0;
11941191
foreach (var it in lstProfiles)
@@ -1244,7 +1241,7 @@ private static async Task<int> AddBatchServers4Custom(Config config, string strD
12441241

12451242
if (isSub && Utils.IsNotEmpty(subid))
12461243
{
1247-
await RemoveServerViaSubid(config, subid, isSub);
1244+
await RemoveServersViaSubid(config, subid, isSub);
12481245
}
12491246

12501247
profileItem.Subid = subid;
@@ -1269,7 +1266,7 @@ private static async Task<int> AddBatchServers4SsSIP008(Config config, string st
12691266

12701267
if (isSub && Utils.IsNotEmpty(subid))
12711268
{
1272-
await RemoveServerViaSubid(config, subid, isSub);
1269+
await RemoveServersViaSubid(config, subid, isSub);
12731270
}
12741271

12751272
var lstSsServer = ShadowsocksFmt.ResolveSip008(strData);
@@ -1456,7 +1453,7 @@ public static async Task<int> AddSubItem(Config config, SubItem subItem)
14561453
/// <param name="config"></param>
14571454
/// <param name="subid"></param>
14581455
/// <returns></returns>
1459-
public static async Task<int> RemoveServerViaSubid(Config config, string subid, bool isSub)
1456+
public static async Task<int> RemoveServersViaSubid(Config config, string subid, bool isSub)
14601457
{
14611458
if (Utils.IsNullOrEmpty(subid))
14621459
{
@@ -1487,7 +1484,7 @@ public static async Task<int> DeleteSubItem(Config config, string id)
14871484
return 0;
14881485
}
14891486
await SQLiteHelper.Instance.DeleteAsync(item);
1490-
await RemoveServerViaSubid(config, id, false);
1487+
await RemoveServersViaSubid(config, id, false);
14911488

14921489
return 0;
14931490
}

v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ public async Task RemoveServerAsync()
520520
}
521521
var exists = lstSelecteds.Exists(t => t.IndexId == _config.IndexId);
522522

523-
await ConfigHandler.RemoveServer(_config, lstSelecteds);
523+
await ConfigHandler.RemoveServers(_config, lstSelecteds);
524524
NoticeHandler.Instance.Enqueue(ResUI.OperationSuccess);
525525
if (lstSelecteds.Count == _profileItems.Count)
526526
{

0 commit comments

Comments
 (0)