hi,
It is possible #add: and element to a larga collection without reading the collection from database ? Example: aBank accounts (20 instances) Each time i #add: anAccount takes up to 12 seg (depending on the PC). This is because the on demand loader read the entire collection from db: addAccount: anAccount ^accounts add: anAccount It is anOrderedCollection, may be i should change it to aDictionary ? Instance variable #accounts it is aProxy until is referenced (here: accounts message), may be there is a way to add: anAccount without reading the entire collection. me stillSearchiing. Any ideas ? Regards Bruno |
Hi,
Correction: aBank accounts (has 20.000 instances NOT 20) Regards Bruno > hi, > > It is possible #add: and element to a larga collection without reading > the collection from database ? > > Example: > > aBank accounts (20 instances) > > Each time i #add: anAccount takes up to 12 seg (depending on the PC). > > This is because the on demand loader read the entire collection from db: > > addAccount: anAccount > > ^accounts add: anAccount > > It is anOrderedCollection, may be i should change it to aDictionary ? > > Instance variable #accounts it is aProxy until is referenced (here: > accounts message), may be there is a way to add: anAccount without > reading the entire collection. > > me stillSearchiing. > > Any ideas ? > > Regards Bruno |
Hi,
A general solution is to insert SQL sentences inside the methods that has performance problems (if it possible, in this case yes). OriginalCode: Bank addAccount: anAccount ^accounts add: anAccount Optimized code: Bank addAccount: anAccount | id result sqlQuery index | result := self nextSQLIndexFor: self sqlClassName. " a sql execution, the next row number for this table " index := self nextObjectIndexCollection. " a sql execution, the index number for the anAccount in accounts collection " [self session insertInto: 'BANK__ACCOUNTS' fields: #('ID' 'SOURCE_ID' 'TARGET_ID' 'INDEX_') values: (Array with: id printString with: self dbId printString with: unaInternacion dbId printString with: index printString )] on: Error do:[:err | ^self handle: err]. ^anAccount Here it never reads all accounts from aBank like the Original Code do. Regards Bruno PS: depending on table relations and names it is possible to create transformations (using the Code Rewriter (in D6)) to do this automatically. I do not create any transformation rule yet, but it seems very possible. Bruno escribió: > > Hi, > > Correction: > > aBank accounts (has 20.000 instances NOT 20) > > Regards Bruno > >> hi, >> >> It is possible #add: and element to a larga collection without reading >> the collection from database ? >> >> Example: >> >> aBank accounts (20.000 instances) >> >> Each time i #add: anAccount takes up to 12 seg (depending on the PC). >> >> This is because the on demand loader read the entire collection from db: >> >> addAccount: anAccount >> >> ^accounts add: anAccount >> >> It is anOrderedCollection, may be i should change it to aDictionary ? >> >> Instance variable #accounts it is aProxy until is referenced (here: >> accounts message), may be there is a way to add: anAccount without >> reading the entire collection. >> >> me stillSearchiing. >> >> Any ideas ? >> >> Regards Bruno |
> Bank
> addAccount: anAccount > | id result sqlQuery index | > > result := self nextSQLIndexFor: self sqlClassName. > " a sql execution, the next row number for this table " > index := self nextObjectIndexCollection. > " a sql execution, the index number for the anAccount in accounts > collection " > > [self session insertInto: 'BANK__ACCOUNTS' > fields: #('ID' 'SOURCE_ID' 'TARGET_ID' 'INDEX_') > values: (Array with: id printString with: self dbId printString > with: anAccount dbId printString with: index printString )] on: > Error do:[:err | ^self handle: err]. > > ^anAccount This the general idea. * Obtain all values (executing sql sentences) to insert new row in a table (with a sql sentence). I copy the code from Dolphin to the email. And i changed some thing inside the email to be more easy to read. Regards Bruno |
Free forum by Nabble | Edit this page |