[英]NetSuite restlet write performance is poor
Edit: I've redacted actual numbers and replaced them with pseudoswears because I've been told sharing performance data is against Netsuite's TOS.编辑:我已经编辑了实际数字并用伪誓言替换了它们,因为我被告知共享性能数据违反了 Netsuite 的 TOS。
I'm integrating our accounting system with NetSuite using restlets, and overall it has gone pretty well with the glaring exception of performance.我正在使用 restlets 将我们的会计系统与 NetSuite 集成,总体而言,除了性能方面的明显异常外,它进展顺利。 I have figured out that nlapiLoadRecord is Satan's own child from a performance perspective, so I avoid it whenever possible favoring the search api and now my read restlets are pretty snappy.从性能的角度来看,我已经发现 nlapiLoadRecord 是撒旦自己的孩子,所以我尽可能避免使用它,有利于搜索 api,现在我的 readrestlets 非常活泼。 However, whenever I ask a restlet to write anything it is as slow as a tortoise stuck in cold tar.然而,每当我让restlet写任何东西时,它就像一只困在冷焦油中的乌龟一样慢。 I'm generally profiling the nlapiSubmitRecord itself at between SLOW and REALLY DAMN SLOW seconds.我通常在SLOW和REALLY DAMN SLOW秒之间分析 nlapiSubmitRecord 本身。 This seems insane to me.这对我来说似乎很疯狂。 No one would use NetSuite if the performance were always this poor for writing.如果编写性能总是如此糟糕,那么没有人会使用 NetSuite。 I'll include a couple of code examples below.我将在下面包含几个代码示例。 Any tips on speeding up NetSuite restlet write performance would be appreciated.任何有关加快 NetSuite restlet 写入性能的提示将不胜感激。
In this first one receivedInvoice is the incoming data, and findCurrencyCode and findCustomerByCustomerNumber are well performing functions that do those things.在这第一个 receivedInvoice 是传入数据, findCurrencyCode 和 findCustomerByCustomerNumber 是执行这些操作的性能良好的函数。 I just clocked this at a nearly unbelievable HOLY MONKEYS THAT IS SLOW seconds for a simple invoice with one line item, nearly all of the time passing while I waited for nlapiSubmitRecord to finish.我刚刚在一个几乎令人难以置信的HOLY MONKEYS计时,对于一个带有一个行项目的简单发票,几乎所有的时间都在等待 nlapiSubmitRecord 完成。
var createdInvoice = nlapiCreateRecord('invoice');
createdInvoice.setFieldValue('customform', Number(receivedInvoice.transactionType));
createdInvoice.setFieldValue('memo', receivedInvoice.message);
createdInvoice.setFieldValue('duedate', receivedInvoice.dateDue);
createdInvoice.setFieldValue('currency', findCurrencyCode(receivedInvoice.currencyUnit));
createdInvoice.setFieldValue('location', Number(receivedInvoice.location));
createdInvoice.setFieldValue('postingperiod', findPostingPeriod(receivedInvoice.datePosted));
var customer = findCustomerByCustomerNumber(receivedInvoice.customerNumber);
createdInvoice.setFieldValue('entity', customer.customerId );
createdInvoice.setFieldValue('custbody_end_user', customer.customerId );
createdInvoice.setFieldValue('department', customer.departmentId);
var itemCount = receivedInvoice.items.length;
for(var i = 0; i < itemCount; i++)
{
createdInvoice.selectNewLineItem('item');
createdInvoice.setCurrentLineItemValue('item', 'item',receivedInvoice.items[i].item);
createdInvoice.setCurrentLineItemValue('item', 'quantity', receivedInvoice.items[i].quantity);
createdInvoice.setCurrentLineItemValue('item', 'rate',receivedInvoice.items[i].price);
createdInvoice.setCurrentLineItemValue('item', 'custcol_list_rate',receivedInvoice.items[i].price);
createdInvoice.setCurrentLineItemValue('item', 'amount',receivedInvoice.items[i].totalAmount);
createdInvoice.setCurrentLineItemValue('item', 'description',receivedInvoice.items[i].description);
createdInvoice.commitLineItem('item');
}
var recordNumber = nlapiSubmitRecord(createdInvoice,false,true);
In this one I think I'm committing a performance heresy by opening the record in dynamic mode, but I'm not sure how else to get the possible line items.在这个中,我认为我通过在动态模式下打开记录来犯下性能异端,但我不确定如何获取可能的行项目。 Simply opening a new record in dynamic mode clocks in at around SLOW seconds.只需在大约SLOW秒内在动态模式下打开新记录即可。 Again, the submit is where most time is being eaten (often around OH DEAR SWEET MOTHER OF HORRIBLE seconds), although this one eats a decent amount of time as I mess with the line items, again presumably because I have opened the record in dynamic mode.再次,提交是大部分时间被消耗的地方(通常在OH DEAR SWEET MOTHER OF HORRIBLE几秒左右),尽管当我把订单项弄得一团糟时,这一次消耗了相当多的时间,这大概是因为我已经打开了动态记录模式。
var customerPayment = nlapiCreateRecord('customerpayment',{recordmode: 'dynamic'});
customerPayment.setFieldValue('customer', parseInt(customerId));
customerPayment.setFieldValue('payment', paymentAmount);
customerPayment.setFieldValue('paymentmethod', paymentMethod);
customerPayment.setFieldValue('checknum', transactionId);
customerPayment.setFieldValue('currency', currency);
customerPayment.setFieldValue('account', account);
var applyCount = customerPayment.getLineItemCount('apply');
if(applyCount>0)
{
for(var i=1;i<=applyCount;i++)
{
var thisInvoice = customerPayment.getLineItemValue('apply','refnum',i);
if(thisInvoice == invoiceToPay)
{
customerPayment.selectLineItem('apply', i);
customerPayment.setCurrentLineItemValue('apply','apply','T');
customerPayment.setCurrentLineItemValue('apply', 'amount',paymentAmount);
customerPayment.commitLineItem('apply');
}
}
}
nlapiSubmitRecord(customerPayment,false,true);
A few thoughts:一些想法:
Also notes on your code.还要注意您的代码。
The normal way to create an invoice is创建发票的正常方法是
nlapiTransformRecord('customer', customer.customerId, 'invoice');
or nlapiTransformRecord('customer', customer.customerId, 'invoice', {recordmode:'dynamic'});
或nlapiTransformRecord('customer', customer.customerId, 'invoice', {recordmode:'dynamic'});
I've never tested whether this has an effect on submit times but it might help since NS will start the save from a slightly better place (grasping at straws but with NS sometimes non-obvious changes have speed benefits)我从来没有测试过这是否对提交时间有影响,但它可能会有所帮助,因为 NS 会从一个稍微好一点的地方开始保存(抓住稻草,但 NS 有时不明显的变化有速度优势)
Also not sure how changing the customform in dynamic mode works.也不确定如何在动态模式下更改自定义表单。 When you know the form you can also add that to the init defaults:当您知道表单时,您还可以将其添加到 init 默认值中:
{recordmode:'dynamic', customform:receivedInvoice.transactionType}
One of the reasons why you Submit is slow might be there are a lot of User Event scripts attached to the record.您提交缓慢的原因之一可能是记录中附加了大量用户事件脚本。 Since it is the Restlet that saves the record, it will trigger the User Event scripts.由于是 Restlet 保存记录,所以会触发用户事件脚本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.