optimization for extra networks sorting

This commit is contained in:
AUTOMATIC1111 2024-03-08 17:09:11 +03:00
parent 3bd75adb1c
commit 530fea2bc4
2 changed files with 11 additions and 9 deletions

View File

@ -37,7 +37,8 @@ class NetworkOnDisk:
try: try:
self.metadata = cache.cached_data_for_file('safetensors-metadata', "lora/" + self.name, filename, read_metadata) self.metadata = cache.cached_data_for_file('safetensors-metadata', "lora/" + self.name, filename, read_metadata)
except Exception as e: except Exception as e:
errors.display(e, f"reading lora {filename}") #errors.display(e, f"reading lora {filename}")
pass
if self.metadata: if self.metadata:
m = {} m = {}

View File

@ -71,7 +71,8 @@ function setupExtraNetworksForTab(tabname) {
}; };
var applySort = function(force) { 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 reverse = sort_dir.dataset.sortdir == "Descending";
var sortKey = sort_mode.dataset.sortmode.toLowerCase().replace("sort", "").replaceAll(" ", "_").replace(/_+$/, "").trim() || "name"; var sortKey = sort_mode.dataset.sortmode.toLowerCase().replace("sort", "").replaceAll(" ", "_").replace(/_+$/, "").trim() || "name";
sortKey = "sort" + sortKey.charAt(0).toUpperCase() + sortKey.slice(1); sortKey = "sort" + sortKey.charAt(0).toUpperCase() + sortKey.slice(1);
@ -82,9 +83,6 @@ function setupExtraNetworksForTab(tabname) {
} }
sort_mode.dataset.sortkey = sortKeyStore; sort_mode.dataset.sortkey = sortKeyStore;
cards.forEach(function(card) {
card.originalParentElement = card.parentElement;
});
var sortedCards = Array.from(cards); var sortedCards = Array.from(cards);
sortedCards.sort(function(cardA, cardB) { sortedCards.sort(function(cardA, cardB) {
var a = cardA.dataset[sortKey]; var a = cardA.dataset[sortKey];
@ -95,15 +93,18 @@ function setupExtraNetworksForTab(tabname) {
return (a < b ? -1 : (a > b ? 1 : 0)); return (a < b ? -1 : (a > b ? 1 : 0));
}); });
if (reverse) { if (reverse) {
sortedCards.reverse(); sortedCards.reverse();
} }
cards.forEach(function(card) {
card.remove(); parent.innerHTML = '';
});
var frag = document.createDocumentFragment();
sortedCards.forEach(function(card) { sortedCards.forEach(function(card) {
card.originalParentElement.appendChild(card); frag.appendChild(card);
}); });
parent.appendChild(frag);
}; };
search.addEventListener("input", function() { search.addEventListener("input", function() {