It could also speed up fetching the files size since the data is found into the database vs having to fecth the info from the filesystem.
Things I did :
Added the column into the DB, with a -1 value for existing files.
Filled the info when creating a new file.
When a file is deleted and the size in database is -1, the file is decrypted to get the right value for the quota.
I moved the quota update code in the file deleted listener (before that it was duplicated in all services that can delete files) because decrypting the file can slow down the calls, and I think not immediately updating the quota is OKish (it even makes sense because the quota is now updated when the file is actually deleted). It also means less code duplication because the code is in a single place.
I wrote a FileSizeService that is in charge of slowly filling the database with info of the files with an unknown size by processing a batch of files every minute, I'm not sure about the right way to deal with errors when a file can't be read, for exemple because it's missing or unreadable (I'm tempted to delete the file record from the database, at least in the case of the file being not found, but it would be pretty drastic). For the moment the code skip the file, which mean it will retry again and again to reprocess it in the next pass. Instead of a scheduled batch approach I could also make a job run batches non-stop, but I prefer a longer migration with a low impact to a one that creates a long load on the server.
In UserResource I factorized two instances of identical code managing notifications.
In the tests I did some factorization and added some constants for the file name and size to avoid the copy / paste in the code.
A draft for https://github.com/sismics/docs/issues/701 .
It could also speed up fetching the files size since the data is found into the database vs having to fecth the info from the filesystem.
Things I did :
FileSizeService
that is in charge of slowly filling the database with info of the files with an unknown size by processing a batch of files every minute, I'm not sure about the right way to deal with errors when a file can't be read, for exemple because it's missing or unreadable (I'm tempted to delete the file record from the database, at least in the case of the file being not found, but it would be pretty drastic). For the moment the code skip the file, which mean it will retry again and again to reprocess it in the next pass. Instead of a scheduled batch approach I could also make a job run batches non-stop, but I prefer a longer migration with a low impact to a one that creates a long load on the server.UserResource
I factorized two instances of identical code managing notifications.All is open for discussion