I have a model that creates a xml file and I have the data that goes into xml tags "mapped" with codes, the codes can change but not the name for what the code is. The max data that will be stored in the codes model is 100 records.
In the model that creates the xml I call a method that gets the code 70+ times. Before I had the codes hard coded in a dict in a python file that I imported. So looking for the code didn't need to do a SQL lookup. But if I run this method:
def get_code_item_code_by_name(self, name): code = self.env['hr.code.list'].get_code_from_name(name) if not code: raise ValidationError('WARNING: Something went wrong for fetching the code for data name "{}"'.format(name)) else: return code
it will cause a lot of overhead on the DB. Or not... I don't know and would appreciate if someone could tell me if this can cause a big DB overhead?
So is there a way to generate a global dict that is filled with {'name': 'code'} for all the data from the 'hr.code.list' model to be used in the methods that fetch data for different xml tags?
Or would such approach be less efficient and cause a bigger overhead than getting the data for every code when needed?
Is there a better approach?