ZODB guys,

I have a bookstore application in which I use the ZODB in a simple way.  The
database saves stores and records in the stores.
I open the database as follows where the databasePath argument points to my
bookserver.fs file.

from ZODB import FileStorage, DB
import  transaction
import BTrees.OOBTree,  BTrees.IOBTree

       def open(self, databasePath):
                self.bookDatabase_storage     =
FileStorage.FileStorage(databasePath)
                self.bookDatabase_db          =
DB(self.bookDatabase_storage)
                self.bookDatabase_connection  = self.bookDatabase_db.open()
                self.dbRoot = self.bookDatabase_connection.root()

       # our btrees
        ibTree = BTrees.IOBTree

I define the key 'books' to be an IOBTree

        db.dbRoot['books'] = ibTree.IOBTree()

And when the user creates a store I define the book number to be an IOBTree

        db.dbRoot['books'][storeNumber] = ibTree.IOBTree()

Then I save the book using storeNumber and bookNumber as keys.

        record = {'title':"The Grapes of Wrath", 'author':"John
Steinbeck",'publisher':"Randomhouse"}
        db.dbRoot['books'][storeNumber][bookNumber] = record

So now I can qualify an entire store by using

                                currentStore = db.dbRoot['books'][storeNumber]

And a single book by

                                currentBook= 
db.dbRoot['books'][storeNumber][bookNumber]

And look at the books in the store by
                          for k, v in currentStore.values():
                                                print k, v

I have two questions.
                1)  When I already have a storeNumber and I save a record to 

                                db.dbRoot['books'][storeNumber][bookNumber] = 
record

                 I have to set the _p_changed flag on the 'books' IOBTREE 
structure to get
the book to save.

                                db.dbRoot['books']._p_changed = True

                Which means that it saves the ENTIRE 'books' IOBTREE' structure 
every time
a save a single book.  (at least it looks like it is doing this).  When I
edit a book and save it the database grows by more than 64k.  And it looks
like it will get worse and worse as more books are added.

                Am I looking at this correctly.  Or am I doing something really 
ignorant?

                2)  When I assign a value to the db such as 

                        db.dbRoot['books'][storeNumber][bookNumber] = record

                        I initially assumed that setting the _p_changed flag on 
the storeNumber
key would only save the single record that I want to save.   As mentioned
above, I am setting the flag on the 'books' IOBTREE also.  Should I have to
set it on both.  I have come to the conclusion that the _p_changed flag must
be set at the highest key level.  ie.. 'books'.  Again, Am I doing something
really ignorant?  


Thank you for your responses.  I really need to know and get this fixed
before my wife divorces me!  She spends time entering books and we still
seem to not really know when the changes are going to permanently be saved.  

Tom




-- 
View this message in context: 
http://www.nabble.com/ZODB-design.-Size-and-saving-records-tp18055895p18055895.html
Sent from the Zope - ZODB-Dev mailing list archive at Nabble.com.

_______________________________________________
For more information about ZODB, see the ZODB Wiki:
http://www.zope.org/Wikis/ZODB/

ZODB-Dev mailing list  -  ZODB-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zodb-dev

Reply via email to