Moving files on upload/update

,

I’m creating a plugin to organize my files in one folder/page containing all files. I have a lot of files (~ 4k) and the response is pretty slow – to load all files takes about 7 seconds. This is why I want to store the files within alphanumeric sub folders/pages (a, b, c). The problem is, that these sub folders should by created on upload/on changeName of the files. And then move the file in the desired folder.

My idea is to achieve this with hooks (file.create:before, file.changeName:before). The creation of the sub folders is easy: Get the first letter of the file name and create the page if it doesn’t exist. But what is the best way to move files with all the contents (text files)?

I think the file.changeName:before hook isn’t the right choice because if I assign a new parent to the Kirby\Cms\File object the file name doesn’t change (file root changes).

And if I use the file.changeName:after hook, I have to rewrite the entire code that is used to update the file name located in the Kirby\Cms\FileActions class (changeName callback function). I don’t want to repeat myself.

Is there a way I’m missing here? Thank you for your support.

Btw: I hope there is a plugin/feature planned to (optionally) organize files in a better way than it actually is. For example an asset management plugin. How are you guys organize loads of documents, images etc. referenced on several pages?