AlUlkesh / stable-diffusion-webui-images-browser

an images browse for stable-diffusion-webui
623 stars 111 forks source link

Stale Thumbnail Cache #209

Open deckar01 opened 1 year ago

deckar01 commented 1 year ago

When an image is deleted and a new image is generated with the same name, the thumbnail for the deleted image is shown. The hash of the image path is used for the thumbnail name, which does not change when the image's content changes.

Hashing the image's content would work, but can be resource intensive. A relatively inexpensive cache busting heuristic would be to append the modified time of the file to the end of the path when hashing.

AlUlkesh commented 1 year ago

Do you mean the thumbnail creation in the code, that's used if the Use optimized images in the thumbnail interface option is set? Or the internal Gradio thumbnail?

deckar01 commented 1 year ago

The optimized image.

image_path_hash = hashlib.md5(image_path.encode("utf-8")).hexdigest()

scripts/image_browser.py#L874

image_info = image_path + str(os.path.getmtime(image_path))
image_path_hash = hashlib.md5(image_info.encode("utf-8")).hexdigest()