Refactor model response inclusion to only include groups with multiple models; update model removal logic to accept hash value. See #221

This commit is contained in:
Will Miao
2025-06-11 19:52:44 +08:00
parent e0d9880b32
commit eb01ad3af9
6 changed files with 48 additions and 25 deletions

View File

@@ -132,8 +132,6 @@ export function appendLoraCards(loras) {
}
export async function resetAndReload(updateFolders = false) {
const pageState = getCurrentPageState();
// Check if virtual scroller is available
if (state.virtualScroller) {
return resetAndReloadWithVirtualScroll({

View File

@@ -2,6 +2,8 @@
import { showToast } from '../utils/uiHelpers.js';
import { state, getCurrentPageState } from '../state/index.js';
import { formatDate } from '../utils/formatters.js';
import { resetAndReload as resetAndReloadLoras } from '../api/loraApi.js';
import { resetAndReload as resetAndReloadCheckpoints } from '../api/checkpointApi.js';
export class ModelDuplicatesManager {
constructor(pageManager, modelType = 'loras') {
@@ -536,11 +538,43 @@ export class ModelDuplicatesManager {
showToast(`Successfully deleted ${data.total_deleted} models`, 'success');
// Exit duplicate mode if deletions were successful
// If models were successfully deleted
if (data.total_deleted > 0) {
// Check duplicates count after deletion
this.checkDuplicatesCount();
this.exitDuplicateMode();
// Reload model data with updated folders
if (this.modelType === 'loras') {
await resetAndReloadLoras(true);
} else {
await resetAndReloadCheckpoints(true);
}
// Check if there are still duplicates
try {
const endpoint = `/api/${this.modelType}/find-duplicates`;
const dupResponse = await fetch(endpoint);
if (!dupResponse.ok) {
throw new Error(`Failed to get duplicates: ${dupResponse.statusText}`);
}
const dupData = await dupResponse.json();
const remainingDuplicatesCount = (dupData.duplicates || []).length;
// Update badge count
this.updateDuplicatesBadge(remainingDuplicatesCount);
// If no more duplicates, exit duplicate mode
if (remainingDuplicatesCount === 0) {
this.exitDuplicateMode();
} else {
// If duplicates remain, refresh duplicate groups display
this.duplicateGroups = dupData.duplicates || [];
this.selectedForDeletion.clear();
this.renderDuplicateGroups();
this.updateSelectedCount();
}
} catch (error) {
console.error('Error checking remaining duplicates:', error);
}
}
} catch (error) {