Closed namdinh-novobi closed 5 years ago
Hi,
You're finding all records with testA_records = self.env['testA'].search([])
and you're looping over them one by one to trigger item.computed_field
so it is logical that you're getting all records and they're all being computed?
P.S: Closing this as it is not really related to any off my modules but I'll still get notifications.
Yenthe, That's correct. I do not understand why it does not mapped one by one, but it passed list of redudant items while calculating is just related to one item.
Sorry for posting to the wrong issue, because I would like to contact you, but I do not know how to do :).
In case, I need your help. What do i need to do?
Thanks, -Nam
Vào Th 5, 12 thg 9, 2019 vào lúc 13:09 Yenthe Van Ginneken < notifications@github.com> đã viết:
Hi,
You're finding all records with testA_records = self.env['testA'].search([]) and you're looping over them one by one to trigger item.computed_field so it is logical that you're getting all records and they're all being computed?
P.S: Closing this as it is not really related to any off my modules but I'll still get notifications.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Yenthe666/Odoo_Samples/issues/12?email_source=notifications&email_token=AKH73LNR6SUSGQAHNQE45NLQJHMJXA5CNFSM4IV7MDE2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6QYTAQ#issuecomment-530680194, or mute the thread https://github.com/notifications/unsubscribe-auth/AKH73LM6CAGOYWDLQUCYUVTQJHMJXANCNFSM4IV7MDEQ .
Are you sure that you don't want to replace testA_records = self.env['testA'].search([])
by just the specific record? When you load all those records the compute is going off.
I think looping over items to handle logics is normal. In some cases, we do not know which record is specific. I can give you an example like this '# example for calculting salary of employees. '# BONUS which is value passed to the function executing... maybe '# basic_salary is a computed field calculated based on LEVEL of employee maybe... '# employees, we need to have all employees.
for emp in employees: emp.total_salary = emp.basic_salary + BONUS
The thing makes me confused is why there are redundant items passed to the computed function while the handling the logic is only correlated to the current item in the loop.
Hi Yenthe,
Today, I have found a thing correlated with the performance in Odoo, so I would like to discuss this with you to see whether it could be called an issue or not?
I have checked it on the latest Odoo (version 12), it has still been there.
The thing I have found, I will describe as code to esaier to explain:
class TestA(models.Model): _name = "testA"
class TestB(models.Model): _name = "testB"
If the current item in the loop is 1 (object of testA with id = 1), then when the computed function called, the value of self should be the same. It would be (object of testA with id = 1) too.
But, the thing I do not understand why is although the current item in the loop is 1, but the self in the computed function is one list of items with ids from 1 to 100?
This leads to an issue related to the performance. If the computed function taking to run about 5s for each call, we have 100 items here, it would take time to run is 5s * 100 = 500s. I see passing redundant items to self, it does not make sense, and it makes the time execution slower.
I do not know whether it should be an issue in Odoo or not. Anyone else, Can you explain its reason? and also the solution to bypass it.
Thank you!