Skip to content

Commit

Permalink
dynamodb: temporarily remove scan query
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeybannov committed Dec 2, 2023
1 parent bc5828f commit 71a8221
Showing 1 changed file with 32 additions and 31 deletions.
63 changes: 32 additions & 31 deletions web/ASC.Web.Core/Helpers/ApiSystemHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public ApiSystemHelper(
_tenantDomainValidator = tenantDomainValidator;
_coreBaseSettings = coreBaseSettings;
_dynamoDbSettings = configuration.GetSetting<DynamoDbSettings>("aws:dynamoDB");
_regionTableName = !string.IsNullOrEmpty(_dynamoDbSettings.TableName) ? _dynamoDbSettings.TableName: "docspace-tenants_region";
_regionTableName = !string.IsNullOrEmpty(_dynamoDbSettings.TableName) ? _dynamoDbSettings.TableName : "docspace-tenants_region";
}

public string CreateAuthToken(string pkey)
Expand Down Expand Up @@ -121,12 +121,12 @@ public async Task AddTenantToCacheAsync(string tenantDomain, string tenantRegion
TableName = _regionTableName,
Item = new Dictionary<string, AttributeValue>
{
{ TenantDomainKey, new AttributeValue
{ TenantDomainKey, new AttributeValue
{
S = tenantDomain
}
},
{ TenantRegionKey, new AttributeValue
{ TenantRegionKey, new AttributeValue
{
S = tenantRegion
}
Expand Down Expand Up @@ -195,41 +195,42 @@ public async Task<IEnumerable<string>> FindTenantsInCacheAsync(string portalName

if (getItemResponse.Item.Count == 0) return null;

// cut number suffix
while (true)
{
if (_tenantDomainValidator.MinLength < portalName.Length && char.IsNumber(portalName, portalName.Length - 1))
{
portalName = portalName[0..^1];
}
else
{
break;
}
}

var scanRequest = new ScanRequest
{
TableName = _regionTableName,
FilterExpression = "begins_with(tenant_domain, :v_tenant_domain)",
ExpressionAttributeValues = new Dictionary<string, AttributeValue> {
{":v_tenant_domain", new AttributeValue { S = portalName }} },
ProjectionExpression = TenantDomainKey,
ConsistentRead = true
};

var scanResponse = await awsDynamoDbClient.ScanAsync(scanRequest);
var result = scanResponse.Items.Select(x => x.Values.First().S.Split('.')[0]);
return result;
//// cut number suffix
//while (true)
//{
// if (_tenantDomainValidator.MinLength < portalName.Length && char.IsNumber(portalName, portalName.Length - 1))
// {
// portalName = portalName[0..^1];
// }
// else
// {
// break;
// }
//}

//var scanRequest = new ScanRequest
//{
// TableName = _regionTableName,
// FilterExpression = "begins_with(tenant_domain, :v_tenant_domain)",
// ExpressionAttributeValues = new Dictionary<string, AttributeValue> {
// {":v_tenant_domain", new AttributeValue { S = portalName }} },
// ProjectionExpression = TenantDomainKey,
// ConsistentRead = true
//};

//var scanResponse = await awsDynamoDbClient.ScanAsync(scanRequest);
//var result = scanResponse.Items.Select(x => x.Values.First().S.Split('.')[0]);

return new List<string> { portalName };
}

#endregion

private AmazonDynamoDBClient GetDynamoDBClient()
{
return new AmazonDynamoDBClient(_dynamoDbSettings.AccessKeyId, _dynamoDbSettings.SecretAccessKey, RegionEndpoint.GetBySystemName(_dynamoDbSettings.Region));
}

private async Task<string> SendToApiAsync(string absoluteApiUrl, string apiPath, string httpMethod, Guid userId, string data = null)
{
if (!Uri.TryCreate(absoluteApiUrl, UriKind.Absolute, out _))
Expand Down

0 comments on commit 71a8221

Please sign in to comment.