From 944ecff9ceb7338ce9d58b817cb958f24de90de8 Mon Sep 17 00:00:00 2001 From: newtextdoc1111 Date: Sun, 13 Jul 2025 22:21:21 +0900 Subject: [PATCH 1/3] fix: Implement maximum tag length check for performance issue --- web/js/autocomplete.js | 9 ++++++--- web/js/data.js | 5 +++-- web/js/related-tags.js | 7 ++++--- web/js/settings.js | 13 ++++++++++++- web/js/utils.js | 11 +++++++++++ 5 files changed, 36 insertions(+), 9 deletions(-) diff --git a/web/js/autocomplete.js b/web/js/autocomplete.js index 91901fe..638cc05 100644 --- a/web/js/autocomplete.js +++ b/web/js/autocomplete.js @@ -5,9 +5,10 @@ import { getEnabledTagSourceInPriorityOrder } from './data.js'; import { - formatCountHumanReadable, + isLongText, hiraToKata, kataToHira, + formatCountHumanReadable, isContainsLetterOrNumber, normalizeTagToInsert, normalizeTagToSearch, @@ -82,8 +83,10 @@ function searchCompletionCandidates(textareaElement) { const ESCAPE_SEQUENCE = ["#", "/"]; // If the first string is that character, autocomplete will not be displayed. const partialTag = getCurrentPartialTag(textareaElement); - if (!partialTag || partialTag.length <= 0 || ESCAPE_SEQUENCE.some(seq => partialTag.startsWith(seq))) { - return []; // No valid input for autocomplete + if (!partialTag || partialTag.length <= 0 || + ESCAPE_SEQUENCE.some(seq => partialTag.startsWith(seq)) || + isLongText(partialTag)) { + return []; // No valid input for autocomplete } const exactMatches = []; diff --git a/web/js/data.js b/web/js/data.js index 0f57bfb..cd1e4f5 100644 --- a/web/js/data.js +++ b/web/js/data.js @@ -1,4 +1,4 @@ -import { settingValues } from "./settings.js"; +import { settingValues, updateMaxTagLength } from "./settings.js"; // --- Constants --- @@ -158,6 +158,8 @@ async function loadTags(csvUrl, siteName) { // Create a TagData instance instead of a plain object const tagData = new TagData(tag, aliases, category, count, siteName); + updateMaxTagLength(tag.length); + autoCompleteData[siteName].sortedTags.push(tagData); } else { console.warn(`[Autocomplete-Plus] Invalid CSV format in line ${i + 1} of ${csvUrl}: ${line}. Expected ${TAGS_CSV_HEADER_COLUMNS.length} columns, but got ${columns.length}.`); @@ -326,7 +328,6 @@ export async function initializeData(csvListData, source) { const startTime = performance.now(); autoCompleteData[source].isInitializing = true; - // console.log("[Autocomplete-Plus] Initializing autocomplete data..."); try { // Store functions that return Promises (Promise Factories) diff --git a/web/js/related-tags.js b/web/js/related-tags.js index e1f779e..b68b5a8 100644 --- a/web/js/related-tags.js +++ b/web/js/related-tags.js @@ -1,13 +1,14 @@ -import { TagSource, TagCategory, TagData, autoCompleteData } from './data.js'; +import { TagCategory, TagData, TagSource, autoCompleteData } from './data.js'; import { settingValues } from './settings.js'; import { extractTagsFromTextArea, findAllTagPositions, + getCurrentTagRange, getViewportMargin, + isLongText, isValidTag, normalizeTagToInsert, normalizeTagToSearch, - getCurrentTagRange, } from './utils.js'; // --- RelatedTags Logic --- @@ -309,7 +310,7 @@ class RelatedTagsUI { const currentTag = getTagFromCursorPosition(textareaElement); if (!this.isPinned) { - if (isValidTag(currentTag)) { + if (!isLongText(currentTag) && isValidTag(currentTag)) { this.currentTag = currentTag } else { this.hide(); diff --git a/web/js/settings.js b/web/js/settings.js index 6b93e98..4342852 100644 --- a/web/js/settings.js +++ b/web/js/settings.js @@ -17,8 +17,19 @@ export const settingValues = { // Internal logic settings _useFallbackAttachmentForEventListener: false, // Fallback to attach event listener when somthing goes wrong + _maxTagLength: 100, // Maximum tag length to prevent performance issues with long text input // Debugging settings (use internally) _hideWhenOutofFocus: true, // Hide UI when the input is out of focus _logprocessingTime: false, // Log processing time for debugging -} \ No newline at end of file +} + +/** + * Update the maximum tag length setting value. + * This function ensures that the maximum tag length is always at least as long as the new length provided. + * @param {number} newLength + */ +export function updateMaxTagLength(newLength) { + if(isNaN(newLength)) return; + settingValues._maxTagLength = Math.max(settingValues._maxTagLength, newLength); +} diff --git a/web/js/utils.js b/web/js/utils.js index ac0246d..203fbc2 100644 --- a/web/js/utils.js +++ b/web/js/utils.js @@ -1,3 +1,5 @@ +import { settingValues } from './settings.js'; + // --- Html String constants --- /** @@ -44,6 +46,15 @@ const REG_STRIP_TRAILING_PAREN = /(.*)(? settingValues._maxTagLength; +} + /** * Converts Hiragana to Katakana. * @param {string} str Input string. From 8b38ade1b9eaa0ff3529e1663ae2f2a6d8704de7 Mon Sep 17 00:00:00 2001 From: newtextdoc1111 Date: Sun, 13 Jul 2025 22:48:36 +0900 Subject: [PATCH 2/3] fix: Add optional chaining to prevent errors in isLongText function --- web/js/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/js/utils.js b/web/js/utils.js index 203fbc2..1d82a8e 100644 --- a/web/js/utils.js +++ b/web/js/utils.js @@ -52,7 +52,7 @@ const REG_WILDCARD_SIMPLE_WORD = /[^{}_|]+/g; * @return {boolean} True if the text is longer than the maximum tag length, false otherwise. */ export function isLongText(text) { - return text.length > settingValues._maxTagLength; + return text?.length > settingValues._maxTagLength; } /** From ea2ff76fabde9bb7b1562c56eafe9b3612554923 Mon Sep 17 00:00:00 2001 From: newtextdoc1111 Date: Sun, 13 Jul 2025 22:48:48 +0900 Subject: [PATCH 3/3] fix: Bump version to 1.2.1 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index b878941..336df52 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "comfyui-autocomplete-plus" description = "Autocomplete and Related Tag display for ComfyUI" -version = "1.2.0" +version = "1.2.1" license = {file = "LICENSE"} dependencies = ["",]