-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Messages: save blobs in the database instead of in the blob storage (#…
…368) * feat: add PersistMessageBodyInDb migration * feat: update the way of determining whether the message body is already filled * feat: remove the builder.Ignore(a => a.Body) statement * feat: update condition on whether the message body should be filled from blob storage * chore: add required project and package references * test: retrieve message body from blob storage if unavailable in database * test: retrieve message body from blob storage if unavailable in database * feat: remove saving message bodies to blob storage * chore: fix the formatting issues causing the ci/cd test to fail * chore: add project reference needed to use proper TestDataGenerator * fix: await messageRepository.FindMessagesWithIds() to prevent blocking statements * feat: make the Body column nullable and without a default value * chore: extract FillBody logic into a separate method * chore: fix indentation * fix: add missing semicolon * chore: refactor test as per requests in the PR * feat: make the Body column nullable and without a default value in SQL server migration as well * chore: fix the formatting issues causing the ci/cd test to fail * feat: update messages in the database from blob storage on project start if blob storage configuration is present * chore: remove obsolete test * fix: instance BlobStorageOptions to make it possible to run the project when blob storage settings are missing * chore: fix the formatting issues that caused the ci/cd tests fail * chore: move CreateRandomDeviceId() to building blocks for easier access in all modules * chore: add comment to refactor this class so that all necessary methods are contained only in BuildingBlocks.UnitTestTools * chore: remove reference to Devices.Application.Tests * chore: refactor code to match the changes made after requests in the Relationships PR * chore: remove duplicates of methods present in UnitTestTools * chore: update method calls to use unit test tools * chore: fix formatting issues * chore: fix missing indentation * chore: change var name * chore: fix formatting issues --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
eee9155
commit 0d12e2b
Showing
34 changed files
with
2,019 additions
and
1,500 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using Backbone.BuildingBlocks.API.Extensions; | ||
using Backbone.BuildingBlocks.Application.Abstractions.Infrastructure.Persistence.BlobStorage; | ||
using Backbone.Modules.Messages.Application.Infrastructure.Persistence; | ||
using Backbone.Modules.Messages.Infrastructure.Persistence.Database; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace Backbone.ConsumerApi; | ||
|
||
public class MessagesDbContextSeeder : IDbSeeder<MessagesDbContext> | ||
{ | ||
private readonly IBlobStorage? _blobStorage; | ||
private readonly string? _blobRootFolder; | ||
|
||
public MessagesDbContextSeeder(IServiceProvider serviceProvider) | ||
{ | ||
_blobStorage = serviceProvider.GetService<IBlobStorage>(); | ||
_blobRootFolder = serviceProvider.GetService<IOptions<BlobOptions>>()?.Value.RootFolder; | ||
} | ||
|
||
public async Task SeedAsync(MessagesDbContext context) | ||
{ | ||
await FillBodyColumnsFromBlobStorage(context); | ||
} | ||
|
||
private async Task FillBodyColumnsFromBlobStorage(MessagesDbContext context) | ||
{ | ||
// _blobRootFolder is null when blob storage configuration is not provided, meaning the content of database entries should not be loaded from blob storage | ||
if (_blobRootFolder == null) | ||
return; | ||
|
||
// ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract | ||
var messagesWithMissingBody = await context.Messages.Where(m => m.Body == null).ToListAsync(); | ||
|
||
foreach (var message in messagesWithMissingBody) | ||
{ | ||
var blobMessageBody = await _blobStorage.FindAsync(_blobRootFolder, message.Id); | ||
message.LoadBody(blobMessageBody); | ||
context.Messages.Update(message); | ||
} | ||
|
||
await context.SaveChangesAsync(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 1 addition & 19 deletions
20
Modules/Devices/test/Devices.Application.Tests/TestDataGenerator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.