mirror of
https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
synced 2025-01-31 18:52:58 +08:00
Merge pull request #15199 from AUTOMATIC1111/add-entry-to-MassFileLister-after-writing-metadata
Add entry to MassFileLister after writing metadata
This commit is contained in:
commit
8076100e14
@ -133,8 +133,10 @@ class UserMetadataEditor:
|
||||
filename = item.get("filename", None)
|
||||
basename, ext = os.path.splitext(filename)
|
||||
|
||||
with open(basename + '.json', "w", encoding="utf8") as file:
|
||||
metadata_path = basename + '.json'
|
||||
with open(metadata_path, "w", encoding="utf8") as file:
|
||||
json.dump(metadata, file, indent=4, ensure_ascii=False)
|
||||
self.page.lister.update_file_entry(metadata_path)
|
||||
|
||||
def save_user_metadata(self, name, desc, notes):
|
||||
user_metadata = self.get_user_metadata(name)
|
||||
@ -200,6 +202,3 @@ class UserMetadataEditor:
|
||||
inputs=[self.edit_name_input],
|
||||
outputs=[]
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
@ -81,6 +81,17 @@ class MassFileListerCachedDir:
|
||||
self.files = {x[0].lower(): x for x in files}
|
||||
self.files_cased = {x[0]: x for x in files}
|
||||
|
||||
def update_entry(self, filename):
|
||||
"""Add a file to the cache"""
|
||||
file_path = os.path.join(self.dirname, filename)
|
||||
try:
|
||||
stat = os.stat(file_path)
|
||||
entry = (filename, stat.st_mtime, stat.st_ctime)
|
||||
self.files[filename.lower()] = entry
|
||||
self.files_cased[filename] = entry
|
||||
except FileNotFoundError as e:
|
||||
print(f'MassFileListerCachedDir.add_entry: "{file_path}" {e}')
|
||||
|
||||
|
||||
class MassFileLister:
|
||||
"""A class that provides a way to check for the existence and mtime/ctile of files without doing more than one stat call per file."""
|
||||
@ -136,3 +147,9 @@ class MassFileLister:
|
||||
def reset(self):
|
||||
"""Clear the cache of all directories."""
|
||||
self.cached_dirs.clear()
|
||||
|
||||
def update_file_entry(self, path):
|
||||
"""Update the cache for a specific directory."""
|
||||
dirname, filename = os.path.split(path)
|
||||
if cached_dir := self.cached_dirs.get(dirname):
|
||||
cached_dir.update_entry(filename)
|
||||
|
Loading…
Reference in New Issue
Block a user