Skip to main content
27shutterclicks
Inspiring
September 19, 2022
Answered

LrTasks, SQLite and caching questions

  • September 19, 2022
  • 1 reply
  • 197 views

For the last couple of weeks, I've picked up Lua again and I've been trying to wrap my head around LrTasks and how to best use it.

 

I am working on a plugin that makes  a call to sqlite using LrTasks.execute() to get some info from the catalog (that is not available via the SDK).

 

I am monitoring the time it takes for the task making the call using waitForGlobal function I found in the forums and the average is about 2-4 seconds.

 

The call works fine, but if I run the plugin again immediately to fetch the same info, the call time becomes zero and the rest of the codes executes before the call finished outputing the result to the temp file. 

 

Any suggestions on how to fix this? What I am trying to figure out is:

 

  1. Why is the second call time always zero?
  2. Is there some caching happening or some other mechanism that I may not be aware of ?
  3. Do I need to consider killing the task and if so, how?

 

Thanks

This topic has been closed for replies.
Correct answer 27shutterclicks

I think I figured it out, although there much still I need to understand of Lua.

 

I suspected that call time was 0 because the waitForGlobal function wasn't waiting at all, which means the check for the global to be nil failed.  That meant that the global was still set to the old value, even after the plugin finished doing its thing and it was maintaining its value on subsequent runs.

 

To fix this, I simply forced the global variable to be nil at the beginning of the code, and everything worked out.

1 reply

27shutterclicks
27shutterclicksAuthorCorrect answer
Inspiring
September 20, 2022

I think I figured it out, although there much still I need to understand of Lua.

 

I suspected that call time was 0 because the waitForGlobal function wasn't waiting at all, which means the check for the global to be nil failed.  That meant that the global was still set to the old value, even after the plugin finished doing its thing and it was maintaining its value on subsequent runs.

 

To fix this, I simply forced the global variable to be nil at the beginning of the code, and everything worked out.