Hi,
I need to insert 300+ (or more, depending on the # of batches selected) rows of records on grid but the time it consumes is way too long, it takes 10 mins to insert 298 rows, but as I tweaked the code, I was able to lessen it to 8 minutes.
AddProperty Action - This is where I add records to the grid.
public PXAction<REMeterReading> AddProperty;
[PXUIField(DisplayName = REMessages.AddProperty)]
[PXButton()]
public IEnumerable addProperty(PXAdapter adapter)
{
ClearDetails();
if (Filter.AskExt() == WebDialogResult.OK)
{
string[] floors = Filter.Current.Floors.Split(',').Select(_ => _.Trim()).ToArray();
REMeterReading document = MeterReading.Current;
List<REProperty> properties = GetMeterReadingProperties(propertyClassID: document.PropertyClassID,
rateID: document.RateID,
floors: floors);
foreach (REProperty property in properties)
{
REMeterReadingDetail detail = new REMeterReadingDetail();
detail.PropertyID = property.PropertyID;
MeterReadingLines.Insert(detail);
}
Filter.Cache.Clear();
}
return adapter.Get();
}
ClearDetails Method
private void ClearDetails()
{
foreach (REMeterReadingDetail d in MeterReadingLines.Select())
{
MeterReadingLines.Cache.Delete(d);
MeterReadingLines.Cache.IsDirty = true;
}
}
GetMeterReadingProperties Method
private List<REProperty> GetMeterReadingProperties(int? propertyClassID, int? rateID, string[] floors = null)
{
var properties = new PXSelectJoin<REProperty, InnerJoin<REPropertyRateDetail, On<REProperty.propertyID, Equal<REPropertyRateDetail.propertyID>>>,
Where<REProperty.propertyClassID, Equal<Required<REMeterReading.propertyClassID>>,
And<REPropertyRateDetail.rateID, Equal<Required<REMeterReading.rateID>>,
And<REProperty.isSharedUtilities, Equal<True>>>>>(this);
if (!floors.Any())
{
return properties.Select(propertyClassID, rateID).RowCast<REProperty>().AsEnumerable().ToList();
}
properties.WhereAnd(typeof(Where<REProperty.floorNbr, In<Required<REProperty.floorNbr>>>));
return properties.Select(new object[] { propertyClassID, rateID, floors.ToArray() }).RowCast<REProperty>().AsEnumerable().ToList();
}
I am curious about these things:
- What are the things to be considered on adding dynamically adding records on grid?
- Does the defaulting of fields, field calculation affects the row insert? If so, is there a better way to handle these things?
- Also, Is it better to do CacheAttached on fields rather than specifying it early on the DAC?
- What can I do to speed up the insertion of records to the grid
I hope you can give me an advice. Thank you so much and have a nice day.