Browse Source

Merge pull request #1114 from colinin/perf-saas

perf(saas): check the default connection string
pull/1124/head
yx lin 1 year ago
committed by GitHub
parent
commit
f8d3c24c53
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 30
      aspnet-core/modules/saas/LINGYUN.Abp.Saas.Application.Contracts/LINGYUN/Abp/Saas/Tenants/Dto/TenantConnectionStringSetInput.cs
  2. 31
      aspnet-core/modules/saas/LINGYUN.Abp.Saas.Application.Contracts/LINGYUN/Abp/Saas/Tenants/Dto/TenantCreateDto.cs
  3. 2
      aspnet-core/modules/saas/LINGYUN.Abp.Saas.Application.Contracts/LINGYUN/Abp/Saas/Tenants/ITenantAppService.cs
  4. 16
      aspnet-core/modules/saas/LINGYUN.Abp.Saas.Application/LINGYUN/Abp/Saas/Tenants/TenantAppService.cs
  5. 3
      aspnet-core/modules/saas/LINGYUN.Abp.Saas.Domain.Shared/LINGYUN/Abp/Saas/Localization/Resources/en.json
  6. 3
      aspnet-core/modules/saas/LINGYUN.Abp.Saas.Domain.Shared/LINGYUN/Abp/Saas/Localization/Resources/zh-Hans.json
  7. 4
      aspnet-core/modules/saas/LINGYUN.Abp.Saas.EntityFrameworkCore/LINGYUN/Abp/Saas/EntityFrameworkCore/EfCoreTenantRepository.cs
  8. 2
      aspnet-core/modules/saas/LINGYUN.Abp.Saas.HttpApi/LINGYUN/Abp/Saas/Tenants/TenantController.cs

30
aspnet-core/modules/saas/LINGYUN.Abp.Saas.Application.Contracts/LINGYUN/Abp/Saas/Tenants/Dto/TenantConnectionStringCreateOrUpdate.cs → aspnet-core/modules/saas/LINGYUN.Abp.Saas.Application.Contracts/LINGYUN/Abp/Saas/Tenants/Dto/TenantConnectionStringSetInput.cs

@ -1,15 +1,15 @@
using System.ComponentModel.DataAnnotations;
using Volo.Abp.Validation;
namespace LINGYUN.Abp.Saas.Tenants;
public class TenantConnectionStringCreateOrUpdate
{
[Required]
[DynamicStringLength(typeof(TenantConnectionStringConsts), nameof(TenantConnectionStringConsts.MaxNameLength))]
public string Name { get; set; }
[Required]
[DynamicStringLength(typeof(TenantConnectionStringConsts), nameof(TenantConnectionStringConsts.MaxValueLength))]
public string Value { get; set; }
}
using System.ComponentModel.DataAnnotations;
using Volo.Abp.Validation;
namespace LINGYUN.Abp.Saas.Tenants;
public class TenantConnectionStringSetInput
{
[Required]
[DynamicStringLength(typeof(TenantConnectionStringConsts), nameof(TenantConnectionStringConsts.MaxNameLength))]
public string Name { get; set; }
[Required]
[DynamicStringLength(typeof(TenantConnectionStringConsts), nameof(TenantConnectionStringConsts.MaxValueLength))]
public string Value { get; set; }
}

31
aspnet-core/modules/saas/LINGYUN.Abp.Saas.Application.Contracts/LINGYUN/Abp/Saas/Tenants/Dto/TenantCreateDto.cs

@ -1,5 +1,11 @@
using System.Collections.Generic;
using LINGYUN.Abp.Saas.Localization;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Localization;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using Volo.Abp.Validation;
namespace LINGYUN.Abp.Saas.Tenants;
@ -22,10 +28,31 @@ public class TenantCreateDto : TenantCreateOrUpdateBase
/// <summary>
/// 默认数据库连接字符串
/// </summary>
[DynamicStringLength(typeof(TenantConnectionStringConsts), nameof(TenantConnectionStringConsts.MaxValueLength))]
public string DefaultConnectionString { get; set; }
/// <summary>
/// 其他数据库连接
/// </summary>
public Dictionary<string, string> ConnectionStrings { get; set; } = new Dictionary<string, string>();
public List<TenantConnectionStringSetInput> ConnectionStrings { get; set; } = new List<TenantConnectionStringSetInput>();
public override IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
var validationResults = base.Validate(validationContext);
if (!UseSharedDatabase && DefaultConnectionString.IsNullOrWhiteSpace())
{
var saasResource = validationContext.GetRequiredService<IStringLocalizer<AbpSaasResource>>();
var errors = new ValidationResult[1]
{
new ValidationResult(
saasResource["IfUseCustomDataBaseDefaultConnectionStringIsRequiredMessage"],
new string[1]{ nameof(DefaultConnectionString) })
};
return validationResults.Union(errors);
}
return validationResults;
}
}

2
aspnet-core/modules/saas/LINGYUN.Abp.Saas.Application.Contracts/LINGYUN/Abp/Saas/Tenants/ITenantAppService.cs

@ -26,7 +26,7 @@ public interface ITenantAppService :
Task<TenantConnectionStringDto> SetConnectionStringAsync(
Guid id,
TenantConnectionStringCreateOrUpdate input);
TenantConnectionStringSetInput input);
Task DeleteConnectionStringAsync(
Guid id,

16
aspnet-core/modules/saas/LINGYUN.Abp.Saas.Application/LINGYUN/Abp/Saas/Tenants/TenantAppService.cs

@ -83,18 +83,18 @@ public class TenantAppService : AbpSaasAppServiceBase, ITenantAppService
tenant.SetDisableTime(input.DisableTime);
input.MapExtraPropertiesTo(tenant);
if (!input.UseSharedDatabase && !input.DefaultConnectionString.IsNullOrWhiteSpace())
if (!input.UseSharedDatabase)
{
await CheckConnectionString(input.DefaultConnectionString);
tenant.SetDefaultConnectionString(input.DefaultConnectionString);
}
if (input.ConnectionStrings.Any())
{
foreach (var connectionString in input.ConnectionStrings)
if (input.ConnectionStrings.Any())
{
await CheckConnectionString(connectionString.Value, connectionString.Key);
tenant.SetConnectionString(connectionString.Key, connectionString.Value);
foreach (var connectionString in input.ConnectionStrings)
{
await CheckConnectionString(connectionString.Value, connectionString.Name);
tenant.SetConnectionString(connectionString.Name, connectionString.Value);
}
}
}
@ -213,7 +213,7 @@ public class TenantAppService : AbpSaasAppServiceBase, ITenantAppService
}
[Authorize(AbpSaasPermissions.Tenants.ManageConnectionStrings)]
public async virtual Task<TenantConnectionStringDto> SetConnectionStringAsync(Guid id, TenantConnectionStringCreateOrUpdate input)
public async virtual Task<TenantConnectionStringDto> SetConnectionStringAsync(Guid id, TenantConnectionStringSetInput input)
{
await CheckConnectionString(input.Value, input.Name);

3
aspnet-core/modules/saas/LINGYUN.Abp.Saas.Domain.Shared/LINGYUN/Abp/Saas/Localization/Resources/en.json

@ -50,6 +50,7 @@
"Features:ExpiredRecoveryTimeDesc": "If the resource expiration is not handled for a long time, tenant resources will be reclaimed",
"UnActived": "UnActived",
"RecycleStrategy:Reserve": "Reserve",
"RecycleStrategy:Recycle": "Recycle"
"RecycleStrategy:Recycle": "Recycle",
"IfUseCustomDataBaseDefaultConnectionStringIsRequiredMessage": "If you use a custom database, the default connection string must be required!"
}
}

3
aspnet-core/modules/saas/LINGYUN.Abp.Saas.Domain.Shared/LINGYUN/Abp/Saas/Localization/Resources/zh-Hans.json

@ -50,6 +50,7 @@
"Features:ExpiredRecoveryTimeDesc": "当资源超期多久没有处理, 将回收租户资源",
"UnActived": "未启用",
"RecycleStrategy:Reserve": "保留",
"RecycleStrategy:Recycle": "回收"
"RecycleStrategy:Recycle": "回收",
"IfUseCustomDataBaseDefaultConnectionStringIsRequiredMessage": "如果使用自定义数据库,默认连接字符串必须输入!"
}
}

4
aspnet-core/modules/saas/LINGYUN.Abp.Saas.EntityFrameworkCore/LINGYUN/Abp/Saas/EntityFrameworkCore/EfCoreTenantRepository.cs

@ -70,7 +70,7 @@ public class EfCoreTenantRepository : EfCoreRepository<ISaasDbContext, Tenant, G
var queryable = from tenant in tenantDbSet
join edition in editionDbSet on tenant.EditionId equals edition.Id into eg
from e in eg.DefaultIfEmpty()
where tenant.Name.Equals(name)
where tenant.Name.Equals(name) || tenant.NormalizedName.Equals(name)
orderby tenant.Id
select new
{
@ -104,7 +104,7 @@ public class EfCoreTenantRepository : EfCoreRepository<ISaasDbContext, Tenant, G
var queryable = from tenant in tenantDbSet
join edition in editionDbSet on tenant.EditionId equals edition.Id into eg
from e in eg.DefaultIfEmpty()
where tenant.Name.Equals(name)
where tenant.Name.Equals(name) || tenant.NormalizedName.Equals(name)
orderby tenant.Id
select new
{

2
aspnet-core/modules/saas/LINGYUN.Abp.Saas.HttpApi/LINGYUN/Abp/Saas/Tenants/TenantController.cs

@ -83,7 +83,7 @@ public class TenantController : AbpSaasControllerBase, ITenantAppService
[HttpPut]
[Route("{id}/connection-string")]
[Authorize(AbpSaasPermissions.Tenants.ManageConnectionStrings)]
public virtual Task<TenantConnectionStringDto> SetConnectionStringAsync(Guid id, TenantConnectionStringCreateOrUpdate input)
public virtual Task<TenantConnectionStringDto> SetConnectionStringAsync(Guid id, TenantConnectionStringSetInput input)
{
return TenantAppService.SetConnectionStringAsync(id, input);
}

Loading…
Cancel
Save