This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

VAF - Is there a way to update/save properties of multiple objects in batches?

Hi,

I'm fairly new to the VAFs but I have encountered this a few times.

[TaskProcessor(MyTaskId, MyTaskType, TransactionMode = TransactionMode.Unsafe, MaxRequeues = 0, MaxRetries = 0)]
[ShowOnDashboard("My Task Processor", ShowRunCommand = true)]
public void MyTaskProcessor(ITaskProcessingJob<TaskDirective> job)
{
	//ID, data
	Dictionary<int, ApiData> apiDataItems = FetchDataFromSomeApi();

	var sb = new MFSearchBuilder(job.Vault)
		.ObjType(Configuration.Structure.Objects.SomeObjType)
		.Class(Configuration.Structure.Classes.SomeClass)
		.PropertyNotMissing(Configuration.Structure.Properties.SomeTextProperty)
		.Deleted(false)
		.IsCheckedOut(false);

	List<ObjVerEx> foundObjects = sb.FindEx();

	foreach (var obj in foundObjects)
	{
		if (apiDataItems.TryGetValue(obj.ID, out var item))
		{
			//Could check here if modified
			obj.SaveProperty(Configuration.Structure.Properties.SomeTextProperty, MFDataType.MFDatatypeText, item.Value);
		}
	}
}

In the example above I have to call SaveProperty which is a pretty slow operation when called multiple times in a row. Is there a way to update properties in batches?

- Eetu

Parents Reply
  • One other note is that you then, perhaps, might run into transactionality issues as you're using an unsafe transaction processor.  You may want to run each batch (e.g. check out 500, update 500, check in 500) inside a transaction using the transaction runner, which will ensure that you don't end up with issues where items are left checked out because of an issue checking them in.

Children