Hey, I’m experimenting with scripting a batch of tasks in JXA and running into some big speed issues. I think this is a simple misunderstanding - I’m expecting it to work like a single SQL query that loads all objects in memory but instead it seems to do each operation separately.
Here’s a simple example - let’s get the names of all uncompleted tasks:
var tasks = Application('OmniFocus').defaultDocument.flattenedTasks.whose({completed: false})
var totalTasks = tasks.length
for (var i = 0; i < totalTasks; i++) {
tasks[i].name()
}
[Finished in 46.68s]
Actually getting the list of 900 tasks takes ~7 seconds - already slow - but then looping and reading basic properties takes another 40 seconds, presumably because it’s hitting the DB for each one. (Also, tasks
doesn’t behave like an array - it seems to be recomputed every time it’s accessed.)
Is there any way to do this quickly - to read a batch of objects and all their properties into memory at once? Alternatively, if I’m trying to do more complex batch processing, is it possible / preferable to hit the Omnifocus DB directly?