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)
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.
That makes sense for me.
--
Sergi Almacellas Abellana
www.koolpi.com
Twitter: @pokoli_srk