mirror of
https://github.com/2dust/v2rayN.git
synced 2026-10-28 16:14:58 +03:00
Code optimization
This commit is contained in:
@@ -102,17 +102,17 @@
|
||||
|
||||
#region SqliteHelper
|
||||
|
||||
public async Task<List<SubItem>> SubItems()
|
||||
public async Task<List<SubItem>?> SubItems()
|
||||
{
|
||||
return await SQLiteHelper.Instance.TableAsync<SubItem>().OrderBy(t => t.Sort).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<SubItem> GetSubItem(string subid)
|
||||
public async Task<SubItem?> GetSubItem(string subid)
|
||||
{
|
||||
return await SQLiteHelper.Instance.TableAsync<SubItem>().FirstOrDefaultAsync(t => t.Id == subid);
|
||||
}
|
||||
|
||||
public async Task<List<ProfileItem>> ProfileItems(string subid)
|
||||
public async Task<List<ProfileItem>?> ProfileItems(string subid)
|
||||
{
|
||||
if (Utils.IsNullOrEmpty(subid))
|
||||
{
|
||||
@@ -124,12 +124,12 @@
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<string>> ProfileItemIndexes(string subid)
|
||||
public async Task<List<string>?> ProfileItemIndexes(string subid)
|
||||
{
|
||||
return (await ProfileItems(subid)).Select(t => t.IndexId).ToList();
|
||||
return (await ProfileItems(subid))?.Select(t => t.IndexId)?.ToList();
|
||||
}
|
||||
|
||||
public async Task<List<ProfileItemModel>> ProfileItems(string subid, string filter)
|
||||
public async Task<List<ProfileItemModel>?> ProfileItems(string subid, string filter)
|
||||
{
|
||||
var sql = @$"select a.*
|
||||
,b.remarks subRemarks
|
||||
@@ -152,7 +152,7 @@
|
||||
return await SQLiteHelper.Instance.QueryAsync<ProfileItemModel>(sql);
|
||||
}
|
||||
|
||||
public async Task<List<ProfileItemModel>> ProfileItemsEx(string subid, string filter)
|
||||
public async Task<List<ProfileItemModel>?> ProfileItemsEx(string subid, string filter)
|
||||
{
|
||||
var lstModel = await ProfileItems(_config.SubIndexId, filter);
|
||||
|
||||
@@ -209,22 +209,22 @@
|
||||
return await SQLiteHelper.Instance.TableAsync<ProfileItem>().FirstOrDefaultAsync(it => it.Remarks == remarks);
|
||||
}
|
||||
|
||||
public async Task<List<RoutingItem>> RoutingItems()
|
||||
public async Task<List<RoutingItem>?> RoutingItems()
|
||||
{
|
||||
return await SQLiteHelper.Instance.TableAsync<RoutingItem>().Where(it => it.Locked == false).OrderBy(t => t.Sort).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<RoutingItem> GetRoutingItem(string id)
|
||||
public async Task<RoutingItem?> GetRoutingItem(string id)
|
||||
{
|
||||
return await SQLiteHelper.Instance.TableAsync<RoutingItem>().FirstOrDefaultAsync(it => it.Locked == false && it.Id == id);
|
||||
}
|
||||
|
||||
public async Task<List<DNSItem>> DNSItems()
|
||||
public async Task<List<DNSItem>?> DNSItems()
|
||||
{
|
||||
return await SQLiteHelper.Instance.TableAsync<DNSItem>().ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<DNSItem> GetDNSItem(ECoreType eCoreType)
|
||||
public async Task<DNSItem?> GetDNSItem(ECoreType eCoreType)
|
||||
{
|
||||
return await SQLiteHelper.Instance.TableAsync<DNSItem>().FirstOrDefaultAsync(it => it.CoreType == eCoreType);
|
||||
}
|
||||
|
||||
@@ -171,18 +171,7 @@ namespace ServiceLib.Handler
|
||||
/// </summary>
|
||||
/// <param name="config"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<int> SaveConfig(Config config, bool reload = true)
|
||||
{
|
||||
await ToJsonFile(config);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 存储文件
|
||||
/// </summary>
|
||||
/// <param name="config"></param>
|
||||
private static async Task ToJsonFile(Config config)
|
||||
public static async Task<int> SaveConfig(Config config)
|
||||
{
|
||||
lock (_objLock)
|
||||
{
|
||||
@@ -193,7 +182,7 @@ namespace ServiceLib.Handler
|
||||
var tempPath = $"{resPath}_temp";
|
||||
if (JsonUtils.ToFile(config, tempPath) != 0)
|
||||
{
|
||||
return;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (File.Exists(resPath))
|
||||
@@ -206,8 +195,11 @@ namespace ServiceLib.Handler
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logging.SaveLog("ToJsonFile", ex);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endregion ConfigHandler
|
||||
@@ -369,7 +361,7 @@ namespace ServiceLib.Handler
|
||||
|
||||
config.IndexId = indexId;
|
||||
|
||||
await ToJsonFile(config);
|
||||
await SaveConfig(config);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1142,7 +1134,7 @@ namespace ServiceLib.Handler
|
||||
await SQLiteHelper.Instance.InsertAllAsync(lstAdd);
|
||||
}
|
||||
|
||||
await ToJsonFile(config);
|
||||
await SaveConfig(config);
|
||||
return countServers;
|
||||
}
|
||||
|
||||
@@ -1272,7 +1264,7 @@ namespace ServiceLib.Handler
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
await ToJsonFile(config);
|
||||
await SaveConfig(config);
|
||||
return counter;
|
||||
}
|
||||
|
||||
@@ -1605,7 +1597,7 @@ namespace ServiceLib.Handler
|
||||
config.RoutingBasicItem.RoutingIndexId = routingItem.Id;
|
||||
}
|
||||
|
||||
await ToJsonFile(config);
|
||||
await SaveConfig(config);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user