Skip to content

Commit

Permalink
Use CommitAsync() instead od Commit() (#14622)
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeAlhayek authored Nov 1, 2023
1 parent 4703bb5 commit 2057046
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 21 deletions.
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

0 comments on commit 2057046

Please sign in to comment.