I need to store an image as a blob in the DB, but want to access it in Ruby/Rails as an Image (from RMagick). My first guess would be that consists_of is the way to set up this mapping, but, after a lot of hard work and discussion, it seems that consists_of only wants objects that can be instantiated with the data via new/inialitize(). RMagick Image''s are can only be instantiated from blobs via a class method Image.from_blob(). So, my question is: What is the clean, proper, and idiomatic way of doing this? Making some type of delegate or redefine to Image to chaneg the initialize() call? Or am I missing something? LR PS Please CC me on all responses.
On 9/4/05, Lst Recv <listrecv-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> So, my question is: What is the clean, proper, and idiomatic way of > doing this? Making some type of delegate or redefine to Image to > chaneg the initialize() call? Or am I missing something?Well, I found that loading images out of a database was actually tremendously slower than just loading static files from the webserver. The reason is that you have to go through two extra layers just to get to the image (eg, instead of your webserver serving the file directly, it has to go through rails which then has to go through the DB). So unfortunately I don''t remember exactly how to set up image loading from database blobs, but I just wanted to say that if you can get away with it, leave the images out of the database, and it''ll be much faster. -- Urban Artography http://artography.ath.cx
Understood. Well, in this case I really would like to put them in the database, but, regardless, I''d like to understand proper usage of Aggregation/composed_of regardless. On 9/4/05, Rob Park <rbpark-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 9/4/05, Lst Recv <listrecv-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > So, my question is: What is the clean, proper, and idiomatic way of > > doing this? Making some type of delegate or redefine to Image to > > chaneg the initialize() call? Or am I missing something? > > Well, I found that loading images out of a database was actually > tremendously slower than just loading static files from the webserver. > The reason is that you have to go through two extra layers just to get > to the image (eg, instead of your webserver serving the file directly, > it has to go through rails which then has to go through the DB). So > unfortunately I don''t remember exactly how to set up image loading > from database blobs, but I just wanted to say that if you can get away > with it, leave the images out of the database, and it''ll be much > faster. > > -- > Urban Artography > http://artography.ath.cx >
I''d also like to know this. On 9/4/05, Lst Recv <listrecv-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I need to store an image as a blob in the DB, but want to access it in > Ruby/Rails as an Image (from RMagick). > > My first guess would be that consists_of is the way to set up this > mapping, but, after a lot of hard work and discussion, it seems that > consists_of only wants objects that can be instantiated with the data > via new/inialitize(). RMagick Image''s are can only be instantiated > from blobs via a class method Image.from_blob(). > > So, my question is: What is the clean, proper, and idiomatic way of > doing this? Making some type of delegate or redefine to Image to > chaneg the initialize() call? Or am I missing something? > > LR > > PS Please CC me on all responses. > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
On 9/4/05, Rob Park <rbpark-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 9/4/05, Lst Recv <listrecv-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > So, my question is: What is the clean, proper, and idiomatic way of > > doing this? Making some type of delegate or redefine to Image to > > chaneg the initialize() call? Or am I missing something? > > Well, I found that loading images out of a database was actually > tremendously slower than just loading static files from the webserver. > The reason is that you have to go through two extra layers just to get > to the image (eg, instead of your webserver serving the file directly, > it has to go through rails which then has to go through the DB). So > unfortunately I don''t remember exactly how to set up image loading > from database blobs, but I just wanted to say that if you can get away > with it, leave the images out of the database, and it''ll be much > faster.You should be able to cache the images though. I''m considering keeping a canonical version of the image in the database. And then use that image to create thumbnails, etc of it. And using caching for the image views. So after its rendered, it doesn''t need to be renderered again. Thoughts on that approach? Then, ALL the data is in the database. Which makes for really easy backups.
On Sep 12, 2005, at 12:05 PM, Joe Van Dyk wrote:> I''d also like to know this. > > On 9/4/05, Lst Recv <listrecv-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> I need to store an image as a blob in the DB, but want to access it in >> Ruby/Rails as an Image (from RMagick). >> >> My first guess would be that consists_of is the way to set up this >> mapping, but, after a lot of hard work and discussion, it seems that >> consists_of only wants objects that can be instantiated with the data >> via new/inialitize(). RMagick Image''s are can only be instantiated >> from blobs via a class method Image.from_blob(). >> >> So, my question is: What is the clean, proper, and idiomatic way of >> doing this? Making some type of delegate or redefine to Image to >> chaneg the initialize() call? Or am I missing something? >> >> LR >> >> PS Please CC me on all responses.While I have not done this with RMagick specifically, I have done it with TZInfo. I used Ruby''s Forwardable to create a simple class that provides the proper ctor and delegates everything else I need to the TZInfo machinery. Specific details can be found at [1] (class MyTimezone). [1] http://lunchroom.lunchboxsoftware.com/pages/tzinfo_rails -- Scott Barron Lunchbox Software http://lunchboxsoftware.com http://lunchroom.lunchboxsoftware.com