Dear Rails enthusiasts,
I have database that has several blob fields. Some of them aren’t
exactly
photos and I really want to keep them in the database, but some of them
are
quite “huge” (several hundred Ks).
I can’t use http://www.kanthak.net/opensource/file_column/ plugin
because it
uses files and I want to store them in the DB.
The main (or the only) problem is performance.
Whenever I do a find, or SomeOtherModel.find( … :include =>
‘modelcontainingblob’)… The query will be soooooo slow as expected.
Not
much because of a lot of rows but mainly because of the unnecessary blob
columns loaded.
I’ve written an article about this is
gauldong.net,
the main solutions being
- move the blob fields to a separate table
- use views
After some time, it seems both approaches have complicated downsides
that I
can’t bear for a problem “so simple”.
There is this find :select but it seems that I have to use it
everywhere,
and it can’t be used by find :include (by other models) and I don’t
really
know what other methods use find.
What I want is that the default find for the model will exclude the BLOB
fields (or any fields I specify). And only load/save them if I
explicitly
request them (probably upon first access). This will mean an increase in
the
number of queries if I want to access all the BLOB fields on a
table/model,
but will drastically increase the performance of loading the whole
record/records.
I did do some research on Mr. Google and the rails groups and haven’t
got
satisfactory explanation.
Please help. Thank you.
–
Hendy I.
Web: http://hendy.gauldong.net
Mobile: +62 856 24889899
Yahoo Messenger: ceefour666
LinkedIn: http://www.linkedin.com/in/ceefour