From 58aeb83c41f4b916c6589bec3b0deba24cfc45e6 Mon Sep 17 00:00:00 2001 From: vc-ci Date: Fri, 22 Nov 2024 10:00:23 +0000 Subject: [PATCH 1/2] 3.814.0 --- Directory.Build.props | 2 +- src/VirtoCommerce.CoreModule.Web/module.manifest | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 62bd6801..c4ae814c 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -2,7 +2,7 @@ - 3.813.0 + 3.814.0 $(VersionSuffix)-$(BuildNumber) diff --git a/src/VirtoCommerce.CoreModule.Web/module.manifest b/src/VirtoCommerce.CoreModule.Web/module.manifest index d57b7a42..50b70143 100644 --- a/src/VirtoCommerce.CoreModule.Web/module.manifest +++ b/src/VirtoCommerce.CoreModule.Web/module.manifest @@ -1,7 +1,7 @@ VirtoCommerce.Core - 3.813.0 + 3.814.0 3.853.0 Commerce core module From b73950d465e95393ea02c474746ca026b6c3a24c Mon Sep 17 00:00:00 2001 From: Oleg Zhuk Date: Wed, 11 Dec 2024 16:12:42 +0200 Subject: [PATCH 2/2] VCST-2432: Add global tenant ID option for sequence number generation (#234) feat: Introduced a new `UseGlobalTenantId` property in the `SequenceNumberGeneratorOptions` class to support a global counter across all tenants/stores. By default, false. Set VirtoCommerce:SequenceNumberGenerator:UseGlobalTenantId to true, to enable it. (#234) --- .../Common/SequenceNumberGeneratorOptions.cs | 6 ++++++ .../Services/SequenceNumberGeneratorService.cs | 14 ++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/VirtoCommerce.CoreModule.Core/Common/SequenceNumberGeneratorOptions.cs b/src/VirtoCommerce.CoreModule.Core/Common/SequenceNumberGeneratorOptions.cs index 8b58b037..84356be4 100644 --- a/src/VirtoCommerce.CoreModule.Core/Common/SequenceNumberGeneratorOptions.cs +++ b/src/VirtoCommerce.CoreModule.Core/Common/SequenceNumberGeneratorOptions.cs @@ -10,5 +10,11 @@ public class SequenceNumberGeneratorOptions /// Defines the delay between retries in seconds. /// public int RetryDelay { get; set; } = 5; + + /// + /// Defines usage of the static tenant id instead of store id for generating unique number. + /// Can be useful when you want to have golobal counter for all stores/tenants. + /// + public bool UseGlobalTenantId { get; set; } = false; } } diff --git a/src/VirtoCommerce.CoreModule.Data/Services/SequenceNumberGeneratorService.cs b/src/VirtoCommerce.CoreModule.Data/Services/SequenceNumberGeneratorService.cs index 805a5b0a..9fec7208 100644 --- a/src/VirtoCommerce.CoreModule.Data/Services/SequenceNumberGeneratorService.cs +++ b/src/VirtoCommerce.CoreModule.Data/Services/SequenceNumberGeneratorService.cs @@ -141,7 +141,7 @@ protected virtual RetryPolicy ConfigureRetryPolicy() /// protected virtual int RequestNextCounter(string tenantId, CounterOptions counterOptions) { - var sequenceKey = string.IsNullOrEmpty(tenantId) ? counterOptions.NumberTemplate : $"{tenantId}/{counterOptions.NumberTemplate}"; + var sequenceKey = GetSequenceKey(tenantId, counterOptions); using var repository = _repositoryFactory(); var sequence = repository.Sequences.SingleOrDefault(s => s.ObjectType == sequenceKey); @@ -177,6 +177,16 @@ protected virtual int RequestNextCounter(string tenantId, CounterOptions counter return sequence.Value; } + protected virtual string GetSequenceKey(string tenantId, CounterOptions counterOptions) + { + if(_options.UseGlobalTenantId || string.IsNullOrEmpty(tenantId)) + { + return counterOptions.NumberTemplate; + } + + return $"{tenantId}/{counterOptions.NumberTemplate}"; + } + /// /// Returns true if counter should be reset. /// @@ -193,7 +203,7 @@ protected virtual bool ShouldResetCounter(DateTime lastResetDate, ResetCounterTy return currentUtcDate.Date > lastResetDate.Date; case ResetCounterType.Weekly: // Reset every Monday - int daysUntilTargetDay = ((int)DayOfWeek.Monday - (int)lastResetDate.DayOfWeek + 7) % 7; + var daysUntilTargetDay = ((int)DayOfWeek.Monday - (int)lastResetDate.DayOfWeek + 7) % 7; var nextMondayDate = lastResetDate.Date.AddDays(daysUntilTargetDay); return currentUtcDate >= nextMondayDate; case ResetCounterType.Monthly: