Phil, the speed increase is incredible! At first glance it looks like you're just removing a COUNT of all stored files, but I'll have to dig deeper when I have time.
Any idea what effect this will have elsewhere? Are we courting danger or DB corruption here?