Repository: AUTOMATIC1111/stable-diffusion-webui

Issue:
[Bug] Lora activation string is not applied to the prompt
### Checklist

- [ ] The issue exists after disabling all extensions
- [ ] The issue exists on a clean installation of webui
- [ ] The issue is caused by an extension, but I believe it is caused by a bug in the webui
- [X] The issue exists in the current version of the webui
- [X] The issue has not been reported before recently
- [ ] The issue has been reported before but has not been fixed yet

### What happened?

After upgrading to v1.8.0 when I add a Lora activation string in the Lora details window that string is not applied to the prompt when I click the Lora in the Lora selection tab. The Lora string ( \<some-kind-of-lora:1.0\> ) is added but no activation string is added after that.

This happens only with newly added Loras (and also on old Loras where I didn't edited the activation string). If I had already defined activation strings on older Loras I can edit them and the recent changes are reflected on the prompt when I select the Lora. 

windows11
version: [v1.8.0] •  python: 3.10.6  •  torch: 2.0.1+cu118  •  xformers: N/A  •  gradio: 3.41.2

### Steps to reproduce the problem

1. go to lora selection tab
2. click edit details on a Lora (with no activation string defined)
3. add an activation string
4. click on the lora and check the string added to the prompt

### What should have happened?

the new activation string should appear after the lora reference: "\<a-lora:1.0\> some-activation-string"

### What browsers do you use to access the UI ?

Mozilla Firefox, Microsoft Edge

### Sysinfo

-

### Console logs

```Shell
-
```


### Additional information

_No response_


Discussion:

Resolving patch:
diff --git a/modules/ui_extra_networks_user_metadata.py b/modules/ui_extra_networks_user_metadata.py
--- a/modules/ui_extra_networks_user_metadata.py
+++ b/modules/ui_extra_networks_user_metadata.py
@@ -133,8 +133,10 @@ def write_user_metadata(self, name, metadata):
         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 @@ def setup_ui(self, gallery):
             inputs=[self.edit_name_input],
             outputs=[]
         )
-
-
-
diff --git a/modules/util.py b/modules/util.py
--- a/modules/util.py
+++ b/modules/util.py
@@ -81,6 +81,17 @@ def __init__(self, dirname):
         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 @@ def mctime(self, path):
     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)


Test patch: