Add lock for db
This commit is contained in:
@@ -9,8 +9,9 @@ namespace v2rayN.Base
|
|||||||
private static readonly Lazy<SqliteHelper> _instance = new(() => new());
|
private static readonly Lazy<SqliteHelper> _instance = new(() => new());
|
||||||
public static SqliteHelper Instance => _instance.Value;
|
public static SqliteHelper Instance => _instance.Value;
|
||||||
private string _connstr;
|
private string _connstr;
|
||||||
public SQLiteConnection _db;
|
private SQLiteConnection _db;
|
||||||
public SQLiteAsyncConnection _dbAsync;
|
private SQLiteAsyncConnection _dbAsync;
|
||||||
|
private static readonly object objLock = new();
|
||||||
|
|
||||||
public SqliteHelper()
|
public SqliteHelper()
|
||||||
{
|
{
|
||||||
@@ -33,31 +34,43 @@ namespace v2rayN.Base
|
|||||||
return await _dbAsync.InsertAsync(model);
|
return await _dbAsync.InsertAsync(model);
|
||||||
}
|
}
|
||||||
public int Replace(object model)
|
public int Replace(object model)
|
||||||
|
{
|
||||||
|
lock (objLock)
|
||||||
{
|
{
|
||||||
return _db.InsertOrReplace(model);
|
return _db.InsertOrReplace(model);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
public async Task<int> Replacesync(object model)
|
public async Task<int> Replacesync(object model)
|
||||||
{
|
{
|
||||||
return await _dbAsync.InsertOrReplaceAsync(model);
|
return await _dbAsync.InsertOrReplaceAsync(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Update(object model)
|
public int Update(object model)
|
||||||
|
{
|
||||||
|
lock (objLock)
|
||||||
{
|
{
|
||||||
return _db.Update(model);
|
return _db.Update(model);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
public async Task<int> UpdateAsync(object model)
|
public async Task<int> UpdateAsync(object model)
|
||||||
{
|
{
|
||||||
return await _dbAsync.UpdateAsync(model);
|
return await _dbAsync.UpdateAsync(model);
|
||||||
}
|
}
|
||||||
public int UpdateAll(IEnumerable models)
|
public int UpdateAll(IEnumerable models)
|
||||||
|
{
|
||||||
|
lock (objLock)
|
||||||
{
|
{
|
||||||
return _db.UpdateAll(models);
|
return _db.UpdateAll(models);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public int Delete(object model)
|
public int Delete(object model)
|
||||||
|
{
|
||||||
|
lock (objLock)
|
||||||
{
|
{
|
||||||
return _db.Delete(model);
|
return _db.Delete(model);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
public async Task<int> DeleteAsync(object model)
|
public async Task<int> DeleteAsync(object model)
|
||||||
{
|
{
|
||||||
return await _dbAsync.DeleteAsync(model);
|
return await _dbAsync.DeleteAsync(model);
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ namespace v2rayN.Handler
|
|||||||
|
|
||||||
_lstProfileEx = new(SqliteHelper.Instance.Table<ProfileExItem>());
|
_lstProfileEx = new(SqliteHelper.Instance.Table<ProfileExItem>());
|
||||||
|
|
||||||
Task.Run(async () =>
|
Task.Run(() =>
|
||||||
{
|
{
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
@@ -35,7 +35,7 @@ namespace v2rayN.Handler
|
|||||||
var item = _lstProfileEx.FirstOrDefault(t => t.indexId == id);
|
var item = _lstProfileEx.FirstOrDefault(t => t.indexId == id);
|
||||||
if (item is not null)
|
if (item is not null)
|
||||||
{
|
{
|
||||||
await SqliteHelper.Instance.Replacesync(item);
|
SqliteHelper.Instance.Replace(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Thread.Sleep(1000 * 60);
|
Thread.Sleep(1000 * 60);
|
||||||
|
|||||||
@@ -162,7 +162,7 @@ namespace v2rayN.Handler
|
|||||||
todayDown = 0,
|
todayDown = 0,
|
||||||
dateNow = ticks
|
dateNow = ticks
|
||||||
};
|
};
|
||||||
_ = SqliteHelper.Instance.Replacesync(_serverStatItem);
|
SqliteHelper.Instance.Replace(_serverStatItem);
|
||||||
_lstServerStat.Add(_serverStatItem);
|
_lstServerStat.Add(_serverStatItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user