From fa6d62ffcf896b6892c47ba9932a762c7fad34a7 Mon Sep 17 00:00:00 2001 From: colin Date: Wed, 14 Oct 2026 13:44:39 +0800 Subject: [PATCH] refactor(blobmanagement): Scope the blob existence check by container id Match a blob by its full name and an optional container id instead of joining the container table on every existence check, and resolve the container once in the calling service so the check is scoped to the current blob provider. --- .../Integration/BlobIntegrationService.cs | 3 ++- .../LINGYUN/Abp/BlobManagement/IBlobRepository.cs | 2 +- .../EntityFrameworkCore/EfCoreBlobRepository.cs | 12 ++++-------- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/aspnet-core/modules/blob-management/LINGYUN.Abp.BlobManagement.Application/LINGYUN/Abp/BlobManagement/Integration/BlobIntegrationService.cs b/aspnet-core/modules/blob-management/LINGYUN.Abp.BlobManagement.Application/LINGYUN/Abp/BlobManagement/Integration/BlobIntegrationService.cs index b031ec92c..24d24b483 100644 --- a/aspnet-core/modules/blob-management/LINGYUN.Abp.BlobManagement.Application/LINGYUN/Abp/BlobManagement/Integration/BlobIntegrationService.cs +++ b/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) { diff --git a/aspnet-core/modules/blob-management/LINGYUN.Abp.BlobManagement.Domain/LINGYUN/Abp/BlobManagement/IBlobRepository.cs b/aspnet-core/modules/blob-management/LINGYUN.Abp.BlobManagement.Domain/LINGYUN/Abp/BlobManagement/IBlobRepository.cs index 1577bb3f2..6b011126e 100644 --- a/aspnet-core/modules/blob-management/LINGYUN.Abp.BlobManagement.Domain/LINGYUN/Abp/BlobManagement/IBlobRepository.cs +++ b/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 { Task ExistsAsync( - string containerName, string fullName, + Guid? containerId = null, CancellationToken cancellationToken = default); Task FindByNameAsync( diff --git a/aspnet-core/modules/blob-management/LINGYUN.Abp.BlobManagement.EntityFrameworkCore/LINGYUN/Abp/BlobManagement/EntityFrameworkCore/EfCoreBlobRepository.cs b/aspnet-core/modules/blob-management/LINGYUN.Abp.BlobManagement.EntityFrameworkCore/LINGYUN/Abp/BlobManagement/EntityFrameworkCore/EfCoreBlobRepository.cs index 1456a02e4..b54246385 100644 --- a/aspnet-core/modules/blob-management/LINGYUN.Abp.BlobManagement.EntityFrameworkCore/LINGYUN/Abp/BlobManagement/EntityFrameworkCore/EfCoreBlobRepository.cs +++ b/aspnet-core/modules/blob-management/LINGYUN.Abp.BlobManagement.EntityFrameworkCore/LINGYUN/Abp/BlobManagement/EntityFrameworkCore/EfCoreBlobRepository.cs @@ -20,17 +20,13 @@ public class EfCoreBlobRepository : EfCoreRepository ExistsAsync( - string containerName, string fullName, + Guid? containerId = null, CancellationToken cancellationToken = default) { - var dbContext = await GetDbContextAsync(); - - return await (from container in dbContext.Set() - join blob in dbContext.Set() - 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)); }