Tap Forms – Organizer Database App for Mac, iPhone, and iPad › Forums › Script Talk › Speed Tips?
- This topic has 8 replies, 3 voices, and was last updated 2 years, 4 months ago by Stephen Meehan.
-
AuthorPosts
-
August 13, 2022 at 12:45 PM #47777
Stephen MeehanParticipantHi, the script below takes about 5 seconds to execute, which seems inordinately slow for something so simple.
Anyone notice any obvious bottlenecks?
Thanks!
function New_Script() {
var l1_id = ‘fld-1150255ff604464392abee526dd2592b’;
var l1b_id = ‘fld-5afc66a3718e4ac69e5121ae0182b483’;
var l2_id = ‘fld-b9080a9632014c118b8a4f1790d7363e’;
var l2b_id = ‘fld-144e23e549f4475b8d384de1b6b367e3’;record.setFieldValue(l1b_id, record.getFieldValue(l1_id));
record.setFieldValue(l2b_id, record.getFieldValue(l2_id));document.saveAllChanges();
}
New_Script();
August 13, 2022 at 8:22 PM #47778
Daniel LeuParticipant5s seems indeed a bit long. I added some code to measure the execution time:
function speedtest() { var l1_id = 'fld-xxx'; var l1b_id = 'fld-xxx'; var l2_id = 'fld-xxx'; var l2b_id = 'fld-xxx'; record.setFieldValue(l1b_id, record.getFieldValue(l1_id)); record.setFieldValue(l2b_id, record.getFieldValue(l2_id)); document.saveAllChanges(); } var start = Date.now(); speedtest(); var end = Date.now(); console.log(<code>Execution time: ${end - start} ms</code>);
The first time running the script, I get an execution time of 5ms, successive runs are all between 1ms and 2ms.
August 14, 2022 at 9:37 AM #47779
Stephen MeehanParticipantconsole.log line results in an error:
Copy L1/L2 to L1B/L2B: SyntaxError: Unexpected token ‘<‘, line:17
changed to:
console.log(“Execution time: ” + (end – start) + “ms”);and get around 10ms, but it still takes 5s for the spinner to stop spinning and the result to show up in the console log window.
August 14, 2022 at 12:36 PM #47780
BrendanKeymasterdocument.saveAllChanges();
posts a notification to reload the records list after the save. Try it withoutdocument.saveAllChanges();
and see how that goes. Just as a test. But of course it won’t save the values.How many records do you have in your form?
August 14, 2022 at 4:24 PM #47781
Stephen MeehanParticipantForm has 4560 records, but removing document.saveAllChanges() didn’t make a noticeable difference, surprisingly.
However, I deleted all but 50 records as a test, and that works much, much faster. Less than one second I would say.
Is there anything else that could be causing the records to reload, or is there a way to explicitly block reloading?
- This reply was modified 2 years, 4 months ago by Stephen Meehan.
August 14, 2022 at 10:21 PM #47783
BrendanKeymasterThe notification to reload the records is built-in to the saveAllChanges command, so there’s no way to disable it. Not without me making changes to Tap Forms at least.
I’ll think about providing an alternative save mechanism, one that doesn’t post the notification, in a future version.
Is this a Field script or a Form script?
August 15, 2022 at 7:39 PM #47784
Stephen MeehanParticipantNo worries. Very minor issue.
It’s a Form script.
Thanks for the help, Daniel and Brendan!
- This reply was modified 2 years, 4 months ago by Stephen Meehan.
August 16, 2022 at 10:47 AM #47787
Daniel LeuParticipant>Copy L1/L2 to L1B/L2B: SyntaxError: Unexpected token ‘<‘, line:17
That’s an issue with the forum :-(. Sorry, I didn’t notice it when I posted my code.
August 17, 2022 at 5:53 PM #47788
Stephen MeehanParticipantNo problem.
Again, your input is very much appreciated!
-
AuthorPosts
You must be logged in to reply to this topic.