Skip to content

Commit

Permalink
Remove data conenction cache
Browse files Browse the repository at this point in the history
  • Loading branch information
PascalSenn committed Jun 20, 2024
1 parent 1928feb commit fe97d41
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 118 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public class UserDataConnectorService : IUserDataConnectorService
{
private readonly ILogger<UserDataConnectorService> _logger;
private readonly IEnumerable<IUserDataConnector> _connectors;
private readonly IUserDataConnectorDataRepository _repository;
private readonly IEventService _eventService;

private static readonly Dictionary<string, ConnectorProfileType> ProfileTypeMap
Expand All @@ -34,12 +33,10 @@ private static readonly Dictionary<string, ConnectorProfileType> ProfileTypeMap
public UserDataConnectorService(
ILogger<UserDataConnectorService> logger,
IEnumerable<IUserDataConnector> connectors,
IUserDataConnectorDataRepository repository,
IEventService eventService)
{
_logger = logger;
_connectors = connectors;
_repository = repository;
_eventService = eventService;
}

Expand Down Expand Up @@ -108,7 +105,7 @@ private async Task<IEnumerable<Claim>> LoadDataAsync(
IUserDataConnector? connector = _connectors
.Single(x => x.Name == options.Name);

var timeOutToken = new CancellationTokenSource(Debugger.IsAttached ? 300000 : 5000);
var timeOutToken = new CancellationTokenSource(300000);

CancellationTokenSource cts = CancellationTokenSource.CreateLinkedTokenSource(
cancellationToken,
Expand All @@ -121,58 +118,9 @@ private async Task<IEnumerable<Claim>> LoadDataAsync(

activity?.EnrichDataConnectorResult(result);

if (result.Success && result.Executed && result.CacheKey != null)
{
try
{
await SaveDataAsync(options, result, context.Subject, cancellationToken);
}
catch (Exception ex)
{
_logger.DataConnectorSaveDataFailed(connector.Name);
activity?.RecordException(ex);
}
}
else if (!result.Success && result.CacheKey != null)
{
UserDataConnectorData? storedData = await _repository.GetAsync(
result.CacheKey,
connector.Name,
cancellationToken);

if (storedData != null)
{
claims = storedData.Claims.Select(x => new Claim(x.Type, x.Value));
}
else
{
throw result.Error;
}
}

return claims;
}

private async Task SaveDataAsync(
DataConnectorOptions options,
UserDataConnectorResult result,
string subject,
CancellationToken cancellationToken)
{
await _repository.SaveAsync(new UserDataConnectorData
{
Claims = result.Claims.Select(x => new ClaimData
{
Type = x.Type,
Value = x.Value
}),
Key = result.CacheKey!,
SubjectId = subject,
Connector = options.Name,
LastModifiedAt = DateTime.UtcNow
}, cancellationToken);
}

private bool ShouldExecute(DataConnectorOptions options, string caller)
{
return options.Enabled &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ public static IServiceCollection AddMongoStores(
services.AddSingleton<IIdentityResourceRepository, IdentityResourceRepository>();
services.AddSingleton<IPersonalAccessTokenRepository, PersonalAccessTokenRepository>();
services.AddSingleton<IUserClaimRuleRepository, UserClaimRuleRepository>();
services.AddSingleton<
IUserDataConnectorDataRepository,
UserDataConnectorDataRepository>();

return services;
}
Expand Down

This file was deleted.

0 comments on commit fe97d41

Please sign in to comment.