Browse Source

Merge pull request #1616 from colinin/blob-exists

refactor(blobmanagement): Scope the blob existence check by container id
pull/1626/head
i2nets 1 month ago
committed by GitHub
parent
commit
e36b3fc0c3
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 3
      aspnet-core/modules/blob-management/LINGYUN.Abp.BlobManagement.Application/LINGYUN/Abp/BlobManagement/Integration/BlobIntegrationService.cs
  2. 2
      aspnet-core/modules/blob-management/LINGYUN.Abp.BlobManagement.Domain/LINGYUN/Abp/BlobManagement/IBlobRepository.cs
  3. 12
      aspnet-core/modules/blob-management/LINGYUN.Abp.BlobManagement.EntityFrameworkCore/LINGYUN/Abp/BlobManagement/EntityFrameworkCore/EfCoreBlobRepository.cs

3
aspnet-core/modules/blob-management/LINGYUN.Abp.BlobManagement.Application/LINGYUN/Abp/BlobManagement/Integration/BlobIntegrationService.cs

@ -83,7 +83,8 @@ public class BlobIntegrationService : BlobAppServiceBase, IBlobIntegrationServic
try
{
var blobName = HttpUtility.UrlDecode(input.BlobName);
return await BlobRepository.ExistsAsync(input.ContainerName, blobName);
var blobContainer = await BlobContainerRepository.GetByNameAsync(BlobManager.GetBlobProvider(), input.ContainerName);
return await BlobRepository.ExistsAsync(blobName, blobContainer.Id);
}
catch (Exception ex)
{

2
aspnet-core/modules/blob-management/LINGYUN.Abp.BlobManagement.Domain/LINGYUN/Abp/BlobManagement/IBlobRepository.cs

@ -10,8 +10,8 @@ namespace LINGYUN.Abp.BlobManagement;
public interface IBlobRepository : IBasicRepository<Blob, Guid>
{
Task<bool> ExistsAsync(
string containerName,
string fullName,
Guid? containerId = null,
CancellationToken cancellationToken = default);
Task<Blob?> FindByNameAsync(

12
aspnet-core/modules/blob-management/LINGYUN.Abp.BlobManagement.EntityFrameworkCore/LINGYUN/Abp/BlobManagement/EntityFrameworkCore/EfCoreBlobRepository.cs

@ -20,17 +20,13 @@ public class EfCoreBlobRepository : EfCoreRepository<IBlobManagementDbContext, B
}
public async virtual Task<bool> ExistsAsync(
string containerName,
string fullName,
Guid? containerId = null,
CancellationToken cancellationToken = default)
{
var dbContext = await GetDbContextAsync();
return await (from container in dbContext.Set<BlobContainer>()
join blob in dbContext.Set<Blob>()
on container.Id equals blob.ContainerId
where container.Name == containerName && blob.FullName == fullName
select blob)
return await (await GetQueryableAsync())
.Where(x => x.FullName == fullName)
.WhereIf(containerId.HasValue, x => x.ContainerId == containerId)
.AnyAsync(GetCancellationToken(cancellationToken));
}

Loading…
Cancel
Save