Go Back   Cockos Incorporated Forums > REAPER Forums > Dstruct's Casa De Nitpicks

Reply
 
Thread Tools Display Modes
Old 02-14-2018, 08:02 AM   #1
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,999
Default ReaScript EnumerateFiles function Cache files list ?

Hi,


It seeùs that the EnumerateFiles cache file list for each subfolder.

This means that if you os.rename so file, you will not see the file list change, even if you recall EnumerateFiles .

Here is a sample code:

Quote:
function EnumerateFiles( folder )
local files = {}
local i = 0
repeat
local retval = reaper.EnumerateFiles( folder, i )
table.insert(files, retval)
i = i + 1
until not retval
return files
end

path = "E:\\Bureau\\Test\"

files_a = EnumerateFiles( path )
retval, message = os.rename(path .. "1.txt", path .. "4.txt")
files__b = EnumerateFiles( path )
And here is the result:



But note that the files do change, it is just the EnumerateFiles which stay the same.

Here is test code from cfillion;



I would have expect EnumerateFiles to NOT cache the result, and let the coder cache it by himself and use virtual folder structure if he want (surely faster), at least as an optional argument, as it is a bit unexpected (and undocumented) behavior.

Thanks !
X-Raym is offline   Reply With Quote
Old 02-14-2018, 06:12 PM   #2
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,999
Default

According to cfillion test, the cache last 17 ticks (approx 500ms).
X-Raym is offline   Reply With Quote
Old 01-05-2021, 01:55 AM   #3
Buy One
Human being with feelings
 
Buy One's Avatar
 
Join Date: Sep 2019
Posts: 1,196
Default

This is true for reaper.EnumerateSubdirectories as well

When checking if a directory has been created immediately afterwards it's not registered and not getting listed in the output.

Can be cured with
Code:
local t_point = reaper.time_precise()
repeat until reaper.time_precise() - t_point > 0.5

Last edited by Buy One; 01-05-2021 at 02:03 AM.
Buy One is online now   Reply With Quote
Old 01-05-2021, 07:08 AM   #4
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,672
Default

Yeah. The reason, why my GetProjectStateChunk-function fails often.

The update latency can be much longer than 500ms.
Sometimes waiting 20 seconds isn't enough.
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...
Meo-Ada Mespotine is offline   Reply With Quote
Old 01-06-2021, 05:05 PM   #5
Justin
Administrator
 
Justin's Avatar
 
Join Date: Jan 2005
Location: NYC
Posts: 15,855
Default

To clear the cache, you can scan a different path. Unfortunately there's a bug in the caching logic where the other path has to be valid (oops). So, we'll be fixing the caching logic, and also adding an additional thing where passing idx=-1 will invalidate the cache.
Justin is offline   Reply With Quote
Old 01-06-2021, 05:15 PM   #6
Justin
Administrator
 
Justin's Avatar
 
Join Date: Jan 2005
Location: NYC
Posts: 15,855
Default

Quote:
Originally Posted by Meo-Ada Mespotine View Post
Yeah. The reason, why my GetProjectStateChunk-function fails often.

The update latency can be much longer than 500ms.
Sometimes waiting 20 seconds isn't enough.
Hmm not sure I understand this -- can you explain?
Justin is offline   Reply With Quote
Old 01-21-2021, 08:46 AM   #7
Buy One
Human being with feelings
 
Buy One's Avatar
 
Join Date: Sep 2019
Posts: 1,196
Default

Should be fixed in build 6.20

from the change log

Quote:
+ ReaScript: EnumerateFiles()/EnumerateSubDirectories() allow manual cache invalidation [t=203235]
+ ReaScript: fix EnumerateFiles()/EnumerateSubDirectories() cache bug [t=203235]
Now cache clearing besides passing -1 also works with invalid directory

Last edited by Buy One; 04-25-2021 at 01:42 PM.
Buy One is online now   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 10:41 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.