From 530fea2bc4a2ab3412c76521961dd256b005a38b Mon Sep 17 00:00:00 2001 From: AUTOMATIC1111 <16777216c@gmail.com> Date: Fri, 8 Mar 2024 17:09:11 +0300 Subject: [PATCH] optimization for extra networks sorting --- extensions-builtin/Lora/network.py | 3 ++- javascript/extraNetworks.js | 17 +++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/extensions-builtin/Lora/network.py b/extensions-builtin/Lora/network.py index 2268b0f7e..b1426c6f7 100644 --- a/extensions-builtin/Lora/network.py +++ b/extensions-builtin/Lora/network.py @@ -37,7 +37,8 @@ class NetworkOnDisk: try: self.metadata = cache.cached_data_for_file('safetensors-metadata', "lora/" + self.name, filename, read_metadata) except Exception as e: - errors.display(e, f"reading lora {filename}") + #errors.display(e, f"reading lora {filename}") + pass if self.metadata: m = {} diff --git a/javascript/extraNetworks.js b/javascript/extraNetworks.js index ec6da69d8..b557d20d7 100644 --- a/javascript/extraNetworks.js +++ b/javascript/extraNetworks.js @@ -71,7 +71,8 @@ function setupExtraNetworksForTab(tabname) { }; var applySort = function(force) { - var cards = gradioApp().querySelectorAll('#' + tabname + '_extra_tabs div.card'); + var cards = gradioApp().querySelectorAll('#' + tabname_full + ' div.card'); + var parent = gradioApp().querySelector('#' + tabname_full + "_cards" ); var reverse = sort_dir.dataset.sortdir == "Descending"; var sortKey = sort_mode.dataset.sortmode.toLowerCase().replace("sort", "").replaceAll(" ", "_").replace(/_+$/, "").trim() || "name"; sortKey = "sort" + sortKey.charAt(0).toUpperCase() + sortKey.slice(1); @@ -82,9 +83,6 @@ function setupExtraNetworksForTab(tabname) { } sort_mode.dataset.sortkey = sortKeyStore; - cards.forEach(function(card) { - card.originalParentElement = card.parentElement; - }); var sortedCards = Array.from(cards); sortedCards.sort(function(cardA, cardB) { var a = cardA.dataset[sortKey]; @@ -95,15 +93,18 @@ function setupExtraNetworksForTab(tabname) { return (a < b ? -1 : (a > b ? 1 : 0)); }); + if (reverse) { sortedCards.reverse(); } - cards.forEach(function(card) { - card.remove(); - }); + + parent.innerHTML = ''; + + var frag = document.createDocumentFragment(); sortedCards.forEach(function(card) { - card.originalParentElement.appendChild(card); + frag.appendChild(card); }); + parent.appendChild(frag); }; search.addEventListener("input", function() {