|
|
|
@ -7,7 +7,7 @@ namespace v2rayN.Handler
|
|
|
|
|
internal class ProfileExHandler |
|
|
|
|
{ |
|
|
|
|
private static readonly Lazy<ProfileExHandler> _instance = new(() => new()); |
|
|
|
|
private ConcurrentBag<ProfileExItem> _lstProfileEx; |
|
|
|
|
private ConcurrentBag<ProfileExItem> _lstProfileEx = []; |
|
|
|
|
private Queue<string> _queIndexIds = new(); |
|
|
|
|
public ConcurrentBag<ProfileExItem> ProfileExs => _lstProfileEx; |
|
|
|
|
public static ProfileExHandler Instance => _instance.Value; |
|
|
|
@ -15,6 +15,15 @@ namespace v2rayN.Handler
|
|
|
|
|
public ProfileExHandler() |
|
|
|
|
{ |
|
|
|
|
Init(); |
|
|
|
|
|
|
|
|
|
Task.Run(async () => |
|
|
|
|
{ |
|
|
|
|
while (true) |
|
|
|
|
{ |
|
|
|
|
SaveQueueIndexIds(); |
|
|
|
|
await Task.Delay(1000 * 600); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void Init() |
|
|
|
@ -22,31 +31,56 @@ namespace v2rayN.Handler
|
|
|
|
|
SQLiteHelper.Instance.Execute($"delete from ProfileExItem where indexId not in ( select indexId from ProfileItem )"); |
|
|
|
|
|
|
|
|
|
_lstProfileEx = new(SQLiteHelper.Instance.Table<ProfileExItem>()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Task.Run(async () => |
|
|
|
|
private void IndexIdEnqueue(string indexId) |
|
|
|
|
{ |
|
|
|
|
while (true) |
|
|
|
|
if (!Utils.IsNullOrEmpty(indexId) && !_queIndexIds.Contains(indexId)) |
|
|
|
|
{ |
|
|
|
|
_queIndexIds.Enqueue(indexId); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void SaveQueueIndexIds() |
|
|
|
|
{ |
|
|
|
|
var cnt = _queIndexIds.Count; |
|
|
|
|
if (cnt > 0) |
|
|
|
|
{ |
|
|
|
|
var lstExists = SQLiteHelper.Instance.Table<ProfileExItem>(); |
|
|
|
|
List<ProfileExItem> lstInserts = []; |
|
|
|
|
List<ProfileExItem> lstUpdates = []; |
|
|
|
|
|
|
|
|
|
for (int i = 0; i < cnt; i++) |
|
|
|
|
{ |
|
|
|
|
var id = _queIndexIds.Dequeue(); |
|
|
|
|
var item = _lstProfileEx.FirstOrDefault(t => t.indexId == id); |
|
|
|
|
if (item is not null) |
|
|
|
|
var item = lstExists.FirstOrDefault(t => t.indexId == id); |
|
|
|
|
var itemNew = _lstProfileEx?.FirstOrDefault(t => t.indexId == id); |
|
|
|
|
if (itemNew is null) |
|
|
|
|
{ |
|
|
|
|
SQLiteHelper.Instance.Replace(item); |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (item is not null) |
|
|
|
|
{ |
|
|
|
|
lstUpdates.Add(itemNew); |
|
|
|
|
} |
|
|
|
|
await Task.Delay(1000 * 60); |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
lstInserts.Add(itemNew); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void IndexIdEnqueue(string indexId) |
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
if (!Utils.IsNullOrEmpty(indexId) && !_queIndexIds.Contains(indexId)) |
|
|
|
|
if (lstInserts.Count() > 0) |
|
|
|
|
SQLiteHelper.Instance.InsertAll(lstInserts); |
|
|
|
|
|
|
|
|
|
if (lstUpdates.Count() > 0) |
|
|
|
|
SQLiteHelper.Instance.UpdateAll(lstUpdates); |
|
|
|
|
} |
|
|
|
|
catch (Exception ex) |
|
|
|
|
{ |
|
|
|
|
_queIndexIds.Enqueue(indexId); |
|
|
|
|
Logging.SaveLog("ProfileExHandler", ex); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -73,11 +107,7 @@ namespace v2rayN.Handler
|
|
|
|
|
{ |
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
//foreach (var item in _lstProfileEx) |
|
|
|
|
//{ |
|
|
|
|
// SQLiteHelper.Instance.Replace(item); |
|
|
|
|
//} |
|
|
|
|
SQLiteHelper.Instance.UpdateAll(_lstProfileEx); |
|
|
|
|
SaveQueueIndexIds(); |
|
|
|
|
} |
|
|
|
|
catch (Exception ex) |
|
|
|
|
{ |
|
|
|
|