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.
for record in records:
defaults = {…}
new_record = Model.copy([record], defaults)
But indeed it would be done with quiet good preformance once the
write-multi is there like this:
new_records = Model.copy(records)
to_write = []
for record, new_record in zip(records, new_records):
default = {…}
to_write.extend(([new_record], defaults))
Model.write(*to_write)
Ok it is a little bit longer and it generate twice validation. But I
think it is pretty good enough.
--
Cédric Krier - B2CK SPRL
Email/Jabber: [email protected]
Tel: +32 472 54 46 59
Website: http://www.b2ck.com/
pgp7KICWna7XQ.pgp
Description: PGP signature
