On Fri 2006-09-22 (07:16), [EMAIL PROTECTED] wrote:
> Is it better convention to store images (lets say i was making a photo
> gallery app) in the DB as per
> (http://trac.turbogears.org/turbogears/wiki/StoringAndRetrievingFilesFromDatabase),
> or straight on the HD?
The downside of storing in the database attached to your main class is
that SQLObject will fetch that from the database every time you get any
information from a particular object. That's fairly heavy - when I
tried it, it made the whole application unusable.
You can relatively easily avoid this by storing the image in a separate
table and class, and accessing it via a SQLObject SingleJoin, like this:
class Photo:
...
contents = SingleJoin('PhotoContent')
class PhotoContent:
photo = ForeignKey('Photo')
image = BLOBCol()
It would be better to create an accessor on the original SQLObject,
though, like this:
class Photo:
...
contents = SingleJoin('PhotoContent')
def _get_image():
return self.contents.image
A layer of filesystem caching can then be added to prevent accessing
from the database each time, but you can also scale out to multiple
servers without a shared filesystem (such as NFS).
Neil
--
Neil Blakey-Milner
[EMAIL PROTECTED]
http://mithrandr.moria.org/
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/turbogears
-~----------~----~----~----~------~----~------~--~---