tas3d All good, but it get evaluated 12 times! Any clues why is that and how to get it populated once?
Such is houdini. Use fast code in menus that's okay to be called hundreds of times in a row. Each menu event might evaluate the callback script dozens of times. For database/disk hits, use caching to prevent unnecessary actions.
jsmack For database/disk hits, use caching to prevent unnecessary actions.
Disk queries are my reason for asking. Could you elaborate idea of caching?
There's probably a better way to do this, but in the module where the callback is defined, save the results of the query with some key that can be used to retrieve the results of the same query later, recording the time of the initial query. Then when the callback runs again it can use the cached result if it isn't too old. Otherwise, run the live query again. The cache can be short lived, like 30 seconds. This should prevent a menu callback from hitting the disk 10 times instead of once.
I was doing sort of the same trick and noticed huge improvements on a heavy menu script. The issue was indeed that you don't know what iteration number is the current run of the menu script. If there was a kwargs argument for that, it would be easier to load the cached menu after the first evaluation for the remaining iterations.