I have a code that puts its data and declare it in a dictionary. I am currently having a long time in my for loop that is about 200,000 thousand datas taking about 2 hours. And now I am thinking what more if I have 2 million datas.
Here is my for loop example(Sorry for the naming of variables, this just my sample code):
# Gets the data in database
data_list = self.my_service.get_database_list()
my_dict_list = {}
for item in data_list:
primary_key = item.primarykey
value = item.name + item.address + item.age
my_dict_list[primary_key] = value
This is my model/db get code:
def get_database_list(self):
return self.session.query(
self.mapper.name,
self.mapper.addreess,
self.mapper.age,
)
My database engine is InnoDB. Is there a way to make it a bit optimize or loop through datas faster. Thank you for sharing.