forked from ddrilling/AsbCloudServer
Added default predicate to CacheTable.Where() method
This commit is contained in:
parent
1db3a81d56
commit
e1310be988
@ -141,29 +141,38 @@ namespace AsbCloudInfrastructure.Services.Cache
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<IEnumerable<TEntity>> SelectAsync(Func<TEntity, bool> predicate, CancellationToken token = default)
|
public Task<IEnumerable<TEntity>> WhereAsync(Func<TEntity, bool> predicate, CancellationToken token = default)
|
||||||
=> SelectAsync(predicate, RefreshMode.IfResultEmpty, token);
|
=> WhereAsync(predicate, RefreshMode.IfResultEmpty, token);
|
||||||
|
|
||||||
public IEnumerable<TEntity> Select(Func<TEntity, bool> predicate, RefreshMode refreshMode = RefreshMode.IfResultEmpty)
|
public IEnumerable<TEntity> Where(Func<TEntity, bool> predicate = default, RefreshMode refreshMode = RefreshMode.IfResultEmpty)
|
||||||
{
|
{
|
||||||
bool isUpdated = CheckRefresh(refreshMode);
|
bool isUpdated = CheckRefresh(refreshMode);
|
||||||
var result = cached.Where(predicate);
|
var result = (predicate != default)
|
||||||
|
? cached.Where(predicate)
|
||||||
|
: cached;
|
||||||
if (!result.Any() && refreshMode == RefreshMode.IfResultEmpty && !isUpdated)
|
if (!result.Any() && refreshMode == RefreshMode.IfResultEmpty && !isUpdated)
|
||||||
{
|
{
|
||||||
Refresh();
|
Refresh();
|
||||||
return cached.Where(predicate);
|
result = (predicate != default)
|
||||||
|
? cached.Where(predicate)
|
||||||
|
: cached;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IEnumerable<TEntity>> SelectAsync(Func<TEntity, bool> predicate, RefreshMode refreshMode = RefreshMode.IfResultEmpty, CancellationToken token = default)
|
public async Task<IEnumerable<TEntity>> WhereAsync(Func<TEntity, bool> predicate = default,
|
||||||
|
RefreshMode refreshMode = RefreshMode.IfResultEmpty, CancellationToken token = default)
|
||||||
{
|
{
|
||||||
bool isUpdated = await CheckRefreshAsync(refreshMode, token);
|
bool isUpdated = await CheckRefreshAsync(refreshMode, token);
|
||||||
var result = cached.Where(predicate);
|
var result = (predicate != default)
|
||||||
|
? cached.Where(predicate)
|
||||||
|
: cached;
|
||||||
if (!result.Any() && refreshMode == RefreshMode.IfResultEmpty && !isUpdated)
|
if (!result.Any() && refreshMode == RefreshMode.IfResultEmpty && !isUpdated)
|
||||||
{
|
{
|
||||||
await RefreshAsync(token);
|
await RefreshAsync(token);
|
||||||
return cached.Where(predicate);
|
result = (predicate != default)
|
||||||
|
? cached.Where(predicate)
|
||||||
|
: cached;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
if (telemetryId is null)
|
if (telemetryId is null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
var events = cacheEvents.Select(e => e.IdTelemetry == telemetryId);
|
var events = cacheEvents.Where(e => e.IdTelemetry == telemetryId);
|
||||||
|
|
||||||
if (!events.Any())
|
if (!events.Any())
|
||||||
return null;
|
return null;
|
||||||
@ -89,7 +89,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
if (messagesList.Count == 0)
|
if (messagesList.Count == 0)
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
var users = cacheTUsers.Select(u => u.IdTelemetry == telemetryId);
|
var users = cacheTUsers.Where(u => u.IdTelemetry == telemetryId);
|
||||||
|
|
||||||
foreach (var message in messagesList)
|
foreach (var message in messagesList)
|
||||||
{
|
{
|
||||||
|
@ -28,7 +28,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
this.telemetryService = telemetryService;
|
this.telemetryService = telemetryService;
|
||||||
this.saubDataCache = saubDataCache;
|
this.saubDataCache = saubDataCache;
|
||||||
cacheOperations = cacheDb.GetCachedTable<OperationCategory>((AsbCloudDbContext)db);
|
cacheOperations = cacheDb.GetCachedTable<OperationCategory>((AsbCloudDbContext)db);
|
||||||
operations = cacheOperations.Select(c => true);
|
operations = cacheOperations.Where(c => true);
|
||||||
operationDetectorService = new TelemetryOperationDetectorService(operations);
|
operationDetectorService = new TelemetryOperationDetectorService(operations);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user