(grr it happened again >.<, my apologies to the guy who received this mail, it was intended for the list)
From: Petr Jakeš <petr.ja...@tpc.cz> To: vicariou...@gmail.com Date: Thursday 01 April 2010 > Some examples of the code, so we all can learn from your experiences, will > be nice. > > Regards > > Petr > Well, for this particular case, I was using a factory class that was in charge of creating the several objects that were required. It worked more or less like so: there is an indexer class, which takes care of crawling the filesystem. For every file or directory it encounters, it passes a series of parameters to the factory class (or object ;)), which the factory uses to instantiate the object that represents said file/dir. Yes, you may say that has too much coupling, but given the handling that one must do regarding connections and transactions (and taking care not to use them in a different thread than the one they were created on), it seemed the easiest and more or less "right" way to do it. So, let's say that there's one method in this Factory class/object to instantiate each of the objects that can be scanned from the filesystem (regular file, directory, image/video/audio file). Instantiation in itself isn't too expensive (or at least there isn't much that you can do about it). But when it comes to extracting the metadata for some particular files (namely, audio, video and image files) I found that I was setting fields on the object one at a time. This caused several UPDATE statements, which slowed everything down. So, in order to alleviate this, I did the following: def new_photo(self, parent, name, relpath, mimetype, atime, mtime, root, size, strsize, strabs): trans = self._conn.transaction() atime, mtime = self._check_stat(atime, mtime) mimetype = mimetype[0] photo = Photo(parent = parent, name = name, relpath = relpath, mimetype = mimetype, atime = atime, mtime = mtime, size = size, strsize = strsize, root = root, isdir = False, strabs = strabs, connection = trans) self._get_photo_metadata(photo) trans.commit(close = True) return photo The photo (I didn't use "Image" as a name so I wouldn't overwrite some other class already defined within Python) was the heaviest class in this regard, since it extracted two scaled images from the original (that's just something the pogram does, you can try it out if you want to). This extraction is done in the _get_photo_metadata method. So I got a transaction from the regular SQLObject connection, and used it as a parameter at object creation time, instead of the connection. After that I commit it with the close parameter on True, since then the method ends and I don't want that transaction lying around so that after working I still have a journal file for the SQLite db :P. Hope it is useful for somebody in the future. Don't forget that the transaction object you get from the connection.transaction() method, is already begun. You just have to work directly with it and DON'T FORGET to close it :) (via commit or rollback). Thanks for the help people. Cheers Juan Manuel Santos ------------------------------------------------------------------------------ Download Intel® Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev _______________________________________________ sqlobject-discuss mailing list sqlobject-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss