For large content repositories even the improved version is not satisfying. Testing e.g. 2.5+ mio entries in file system and/or in the database has negative impact on other interactions happening at the same, no matter how fast the machine is.
Therefore, i've implemented a much more scalable approach based on a file-creation log that keeps track of freshly created files (per default the files created on one day). These files can be efficiently checked together with "cr_delete_scheduled_files" without putting much stress on either the file-system or the database.
see: http://cvs.openacs.org/changelog/OpenACS?cs=oacs-5-8%3Agustafn%3A20131231162110
The function "cr_check_orphaned_files" can still be used for cleaning up orphaned files from times before the cr-file creation log was in place (that is from the birth of OpenACS until now).
Please test on your systems as well. Note that the change requires an update of acs-tcl and a restart of nsd.
all the best for 2014!
-gustaf neumann