From 71a8221826968d24b99fe9fbce6f1839aae1b1bf Mon Sep 17 00:00:00 2001 From: Alexey Bannov Date: Sat, 2 Dec 2023 16:15:00 +0300 Subject: [PATCH] dynamodb: temporarily remove scan query --- web/ASC.Web.Core/Helpers/ApiSystemHelper.cs | 63 +++++++++++---------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/web/ASC.Web.Core/Helpers/ApiSystemHelper.cs b/web/ASC.Web.Core/Helpers/ApiSystemHelper.cs index 251074515d8..8a4f3d73175 100644 --- a/web/ASC.Web.Core/Helpers/ApiSystemHelper.cs +++ b/web/ASC.Web.Core/Helpers/ApiSystemHelper.cs @@ -67,7 +67,7 @@ public ApiSystemHelper( _tenantDomainValidator = tenantDomainValidator; _coreBaseSettings = coreBaseSettings; _dynamoDbSettings = configuration.GetSetting("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) @@ -121,12 +121,12 @@ public async Task AddTenantToCacheAsync(string tenantDomain, string tenantRegion TableName = _regionTableName, Item = new Dictionary { - { TenantDomainKey, new AttributeValue + { TenantDomainKey, new AttributeValue { S = tenantDomain } }, - { TenantRegionKey, new AttributeValue + { TenantRegionKey, new AttributeValue { S = tenantRegion } @@ -195,41 +195,42 @@ public async Task> 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 { - {":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 { + // {":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 { portalName }; } #endregion - + private AmazonDynamoDBClient GetDynamoDBClient() { return new AmazonDynamoDBClient(_dynamoDbSettings.AccessKeyId, _dynamoDbSettings.SecretAccessKey, RegionEndpoint.GetBySystemName(_dynamoDbSettings.Region)); } - + private async Task SendToApiAsync(string absoluteApiUrl, string apiPath, string httpMethod, Guid userId, string data = null) { if (!Uri.TryCreate(absoluteApiUrl, UriKind.Absolute, out _))