Fixes distributed lock record creation issue if already exists.

Fixes #6784
This commit is contained in:
jtkech
2016-04-20 18:00:03 +02:00
committed by Sebastien Ros
parent b8e138b2d5
commit 43e1040661

View File

@@ -148,8 +148,11 @@ namespace Orchard.Tasks.Locking.Services {
// No record matched the criteria, but at least one expired record with the specified name was found.
// Delete the expired records before creating a new one. In theory no more than one record can exist
// due to the unique key constraint on the 'Name' column, it won't hurt to work on a collection.
foreach (var expiredRecord in records) {
repository.Delete(expiredRecord);
if (records.Any()) {
foreach (var expiredRecord in records) {
repository.Delete(expiredRecord);
}
repository.Flush();
}
// No valid record existed, so we're good to create a new one.
@@ -220,4 +223,4 @@ namespace Orchard.Tasks.Locking.Services {
return String.Format("DistributedLock:{0}:{1}", _shellSettings.Name, name);
}
}
}
}