Hi,<br><br>I have made a small tweak to the nginx-gridfs module (<a href="https://github.com/mdirolf/nginx-gridfs">https://github.com/mdirolf/nginx-gridfs</a>) to serve my requirement. I am not sure if it is generic enough to raise a pull request. So I thought of posting it here and asking for some feedback.<br>
<br>The code changes are related more to MongoDB and GridFS but still it would be very helpful if the nginx gurus here can review the code from the nginx module angle and give me some feedback.<br><br>Here is a description about my requirement and my change. Or you can skip right ahead and go look at the code at : <a href="https://github.com/brahmana/nginx-gridfs/commit/5f32a63678b9f997bcd4539b89f357dc98be65d4">https://github.com/brahmana/nginx-gridfs/commit/5f32a63678b9f997bcd4539b89f357dc98be65d4</a><br>
<br>Setup :<br> - Rails app accepts user uploaded images and stores them in GridFS, with unique file names<br> - Nginx uses the nginx-gridfs module to serve these files from GridFS directly.<br><br>Requirement<br> - Multiple versions (sizes) of every uploaded image needs to exist - each addressed by the same (or similar) url with a query parameter specifying the version.<br>
- Creating versions during the upload request results in bad user experience (too much time) and hence needs to be done by a background process - using a queuing server. This means additional versions are not available right away.<br>
- The clients would not know when these versions are available and would get 404 when they try to fetch a non-default version of the image.<br> - So the nginx-gridfs module needs to be smart enough to fallback to the default version when the requested version is not available.<br>
i.e. Look for the specified version. If present serve it. Else fetch the default version and serve that.<br><br>I have a very rudimentary implementation of this. It compiles and works fine - no crashes, doesn't seem to leak memory. I haven't done any benchmarking, but it seems do just fine under simple loads.<br>
<br>Here is how the different versions of the image files are stored and addressed :<br><br>The value of the 'type' query parameter is added as a suffix to the filename before searching.<br> Ex : original filename - 'images/4f4292ff1d41c80be4000013' and is requested as '<a href="http://hostname/files/images/4f4292ff1d41c80be4000013">http://hostname/files/images/4f4292ff1d41c80be4000013</a>'<br>
Small version of the same image will be at : 'images/4f4292ff1d41c80be4000013_small' or 'images/4f4292ff1d41c80be4000013_s'<br>and is requested as '<a href="http://hostname/files/images/4f4292ff1d41c80be4000013?type=small">http://hostname/files/images/4f4292ff1d41c80be4000013?type=small</a>' or '<a href="http://hostname/files/images/4f4292ff1d41c80be4000013?type=s">http://hostname/files/images/4f4292ff1d41c80be4000013?type=s</a>'<br>
<br>If the requested version is not found, then we fallback to the default version, i.e. the one without any suffixes (a.k.a 'images/4f4292ff1d41c80be4000013') and serve that one.<br><br>Few notes about the changed code :<br>
1) It assumes that the field type to be queried against on a String type<br>2) It assumes that the gridfs and gridfile are reusable types - i.e same object can be used across multiple queries.<br>3) It is probably not super optimized, but that is ok for now.<br>
<br>And here is the code commit on <a href="http://github.cm">github.cm</a> for this change - <a href="https://github.com/brahmana/nginx-gridfs/commit/5f32a63678b9f997bcd4539b89f357dc98be65d4">https://github.com/brahmana/nginx-gridfs/commit/5f32a63678b9f997bcd4539b89f357dc98be65d4</a><br>
<br>It would be very helpful to get some feedback from you guys.<br><br>-- <br>Regards,<br>Srirang G Doddihal<br>Brahmana.<br>@sribrahmana - <a href="http://www.twitter.com/sribrahmana">http://www.twitter.com/sribrahmana</a> <br>
<br>The LIGHT shows the way.<br>The WISE see it.<br>The BRAVE walk it.<br>The PERSISTENT endure and complete it.<br><br>I want to do it all ALONE.<br>