forked from elsa-workflows/elsa-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add compression feature for workflow state data
This update adds a compression feature for workflow state data to reduce storage needs. A compression strategy resolver, None and GZip strategies have been implemented. Migration scripts were also updated, and a superfluous file(s) were removed.
- Loading branch information
1 parent
ff9aa54
commit 0bfebcc
Showing
14 changed files
with
257 additions
and
21 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
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,38 @@ | ||
#!/usr/bin/env zsh | ||
|
||
# Define the modules to update | ||
mods=("Management") | ||
# mods=("Alterations" "Runtime" "Management" "Identity" "Labels") | ||
|
||
# Define the list of providers | ||
providers=("MySql" "SqlServer" "Sqlite" "PostgreSql") | ||
# providers=("SqlServer") | ||
|
||
# Connection strings for each provider | ||
typeset -A connStrings | ||
connStrings=( | ||
MySql "Server=localhost;Port=3306;Database=elsa;User=root;Password=password;" | ||
SqlServer "" | ||
Sqlite "" | ||
PostgreSql "" | ||
) | ||
|
||
# Loop through each module | ||
for module in "${mods[@]}"; do | ||
# Loop through each provider | ||
for provider in "${providers[@]}"; do | ||
providerPath="../src/modules/Elsa.EntityFrameworkCore.$provider" | ||
migrationsPath="Migrations/$module" | ||
|
||
echo "Updating migrations for $provider..." | ||
echo "Provider path: ${providerPath:?}/${migrationsPath}" | ||
echo "Migrations path: $migrationsPath" | ||
echo "Connection string: ${connStrings[$provider]}" | ||
|
||
# 1. Delete the existing migrations folder | ||
rm -rf "${providerPath:?}/${migrationsPath}" | ||
|
||
# 2. Run the migrations command | ||
dotnet ef migrations add Initial -c "$module"ElsaDbContext -p "$providerPath" -o "$migrationsPath" -- --connectionString "${connStrings[$provider]}" | ||
done | ||
done |
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,35 @@ | ||
#!/usr/bin/env zsh | ||
|
||
# Define the modules to update | ||
mods=("Management") | ||
# mods=("Alterations" "Runtime" "Management" "Identity" "Labels") | ||
|
||
# Define the list of providers | ||
providers=("MySql" "SqlServer" "Sqlite" "PostgreSql") | ||
# providers=("SqlServer") | ||
|
||
# Connection strings for each provider | ||
typeset -A connStrings | ||
connStrings=( | ||
MySql "Server=localhost;Port=3306;Database=elsa;User=root;Password=password;" | ||
SqlServer "" | ||
Sqlite "" | ||
PostgreSql "" | ||
) | ||
|
||
# Loop through each module | ||
for module in "${mods[@]}"; do | ||
# Loop through each provider | ||
for provider in "${providers[@]}"; do | ||
providerPath="../src/modules/Elsa.EntityFrameworkCore.$provider" | ||
migrationsPath="Migrations/$module" | ||
|
||
echo "Updating migrations for $provider..." | ||
echo "Provider path: ${providerPath:?}/${migrationsPath}" | ||
echo "Migrations path: $migrationsPath" | ||
echo "Connection string: ${connStrings[$provider]}" | ||
|
||
# 1. Run the migrations command | ||
dotnet ef migrations add 3_1 -c "$module"ElsaDbContext -p "$providerPath" -o "$migrationsPath" -- --connectionString "${connStrings[$provider]}" | ||
done | ||
done |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System.IO.Compression; | ||
using System.Text; | ||
using Elsa.Workflows.Management.Contracts; | ||
|
||
namespace Elsa.Workflows.Management.Compression; | ||
|
||
/// <summary> | ||
/// Represents a GZip compression strategy. | ||
/// </summary> | ||
public class GZip : ICompressionStrategy | ||
{ | ||
/// <inheritdoc /> | ||
public async ValueTask<string> CompressAsync(string input, CancellationToken cancellationToken) | ||
{ | ||
var inputBytes = Encoding.UTF8.GetBytes(input); | ||
using var output = new MemoryStream(); | ||
await using var compressionStream = new GZipStream(output, CompressionMode.Compress); | ||
await compressionStream.WriteAsync(inputBytes, 0, inputBytes.Length, cancellationToken); | ||
|
||
return Convert.ToBase64String(output.ToArray()); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public async ValueTask<string> DecompressAsync(string input, CancellationToken cancellationToken) | ||
{ | ||
var inputBytes = Convert.FromBase64String(input); | ||
using var inputMemoryStream = new MemoryStream(inputBytes); | ||
await using var decompressionStream = new GZipStream(inputMemoryStream, CompressionMode.Decompress); | ||
using var outputMemoryStream = new MemoryStream(); | ||
|
||
await decompressionStream.CopyToAsync(outputMemoryStream, cancellationToken); | ||
var decompressedBytes = outputMemoryStream.ToArray(); | ||
|
||
return Encoding.UTF8.GetString(decompressedBytes); | ||
} | ||
} |
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,21 @@ | ||
using Elsa.Workflows.Management.Contracts; | ||
|
||
namespace Elsa.Workflows.Management.Compression; | ||
|
||
/// <summary> | ||
/// Represents a compression strategy that does not compress or decompress the input. | ||
/// </summary> | ||
public class None : ICompressionStrategy | ||
{ | ||
/// <inheritdoc /> | ||
public ValueTask<string> CompressAsync(string input, CancellationToken cancellationToken) | ||
{ | ||
return new ValueTask<string>(input); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public ValueTask<string> DecompressAsync(string input, CancellationToken cancellationToken) | ||
{ | ||
return new ValueTask<string>(input); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/modules/Elsa.Workflows.Management/Contracts/ICompressionStrategy.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
namespace Elsa.Workflows.Management.Contracts; | ||
|
||
/// <summary> | ||
/// Represents a compression strategy. | ||
/// </summary> | ||
public interface ICompressionStrategy | ||
{ | ||
/// <summary> | ||
/// Compresses the input. | ||
/// </summary> | ||
ValueTask<string> CompressAsync(string input, CancellationToken cancellationToken); | ||
|
||
/// <summary> | ||
/// Decompresses the input. | ||
/// </summary> | ||
/// <param name="input"></param> | ||
/// <param name="cancellationToken"></param> | ||
/// <returns></returns> | ||
ValueTask<string> DecompressAsync(string input, CancellationToken cancellationToken); | ||
} |
12 changes: 12 additions & 0 deletions
12
src/modules/Elsa.Workflows.Management/Contracts/ICompressionStrategyResolver.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace Elsa.Workflows.Management.Contracts; | ||
|
||
/// <summary> | ||
/// Resolves a <see cref="ICompressionStrategy"/> from its name. | ||
/// </summary> | ||
public interface ICompressionStrategyResolver | ||
{ | ||
/// <summary> | ||
/// Resolves a <see cref="ICompressionStrategy"/> from its name. | ||
/// </summary> | ||
ICompressionStrategy Resolve(string name); | ||
} |
Oops, something went wrong.