Fix anti-pattern about create/write in loop
There are in some place this anti-pattern:
for record in records:
# do some stuffs
record.save()
# or
cls.create()
# or
cls.write()
This pattern is not very good for the cache management of Tryton as for each
create/write the cache of all the record in the records list will be reset.
So it doesn't take advantage at all of the smart cache.
Indeed this pattern should be used:
for sub_records in grouped_slice(records):
for record in sub_records:
# do some stuffs
# store change
cls.create(to_create)
cls.write(to_write)
grouped_slice will be a helper to make the "in_max" loop.
Files
Download | Creator | Timestamp | Type |
---|---|---|---|
tryton-antipatern.txt | @pokoli | 2013-11-23 13:39:09.084000 UTC | text/plain |