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

Fix Sqlite database locking issue #13246

Merged
merged 5 commits into from
Oct 24, 2022
Merged
Changes from 2 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
31 changes: 18 additions & 13 deletions src/Umbraco.Core/Services/FileService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class FileService : RepositoryService, IFileService
private readonly IShortStringHelper _shortStringHelper;
private readonly IStylesheetRepository _stylesheetRepository;
private readonly ITemplateRepository _templateRepository;
private static readonly object _scopeLock = new();

public FileService(
ICoreScopeProvider uowProvider,
Expand Down Expand Up @@ -361,24 +362,28 @@ public long GetScriptFileSize(string filepath)
template.Content = content;
}

using (ICoreScope scope = ScopeProvider.CreateCoreScope())

using ICoreScope scope = ScopeProvider.CreateCoreScope();
var savingEvent = new TemplateSavingNotification(template, eventMessages, true, contentTypeAlias!);
if (scope.Notifications.PublishCancelable(savingEvent))
{
var savingEvent = new TemplateSavingNotification(template, eventMessages, true, contentTypeAlias!);
if (scope.Notifications.PublishCancelable(savingEvent))
{
scope.Complete();
return OperationResult.Attempt.Fail<OperationResultType, ITemplate>(
OperationResultType.FailedCancelledByEvent, eventMessages, template);
}
scope.Complete();
return OperationResult.Attempt.Fail<OperationResultType, ITemplate>(
OperationResultType.FailedCancelledByEvent, eventMessages, template);
}

// This lock prevents a SQLite locking issue, for more info see: https://github.com/umbraco/Umbraco-CMS/pull/13246
lock (_scopeLock)
{
_templateRepository.Save(template);
scope.Notifications.Publish(
new TemplateSavedNotification(template, eventMessages).WithStateFrom(savingEvent));

Audit(AuditType.Save, userId, template.Id, UmbracoObjectTypes.Template.GetName());
scope.Complete();
}

scope.Notifications.Publish(
new TemplateSavedNotification(template, eventMessages).WithStateFrom(savingEvent));

Audit(AuditType.Save, userId, template.Id, UmbracoObjectTypes.Template.GetName());
scope.Complete();

return OperationResult.Attempt.Succeed<OperationResultType, ITemplate>(
OperationResultType.Success,
eventMessages,
Expand Down