I'm setting up a script and I'm trying to figure out why I'm forced to wait 60 seconds for the loading of my pages. I've developed a platform where I display some information about a file (its image and its details).
At the moment, I display the data of 10 folders containing around 10000 files each.
I'm using the Flask framework and FileAdmin to load my files. I've tried to analyze the time of each function in my code and I've obtained this:
all_the_files = glob.glob(directory + "/*.*") >>>>>>>> around 0.01s
for file in all_the_files:
if '_ex' in str(file):
try:
filename = str(file).split('/')[-1]
file_part1 = filename.split('_')[0]
file_part2 = filename.split('_')[1]
>>>>>> around 1e-05s for each
found_file = [file for file in all_the_files if re.match("^"+filename+".*", str(file).split('/')[-1])]
image_path = [file for file in found_file if re.match("^"+filename+".*"+"\.png", str(file).split('/')[-1])][0]
txt_path = [file for file in found_file if re.match("^"+filename+".*"+"\.txt", str(file).split('/')[-1])][0]
>>>>> around 0.02s for each file
With these time records, I know that the third function is too long for each file.
How can I manage to reduce the loading time of my pages?