Deadlock problem while updating properties of nodes
I have 1000 nodes in my project and i need to update some of the properties of all nodes. while updating nodes i faced deadlock and some time memory out of bound exception
Here is the sample how i update single node in loop.
int id = fetchNodes.Id;
var contentService = ApplicationContext.Current.Services.ContentService;
var doc = contentService.GetById(id);
if (colbrandID != null && !string.IsNullOrEmpty(ID.ToString()))
doc.SetValue("id", ID.ToString());
if (Name != null && !string.IsNullOrEmpty(Name.ToString()))
doc.SetValue("name", Name.ToString());
contentService.SaveAndPublishWithStatus(doc);
Hi Alex,
Here is my code . I fetching data from a excel and update to nodes
umbraco.NodeFactory.Node nodeC = new umbraco.NodeFactory.Node(nodeNum);
for (int rowNumber = startRow + 1; rowNumber <= currentWorksheet.Dimension.End.Row; rowNumber++)
// read each row from the start of the data (start row + 1 header row) to the end of the spreadsheet.
{
//hotelid
object colHotelID = currentWorksheet.Cells[rowNumber, 1].Value;
object colbrandName = currentWorksheet.Cells[rowNumber, 3].Value != null && currentWorksheet.Cells[rowNumber, 3].Value.ToString() != "" ? currentWorksheet.Cells[rowNumber, 3].Value : "NA";
var fetchNodes = nodeC.ChildrenAsList.Where(x => x.GetProperty("ID") != null && x.GetProperty("ID").Value.ToString() == colHotelID.ToString()).FirstOrDefault();
//int id = childNode.Id;
if (fetchNodes != null)
{
string amexID = (fetchNodes.GetProperty("ID").Value).ToString();
int id = fetchNodes.Id;
var contentService = ApplicationContext.Current.Services.ContentService;
var doc = contentService.GetById(id);
if (colbrandName != null && !string.IsNullOrEmpty(colbrandName.ToString()))
doc.SetValue("brandname", colbrandName.ToString());
contentService.SaveAndPublishWithStatus(doc);
count += 1;
}
}//end of excel; loop
}
Thanks Alex and Ivan your suggestions worked and now i able to update all 1000 nodes at once without any problem. If anyone face same problem please follow both suggestions of Alex and Ivan.
Deadlock problem while updating properties of nodes
I have 1000 nodes in my project and i need to update some of the properties of all nodes. while updating nodes i faced deadlock and some time memory out of bound exception
Here is the sample how i update single node in loop.
int id = fetchNodes.Id; var contentService = ApplicationContext.Current.Services.ContentService; var doc = contentService.GetById(id); if (colbrandID != null && !string.IsNullOrEmpty(ID.ToString()))
doc.SetValue("id", ID.ToString());
Hi Sukhwinder
You don't need to instantiate contentService in a loop, move this line out of the loop:
Can you show all the code you have?
Alex
Hi Sukhwinder,
In my case, when I needed to change a lot of content, I used overload of SaveAndPublishWithStatus method:
Parameter raiseEvents - is optional boolean indicating whether or not to raise events. So if you do not subscribe on save events set it to false.
Try it, maybe it helps you.
Hi Alex, Here is my code . I fetching data from a excel and update to nodes
umbraco.NodeFactory.Node nodeC = new umbraco.NodeFactory.Node(nodeNum); for (int rowNumber = startRow + 1; rowNumber <= currentWorksheet.Dimension.End.Row; rowNumber++) // read each row from the start of the data (start row + 1 header row) to the end of the spreadsheet. { //hotelid object colHotelID = currentWorksheet.Cells[rowNumber, 1].Value;
Hi Sukhwinder
Please, follow the suggestion from Ivan, what version of Umbraco are you using?
Alex
Thanks Alex and Ivan . I used 7.4.3 version of Umbraco. I will follow both the suggestions and notify u people what results i will get.
Also, do not use "umbraco.NodeFactory.Node" class, it's deprecated, use IPublishedContent instead - https://our.umbraco.org/documentation/reference/querying/ipublishedcontent
Thanks Alex and Ivan your suggestions worked and now i able to update all 1000 nodes at once without any problem. If anyone face same problem please follow both suggestions of Alex and Ivan.
Cool, we are glad to help you :)
Be well!
is working on a reply...