diff --git a/server.py b/server.py index 85a8964be..a8dc4a7d5 100644 --- a/server.py +++ b/server.py @@ -403,11 +403,19 @@ class PromptServer(): if overwrite is not None and (overwrite == "true" or overwrite == "1"): pass else: + # Get uploaded file size once + image.file.seek(0, 2) # Seek to end + uploaded_size = image.file.tell() + image.file.seek(0) # Reset to beginning + i = 1 while os.path.exists(filepath): - if compare_image_hash(filepath, image): #compare hash to prevent saving of duplicates with same name, fix for #3465 - image_is_duplicate = True - break + # Quick size comparison first + existing_size = os.path.getsize(filepath) + if existing_size == uploaded_size: + if compare_image_hash(filepath, image): #compare hash to prevent saving of duplicates with same name, fix for #3465 + image_is_duplicate = True + break filename = f"{split[0]} ({i}){split[1]}" filepath = os.path.join(full_output_folder, filename) i += 1