feat: reimport clears previous lora-manager data first (#52)

Clicking Import LoRA Data now deletes all existing lora-manager
category prompts before scanning, ensuring a clean reimport.
This commit is contained in:
Vito Sansevero
2026-04-03 08:26:15 -07:00
parent 7713cecba6
commit 890fd70ac5
2 changed files with 46 additions and 1 deletions
+32
View File
@@ -444,6 +444,38 @@ class PromptDatabase:
conn.commit()
return cursor.rowcount > 0
def delete_prompts_by_category(self, category: str) -> int:
"""Delete all prompts with the given category.
Returns:
Number of prompts deleted.
"""
with self.model.get_connection() as conn:
# Get IDs first for cascade cleanup
ids = [
r[0]
for r in conn.execute(
"SELECT id FROM prompts WHERE category = ?", (category,)
).fetchall()
]
if not ids:
return 0
placeholders = ",".join("?" * len(ids))
conn.execute(
f"DELETE FROM generated_images WHERE prompt_id IN ({placeholders})",
ids,
)
conn.execute(
f"DELETE FROM prompt_tags WHERE prompt_id IN ({placeholders})",
ids,
)
cursor = conn.execute(
f"DELETE FROM prompts WHERE id IN ({placeholders})",
ids,
)
conn.commit()
return cursor.rowcount
def get_all_categories(self) -> List[str]:
"""
Get all unique categories from the database.
+14 -1
View File
@@ -191,11 +191,24 @@ class LoraIntegrationMixin:
await send_progress(
{
"type": "progress",
"status": "Finding LoRA directories...",
"status": "Clearing previous lora-manager imports...",
"progress": 0,
}
)
# Clear previous imports so reimport is always clean
await self._run_in_executor(
self.db.delete_prompts_by_category, "lora-manager"
)
await send_progress(
{
"type": "progress",
"status": "Finding LoRA directories...",
"progress": 2,
}
)
lora_dirs = await self._run_in_executor(find_lora_directories, lm_path)
# Collect all metadata files