Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use CommitAsync() instead od Commit() #14622

Merged
merged 1 commit into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ private async Task FlushAsync(ShellScope scope, IEnumerable<IndexingTask> tasks)
var ids = localQueue.Select(x => x.ContentItemId).ToArray();
var table = $"{session.Store.Configuration.TablePrefix}{nameof(IndexingTask)}";

if (logger.IsEnabled(LogLevel.Debug))
{
logger.LogDebug("Updating indexing tasks: {ContentItemIds}", string.Join(", ", tasks.Select(x => x.ContentItemId)));
}

using var connection = dbConnectionAccessor.CreateConnection();
await connection.OpenAsync();

Expand All @@ -125,11 +130,6 @@ private async Task FlushAsync(ShellScope scope, IEnumerable<IndexingTask> tasks)

try
{
if (logger.IsEnabled(LogLevel.Debug))
{
logger.LogDebug("Updating indexing tasks: {ContentItemIds}", string.Join(", ", tasks.Select(x => x.ContentItemId)));
}

// Page delete statements to prevent the limits from IN sql statements.
var pageSize = 100;

Expand All @@ -139,21 +139,21 @@ private async Task FlushAsync(ShellScope scope, IEnumerable<IndexingTask> tasks)
{
var pageOfIds = ids.Take(pageSize).ToArray();

if (pageOfIds.Any())
if (pageOfIds.Length > 0)
{
await transaction.Connection.ExecuteAsync(deleteCmd, new { Ids = pageOfIds }, transaction);
ids = ids.Skip(pageSize).ToArray();
}
} while (ids.Any());
} while (ids.Length > 0);

var insertCmd = $"insert into {dialect.QuoteForTableName(table, _store.Configuration.Schema)} ({dialect.QuoteForColumnName("CreatedUtc")}, {dialect.QuoteForColumnName("ContentItemId")}, {dialect.QuoteForColumnName("Type")}) values (@CreatedUtc, @ContentItemId, @Type);";
await transaction.Connection.ExecuteAsync(insertCmd, localQueue, transaction);

transaction.Commit();
await transaction.CommitAsync();
}
catch (Exception e)
{
transaction.Rollback();
await transaction.RollbackAsync();
logger.LogError(e, "An error occurred while updating indexing tasks");

throw;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,11 @@ public int Create()

await transaction.Connection.ExecuteAsync(updateCmd, null, transaction);

transaction.Commit();
await transaction.CommitAsync();
}
catch (Exception e)
{
transaction.Rollback();
await transaction.RollbackAsync();
logger.LogError(e, "An error occurred while updating Lucene indices settings and queries");

throw;
Expand Down
9 changes: 4 additions & 5 deletions src/OrchardCore.Modules/OrchardCore.Users/Migrations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,16 +255,15 @@ public int UpdateFrom12()
var documentTableName = session.Store.Configuration.TableNameConvention.GetDocumentTable();
var table = $"{session.Store.Configuration.TablePrefix}{documentTableName}";

logger.LogDebug("Updating User Settings");

using var connection = dbConnectionAccessor.CreateConnection();
await connection.OpenAsync();

using var transaction = connection.BeginTransaction(session.Store.Configuration.IsolationLevel);
var dialect = session.Store.Configuration.SqlDialect;

try
{
logger.LogDebug("Updating User Settings");

var quotedTableName = dialect.QuoteForTableName(table, session.Store.Configuration.Schema);
var quotedContentColumnName = dialect.QuoteForColumnName("Content");
var quotedTypeColumnName = dialect.QuoteForColumnName("Type");
Expand All @@ -273,11 +272,11 @@ public int UpdateFrom12()

await transaction.Connection.ExecuteAsync(updateCmd, null, transaction);

transaction.Commit();
await transaction.CommitAsync();
}
catch (Exception e)
{
transaction.Rollback();
await transaction.RollbackAsync();
logger.LogError(e, "An error occurred while updating User Settings");

throw;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,19 @@ public async Task RemovingAsync(ShellRemovingContext context)
{
await connection.OpenAsync();
using var transaction = connection.BeginTransaction(store.Configuration.IsolationLevel);
try
{
// Remove all tables of this tenant.
shellDbTablesInfo.Configure(transaction, _logger, throwOnError: false);
shellDbTablesInfo.RemoveAllTables();

// Remove all tables of this tenant.
shellDbTablesInfo.Configure(transaction, _logger, throwOnError: false);
shellDbTablesInfo.RemoveAllTables();

transaction.Commit();
await transaction.CommitAsync();
}
catch
{
await transaction.RollbackAsync();
throw;
}
}
}
catch (Exception ex)
Expand Down
Loading