On 27/11/13 20:00 +0100, Sergi Almacellas Abellana wrote: > El 25/11/13 22:37, Cédric Krier ha escrit: > >On 23/11/13 20:49 +0100, Cédric Krier wrote: > >>>On 23/11/13 20:45 +0100, Sergi Almacellas Abellana wrote: > >>>> >Hi All, > >>>> > > >>>> >As Albert suggested on [1] i think that copy may also be improved in > >>>> >the line of [2]. > >>>> > > >>>> >This is difficult as a the default parameter is not mandatory. > >>>> > > >>>> >As copy is a simplification of creating new records I will suggest > >>>> >the following improvement: > >>>> > > >>>> >def copy(cls, records, default=None, create=True): > >>>> >.... > >>>> > to_create = [] > >>>> > for data in datas: > >>>> > data = convert_data(field_defs, data) > >>>> >to_create.append(data) > >>>> > if not create: > >>>> > return to_create > >>>> > new_records = cls.create(to_create) > >>>> >.... > >>> > >>>This can not work because of the translations. > >>>Moreover, over time we have removed all the ugly different in and out > >>>type of values because they always generate bugs. > >I have re-think about it and I have one more cons. > >Indeed what you try to optimize is when we copy records with different > >default values. > Indeed what I try to optimize is copying multiple times the same > record. Something like: > > new_records = Model.copy([record]*10, defaults)
In this case, I don't see what needs to be optimized. In such case copy will already call once create and with the cache of records the computation of the values is quite fast (no DB access). -- Cédric Krier - B2CK SPRL Email/Jabber: [email protected] Tel: +32 472 54 46 59 Website: http://www.b2ck.com/
pgpkuxNfF7HDp.pgp
Description: PGP signature
