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)
....

So when using copy inside a loop can be used in the following way:

to_create = []
for i in range(1, 1000):
    to_create.extend(cls.copy([record], default, False))
cls.create(to_create)

I've done some benchmarks on stock_split module. I split a move of quantity 50 into 50 moves of quantity one.

The results (in seconds) are the following:

Without patch: Elapsed:  2.81604099274
With patch: Elapsed:  1.34554600716

I can share the patches if anyone is interested.

Any toughs?


[1]https://groups.google.com/d/msg/tryton-dev/PU_P_Z8wjoE/uWcJE8mwHzEJ

[2] http://codereview.tryton.org/1641003/

--
Sergi Almacellas Abellana
www.koolpi.com
Twitter: @pokoli_srk

Reply via email to