Resolved #4296: DatabaseBlobProvider auto save changes.

pull/4308/head
Halil İbrahim Kalkan 5 years ago
parent dff6d79036
commit 2414fb1ddb

@ -26,8 +26,11 @@ namespace Volo.Abp.BlobStoring.Database
{
var container = await GetOrCreateContainerAsync(args.ContainerName, args.CancellationToken);
var blob = await DatabaseBlobRepository.FindAsync(container.Id, args.BlobName,
args.CancellationToken);
var blob = await DatabaseBlobRepository.FindAsync(
container.Id,
args.BlobName,
args.CancellationToken
);
var content = await args.BlobStream.GetAllBytesAsync(args.CancellationToken);
@ -40,58 +43,72 @@ namespace Volo.Abp.BlobStoring.Database
}
blob.SetContent(content);
await DatabaseBlobRepository.UpdateAsync(blob);
await DatabaseBlobRepository.UpdateAsync(blob, autoSave: true);
}
else
{
blob = new DatabaseBlob(GuidGenerator.Create(), container.Id, args.BlobName, content);
await DatabaseBlobRepository.InsertAsync(blob);
await DatabaseBlobRepository.InsertAsync(blob, autoSave: true);
}
}
public override async Task<bool> DeleteAsync(BlobProviderDeleteArgs args)
{
var container =
await DatabaseBlobContainerRepository.FindAsync(args.ContainerName,
args.CancellationToken);
var container = await DatabaseBlobContainerRepository.FindAsync(
args.ContainerName,
args.CancellationToken
);
if (container == null)
{
return false;
}
return await DatabaseBlobRepository.DeleteAsync(container.Id, args.BlobName,
args.CancellationToken);
return await DatabaseBlobRepository.DeleteAsync(
container.Id,
args.BlobName,
autoSave: true,
cancellationToken: args.CancellationToken
);
}
public override async Task<bool> ExistsAsync(BlobProviderExistsArgs args)
{
var container =
await DatabaseBlobContainerRepository.FindAsync(args.ContainerName,
args.CancellationToken);
var container = await DatabaseBlobContainerRepository.FindAsync(
args.ContainerName,
args.CancellationToken
);
if (container == null)
{
return false;
}
return await DatabaseBlobRepository.ExistsAsync(container.Id, args.BlobName,
args.CancellationToken);
return await DatabaseBlobRepository.ExistsAsync(
container.Id,
args.BlobName,
args.CancellationToken
);
}
public override async Task<Stream> GetOrNullAsync(BlobProviderGetArgs args)
{
var container =
await DatabaseBlobContainerRepository.FindAsync(args.ContainerName,
args.CancellationToken);
var container = await DatabaseBlobContainerRepository.FindAsync(
args.ContainerName,
args.CancellationToken
);
if (container == null)
{
return null;
}
var blob = await DatabaseBlobRepository.FindAsync(container.Id, args.BlobName,
args.CancellationToken);
var blob = await DatabaseBlobRepository.FindAsync(
container.Id,
args.BlobName,
args.CancellationToken
);
if (blob == null)
{

@ -12,6 +12,6 @@ namespace Volo.Abp.BlobStoring.Database
Task<bool> ExistsAsync(Guid containerId, [NotNull] string name, CancellationToken cancellationToken = default);
Task<bool> DeleteAsync(Guid containerId, [NotNull] string name, CancellationToken cancellationToken = default);
Task<bool> DeleteAsync(Guid containerId, [NotNull] string name, bool autoSave = false, CancellationToken cancellationToken = default);
}
}

@ -7,9 +7,10 @@ using Volo.Abp.EntityFrameworkCore;
namespace Volo.Abp.BlobStoring.Database.EntityFrameworkCore
{
public class EfCoreDatabaseBlobRepository : EfCoreRepository<IBlobStoringDbContext, DatabaseBlob, Guid>, IDatabaseBlobRepository
public class EfCoreDatabaseBlobRepository : EfCoreRepository<IBlobStoringDbContext, DatabaseBlob, Guid>,
IDatabaseBlobRepository
{
public EfCoreDatabaseBlobRepository(IDbContextProvider<IBlobStoringDbContext> dbContextProvider)
public EfCoreDatabaseBlobRepository(IDbContextProvider<IBlobStoringDbContext> dbContextProvider)
: base(dbContextProvider)
{
}
@ -38,15 +39,18 @@ namespace Volo.Abp.BlobStoring.Database.EntityFrameworkCore
public virtual async Task<bool> DeleteAsync(
Guid containerId,
string name,
bool autoSave = false,
CancellationToken cancellationToken = default)
{
//TODO: Should extract this logic to out of the repository and remove this method completely
var blob = await FindAsync(containerId, name, cancellationToken);
if (blob == null)
{
return false;
}
await base.DeleteAsync(blob.Id, cancellationToken: GetCancellationToken(cancellationToken));
await base.DeleteAsync(blob, autoSave, cancellationToken: GetCancellationToken(cancellationToken));
return true;
}
}

@ -29,7 +29,11 @@ namespace Volo.Abp.BlobStoring.Database.MongoDB
GetCancellationToken(cancellationToken));
}
public virtual async Task<bool> DeleteAsync(Guid containerId, string name, CancellationToken cancellationToken = default)
public virtual async Task<bool> DeleteAsync(
Guid containerId,
string name,
bool autoSave = false,
CancellationToken cancellationToken = default)
{
var blob = await FindAsync(containerId, name, cancellationToken);
@ -38,7 +42,7 @@ namespace Volo.Abp.BlobStoring.Database.MongoDB
return false;
}
await base.DeleteAsync(blob, cancellationToken: GetCancellationToken(cancellationToken));
await base.DeleteAsync(blob, autoSave, cancellationToken: GetCancellationToken(cancellationToken));
return true;
}
}

Loading…
Cancel
Save