You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
kyledecot edited this page Apr 11, 2013
·
6 revisions
Partitioning
If you have many files dumped in the same directory disk lookups might be slow.
That is why it's a good idea to partition your files into directories like in the following example:
In this example we use the first two letters of the filename to create directories that will partition our files.
This way we can have nice fast dictionary-like lookups.
It is also a good idea to clean up your empty directories when the files in them are deleted, like in the following example:
classFileUploader < CarrierWave::Uploader::Basestorage:fileafter:remove,:delete_empty_upstream_dirsdefstore_dir"#{base_store_dir}/#{model.id}"enddefbase_store_dir"documents/#{model.file_name[0,2]}"enddefdelete_empty_upstream_dirspath= ::File.expand_path(store_dir,root)Dir.delete(path)# fails if path not empty dirpath= ::File.expand_path(base_store_dir,root)Dir.delete(path)# fails if path not empty dirrescueSystemCallErrortrue# nothing, the dir is not emptyendend