We’ve created a cms scheduled job that processes a queue of operations on meta classes and meta fields. In this job we Create and Delete meta classes and meta fields. We also relate meta fields to meta classes. During the job execution we have an issue where the sql server cpu is getting slammed due to thousands of calls to the following stored procedure per second: mdpsp_sys_LoadMetaFieldListByMetaClassId. The stored proc alone is pretty simple and fast, but what is making this SP execute so often?
We're using the MetaClass and MetaField classes in the Mediachase.MetaDataPlus.Configurator namespace.
Through some debugging we've narrowed it to the following method in the MetaClass class:
private void AddFields(IEnumerable<MetaField> metaFields, int weight)
In this method the following line is responsible for the call to the stored proc mentioned above, because the MetaFields property calls LoadMetaFields().
this.MetaFields.Add(metaField);
Here is our code that is called maybe 300 times during the life of the job
public string CreateMetaFieldRelation(MetaClass metaClass, MetaField metaField)
{
if (metaClass == null)
return "ERROR: Meta class does not exist";
metaClass.AddField(metaField);
return _successMessage;
}