(13.06.2016, 19:59)PErwin van der Zwart Wrote: Hi Buuuudzik,
I think the iterate of the result table is taking a lot of resources, especially when having the execution of multiple scripts in parallel from the tag group
You could try to do it with a direct query from DB to avoid the table iterate and speed up things a bit.
Code:function tag_or(tag)
local result = db:getall('SELECT id FROM objects WHERE datahex = "01" AND tagcache LIKE "%' .. tag .. '%"')
if #result == 0 then
return false
else
return true
end
end
You can also add this script in the start of your script to kill previous script when executed multiple times in parallel.
Code:--check for earlier started scrips
storagename = 'TAG_OR' -- Must be unique for every script
--check storage for tpid value
tpid = storage.get(storagename)
--check if tpid has a value
if tpid == nil then
pid = os.getpid()
storage.set(storagename, pid)
else
pid = os.getpid()
-- create new pid for next time to kill
storage.set(storagename, pid)
-- kill earlier running script
os.kill(tpid, signal.SIGKILL)
end
If this doesn't do the trick you can use the semaphore library making it possible to block parallel execution of scripts
See http://openrb.com/docs/semaphore.htm
BR,
Erwin van der Zwart
Very good tip, I will try tommorrow. Thanks, you're the best. I think this will be helpful for a lot of LM medium programmers like me?