From 023f297ad782c210d9620541f5b7a393a7fba263 Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Tue, 26 Nov 2024 17:55:24 -0800 Subject: [PATCH 1/2] Replace unnecesary calls to SaveChangesAsync by FlushAsync --- .editorconfig | 1 + .../OrchardCore.Html/Migrations.cs | 2 +- .../OrchardCore.Title/Migrations.cs | 2 +- .../YesSql/Stores/OpenIdApplicationStore.cs | 4 ++-- .../YesSql/Stores/OpenIdAuthorizationStore.cs | 8 ++++---- .../YesSql/Stores/OpenIdScopeStore.cs | 6 +++--- .../YesSql/Stores/OpenIdTokenStore.cs | 10 +++++----- .../OrchardCore.Users.Core/Services/UserStore.cs | 11 +++-------- .../Apis/GraphQL/ContentItemsFieldTypeTests.cs | 2 -- .../Decriptors/DefaultShapeTableManagerTests.cs | 2 -- 10 files changed, 20 insertions(+), 28 deletions(-) diff --git a/.editorconfig b/.editorconfig index bbb5af24d58..1948bc0d730 100644 --- a/.editorconfig +++ b/.editorconfig @@ -83,6 +83,7 @@ dotnet_diagnostic.IDE0130.severity = silent # Na dotnet_style_prefer_conditional_expression_over_assignment = silent # Remove redundant equality, e.g. Disabled == false dotnet_diagnostic.CA2263.severity = warning # Prefer generic overload when type is known +dotnet_diagnostic.CA1816.severity = none # Dispose methods should call SuppressFinalize # Sort using and Import directives with System.* appearing first dotnet_sort_system_directives_first = true diff --git a/src/OrchardCore.Modules/OrchardCore.Html/Migrations.cs b/src/OrchardCore.Modules/OrchardCore.Html/Migrations.cs index bcd352f7416..7513f0f12b9 100644 --- a/src/OrchardCore.Modules/OrchardCore.Html/Migrations.cs +++ b/src/OrchardCore.Modules/OrchardCore.Html/Migrations.cs @@ -91,7 +91,7 @@ public async Task UpdateFrom3Async() lastDocumentId = contentItemVersion.Id; } - await _session.SaveChangesAsync(); + await _session.FlushAsync(); } static bool UpdateBody(JsonNode content) diff --git a/src/OrchardCore.Modules/OrchardCore.Title/Migrations.cs b/src/OrchardCore.Modules/OrchardCore.Title/Migrations.cs index 2d5e1b73d57..e2cbf1b5e6b 100644 --- a/src/OrchardCore.Modules/OrchardCore.Title/Migrations.cs +++ b/src/OrchardCore.Modules/OrchardCore.Title/Migrations.cs @@ -68,7 +68,7 @@ public async Task UpdateFrom1() lastDocumentId = contentItemVersion.Id; } - await _session.SaveChangesAsync(); + await _session.FlushAsync(); } static bool UpdateTitle(JsonNode content) diff --git a/src/OrchardCore/OrchardCore.OpenId.Core/YesSql/Stores/OpenIdApplicationStore.cs b/src/OrchardCore/OrchardCore.OpenId.Core/YesSql/Stores/OpenIdApplicationStore.cs index f1dabda01ad..02ab4d0e5c2 100644 --- a/src/OrchardCore/OrchardCore.OpenId.Core/YesSql/Stores/OpenIdApplicationStore.cs +++ b/src/OrchardCore/OrchardCore.OpenId.Core/YesSql/Stores/OpenIdApplicationStore.cs @@ -50,7 +50,7 @@ public virtual async ValueTask CreateAsync(TApplication application, Cancellatio cancellationToken.ThrowIfCancellationRequested(); await _session.SaveAsync(application, collection: OpenIdCollection); - await _session.SaveChangesAsync(); + await _session.FlushAsync(); } /// @@ -61,7 +61,7 @@ public virtual async ValueTask DeleteAsync(TApplication application, Cancellatio cancellationToken.ThrowIfCancellationRequested(); _session.Delete(application, collection: OpenIdCollection); - await _session.SaveChangesAsync(); + await _session.FlushAsync(); } /// diff --git a/src/OrchardCore/OrchardCore.OpenId.Core/YesSql/Stores/OpenIdAuthorizationStore.cs b/src/OrchardCore/OrchardCore.OpenId.Core/YesSql/Stores/OpenIdAuthorizationStore.cs index d48974c4f7d..040915ef6be 100644 --- a/src/OrchardCore/OrchardCore.OpenId.Core/YesSql/Stores/OpenIdAuthorizationStore.cs +++ b/src/OrchardCore/OrchardCore.OpenId.Core/YesSql/Stores/OpenIdAuthorizationStore.cs @@ -44,7 +44,7 @@ public virtual async ValueTask CreateAsync(TAuthorization authorization, Cancell cancellationToken.ThrowIfCancellationRequested(); await _session.SaveAsync(authorization, collection: OpenIdCollection); - await _session.SaveChangesAsync(); + await _session.FlushAsync(); } /// @@ -55,7 +55,7 @@ public virtual async ValueTask DeleteAsync(TAuthorization authorization, Cancell cancellationToken.ThrowIfCancellationRequested(); _session.Delete(authorization, collection: OpenIdCollection); - await _session.SaveChangesAsync(); + await _session.FlushAsync(); } /// @@ -319,7 +319,7 @@ public virtual async ValueTask PruneAsync(DateTimeOffset threshold, Cancel try { - await _session.SaveChangesAsync(); + await _session.FlushAsync(); } catch (Exception exception) { @@ -440,7 +440,7 @@ public virtual async ValueTask UpdateAsync(TAuthorization authorization, Cancell try { - await _session.SaveChangesAsync(); + await _session.FlushAsync(); } catch (ConcurrencyException exception) { diff --git a/src/OrchardCore/OrchardCore.OpenId.Core/YesSql/Stores/OpenIdScopeStore.cs b/src/OrchardCore/OrchardCore.OpenId.Core/YesSql/Stores/OpenIdScopeStore.cs index 2173cf8f254..02893d1e8de 100644 --- a/src/OrchardCore/OrchardCore.OpenId.Core/YesSql/Stores/OpenIdScopeStore.cs +++ b/src/OrchardCore/OrchardCore.OpenId.Core/YesSql/Stores/OpenIdScopeStore.cs @@ -43,7 +43,7 @@ public virtual async ValueTask CreateAsync(TScope scope, CancellationToken cance cancellationToken.ThrowIfCancellationRequested(); await _session.SaveAsync(scope, collection: OpenIdCollection); - await _session.SaveChangesAsync(); + await _session.FlushAsync(); } /// @@ -54,7 +54,7 @@ public virtual async ValueTask DeleteAsync(TScope scope, CancellationToken cance cancellationToken.ThrowIfCancellationRequested(); _session.Delete(scope, collection: OpenIdCollection); - await _session.SaveChangesAsync(); + await _session.FlushAsync(); } /// @@ -326,7 +326,7 @@ public virtual async ValueTask UpdateAsync(TScope scope, CancellationToken cance try { - await _session.SaveChangesAsync(); + await _session.FlushAsync(); } catch (ConcurrencyException exception) { diff --git a/src/OrchardCore/OrchardCore.OpenId.Core/YesSql/Stores/OpenIdTokenStore.cs b/src/OrchardCore/OrchardCore.OpenId.Core/YesSql/Stores/OpenIdTokenStore.cs index eaa3c46165d..8c09a9b6db4 100644 --- a/src/OrchardCore/OrchardCore.OpenId.Core/YesSql/Stores/OpenIdTokenStore.cs +++ b/src/OrchardCore/OrchardCore.OpenId.Core/YesSql/Stores/OpenIdTokenStore.cs @@ -44,7 +44,7 @@ public virtual async ValueTask CreateAsync(TToken token, CancellationToken cance cancellationToken.ThrowIfCancellationRequested(); await _session.SaveAsync(token, collection: OpenIdCollection); - await _session.SaveChangesAsync(); + await _session.FlushAsync(); } /// @@ -55,7 +55,7 @@ public virtual async ValueTask DeleteAsync(TToken token, CancellationToken cance cancellationToken.ThrowIfCancellationRequested(); _session.Delete(token, collection: OpenIdCollection); - await _session.SaveChangesAsync(); + await _session.FlushAsync(); } /// @@ -354,7 +354,7 @@ public virtual async ValueTask PruneAsync(DateTimeOffset threshold, Cancel try { - await _session.SaveChangesAsync(); + await _session.FlushAsync(); } catch (Exception exception) { @@ -399,7 +399,7 @@ public virtual async ValueTask RevokeByAuthorizationIdAsync(string identif await _session.SaveAsync(token, checkConcurrency: false, collection: OpenIdCollection); } - await _session.SaveChangesAsync(); + await _session.FlushAsync(); return tokens.Count; } @@ -546,7 +546,7 @@ public virtual async ValueTask UpdateAsync(TToken token, CancellationToken cance try { - await _session.SaveChangesAsync(); + await _session.FlushAsync(); } catch (ConcurrencyException exception) { diff --git a/src/OrchardCore/OrchardCore.Users.Core/Services/UserStore.cs b/src/OrchardCore/OrchardCore.Users.Core/Services/UserStore.cs index 741ca54072a..0fc5d116ccc 100644 --- a/src/OrchardCore/OrchardCore.Users.Core/Services/UserStore.cs +++ b/src/OrchardCore/OrchardCore.Users.Core/Services/UserStore.cs @@ -56,11 +56,6 @@ public UserStore(ISession session, public IEnumerable Handlers { get; private set; } - public void Dispose() - { - GC.SuppressFinalize(this); - } - public string NormalizeKey(string key) { return _keyNormalizer == null ? key : _keyNormalizer.NormalizeName(key); @@ -111,7 +106,7 @@ public async Task CreateAsync(IUser user, CancellationToken canc } await _session.SaveAsync(user); - await _session.SaveChangesAsync(); + await _session.FlushAsync(); await Handlers.InvokeAsync((handler, context) => handler.CreatedAsync(context), context, _logger); } catch (Exception e) @@ -139,7 +134,7 @@ public async Task DeleteAsync(IUser user, CancellationToken canc } _session.Delete(user); - await _session.SaveChangesAsync(); + await _session.FlushAsync(); await Handlers.InvokeAsync((handler, context) => handler.DeletedAsync(context), context, _logger); } catch (Exception e) @@ -232,7 +227,7 @@ public async Task UpdateAsync(IUser user, CancellationToken canc } await _session.SaveAsync(user); - await _session.SaveChangesAsync(); + await _session.FlushAsync(); await Handlers.InvokeAsync((handler, context) => handler.UpdatedAsync(context), context, _logger); } catch (Exception e) diff --git a/test/OrchardCore.Tests/Apis/GraphQL/ContentItemsFieldTypeTests.cs b/test/OrchardCore.Tests/Apis/GraphQL/ContentItemsFieldTypeTests.cs index a0da2bb775d..141aa7400a3 100644 --- a/test/OrchardCore.Tests/Apis/GraphQL/ContentItemsFieldTypeTests.cs +++ b/test/OrchardCore.Tests/Apis/GraphQL/ContentItemsFieldTypeTests.cs @@ -648,9 +648,7 @@ public void Build() _inner = _services.BuildServiceProvider(); } -#pragma warning disable CA1816 // Dispose methods should call SuppressFinalize public void Dispose() -#pragma warning restore CA1816 // Dispose methods should call SuppressFinalize { (_inner as IDisposable)?.Dispose(); } diff --git a/test/OrchardCore.Tests/DisplayManagement/Decriptors/DefaultShapeTableManagerTests.cs b/test/OrchardCore.Tests/DisplayManagement/Decriptors/DefaultShapeTableManagerTests.cs index 2d4e5a20cfa..68f881118c3 100644 --- a/test/OrchardCore.Tests/DisplayManagement/Decriptors/DefaultShapeTableManagerTests.cs +++ b/test/OrchardCore.Tests/DisplayManagement/Decriptors/DefaultShapeTableManagerTests.cs @@ -495,9 +495,7 @@ public async Task DerivedThemesCanOverrideBaseThemeShapeBindings() Assert.Equal("DerivedTheme", table.Descriptors["OverriddenShape"].BindingSource); } -#pragma warning disable CA1816 // Dispose methods should call SuppressFinalize public void Dispose() -#pragma warning restore CA1816 // Dispose methods should call SuppressFinalize { (_serviceProvider as IDisposable)?.Dispose(); } From 07116b0daf7b997160a5b815b6fac4c20fd19ff8 Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Tue, 26 Nov 2024 18:13:09 -0800 Subject: [PATCH 2/2] Fix build --- src/OrchardCore/OrchardCore.Users.Core/Services/UserStore.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/OrchardCore/OrchardCore.Users.Core/Services/UserStore.cs b/src/OrchardCore/OrchardCore.Users.Core/Services/UserStore.cs index 0fc5d116ccc..5ed624343ce 100644 --- a/src/OrchardCore/OrchardCore.Users.Core/Services/UserStore.cs +++ b/src/OrchardCore/OrchardCore.Users.Core/Services/UserStore.cs @@ -56,6 +56,10 @@ public UserStore(ISession session, public IEnumerable Handlers { get; private set; } + public void Dispose() + { + } + public string NormalizeKey(string key) { return _keyNormalizer == null ? key : _keyNormalizer.NormalizeName(key);