From 9a2a366e65cb33a7fe3b96240349d4471c265a06 Mon Sep 17 00:00:00 2001 From: bluelovers Date: Thu, 6 Jun 2024 09:47:52 +0800 Subject: [PATCH 1/3] chore: try getFavorites one by one https://github.com/Physton/sd-webui-prompt-all-in-one/issues/328 --- src/src/components/favorite.vue | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/src/components/favorite.vue b/src/src/components/favorite.vue index 19fef45..f34d950 100644 --- a/src/src/components/favorite.vue +++ b/src/src/components/favorite.vue @@ -120,10 +120,10 @@ export default { } }, emits: ['use'], - mounted() { - this.favorites.forEach(item => { - this.getFavorites(item.key) - }) + async mounted() { + for (const item of this.favorites) { + await this.getFavorites(item.key) + } }, methods: { formatTime(time) { @@ -134,7 +134,7 @@ export default { let favoriteItem = this.favorites.find(item => item.key === favoriteKey) if (!favoriteItem) return this.loading = true - this.gradioAPI.getFavorites(favoriteKey).then(res => { + return this.gradioAPI.getFavorites(favoriteKey).then(res => { if(res && res.length > 0){ // 倒序 res.reverse() From f304c5eb844e7df87d89708888391a3c6913561a Mon Sep 17 00:00:00 2001 From: bluelovers Date: Thu, 6 Jun 2024 17:43:11 +0800 Subject: [PATCH 2/3] refactor: try avoid request api at same time --- src/src/App.vue | 10 ++++---- src/src/components/favorite.vue | 8 +++---- src/src/utils/waitTick.js | 41 +++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 8 deletions(-) create mode 100644 src/src/utils/waitTick.js diff --git a/src/src/App.vue b/src/src/App.vue index a38be74..3c1bc39 100644 --- a/src/src/App.vue +++ b/src/src/App.vue @@ -173,6 +173,7 @@ import jsYaml from "js-yaml"; import {ref} from "vue"; import Hotkey from "@/components/hotkey.vue"; import ExtraNetworksPopup from "@/components/extraNetworksPopup.vue"; +import waitTick from "@/utils/waitTick"; export default { name: 'App', @@ -370,7 +371,7 @@ export default { this.gradioAPI.setData('languageCode', val).then(data => { }).catch(err => { }) - this.loadGroupTags() + waitTick.addWaitTick(() => this.loadGroupTags()) }, immediate: false, }, @@ -782,7 +783,7 @@ export default { } if (data.tagCompleteFile !== null) { this.tagCompleteFile = data.tagCompleteFile - this.$nextTick(() => { + waitTick.addWaitTick(() => { this.$refs.translateSetting.getCSV(this.tagCompleteFile) }) } else { @@ -870,7 +871,8 @@ export default { }) this.handlePaste() - this.loadGroupTags() + + waitTick.addWaitTick(() => this.loadGroupTags()) /*this.gradioAPI.getVersion().then(res => { this.version = res.version @@ -905,7 +907,7 @@ export default { }) }, loadGroupTags() { - this.gradioAPI.getGroupTags(this.languageCode).then(data => { + return this.gradioAPI.getGroupTags(this.languageCode).then(data => { if (!data || data === '') { this.groupTags = [] } else { diff --git a/src/src/components/favorite.vue b/src/src/components/favorite.vue index f34d950..9e174c7 100644 --- a/src/src/components/favorite.vue +++ b/src/src/components/favorite.vue @@ -120,10 +120,10 @@ export default { } }, emits: ['use'], - async mounted() { - for (const item of this.favorites) { - await this.getFavorites(item.key) - } + mounted() { + this.favorites.forEach(item => { + waitTick.addWaitTick(() => this.getFavorites(item.key)) + }) }, methods: { formatTime(time) { diff --git a/src/src/utils/waitTick.js b/src/src/utils/waitTick.js new file mode 100644 index 0000000..7b88810 --- /dev/null +++ b/src/src/utils/waitTick.js @@ -0,0 +1,41 @@ +import { nextTick } from 'vue' + +export default { + /** + * @types Function[] + */ + waitTickList: [], + startingTick: false, + /** + * + * @param cb Function + */ + addWaitTick(cb) { + this.waitTickList.push(cb) + return this.startWaitTick() + }, + + async execatueWaitTick() + { + if (this.startingTick) return + + this.startingTick = true + + while (this.waitTickList.length) { + const cb = this.waitTickList.shift() + await nextTick().then(cb) + } + + this.startingTick = false + }, + + async startWaitTick() { + if (!this.startingTick) + { + return nextTick(() => this.execatueWaitTick().catch(e => { + this.startingTick = false + return this.startWaitTick() + })) + } + } +} From bad38d50500fcabdf71809095cc59316a511c049 Mon Sep 17 00:00:00 2001 From: bluelovers Date: Sun, 9 Jun 2024 08:06:20 +0800 Subject: [PATCH 3/3] . --- src/src/components/favorite.vue | 3 ++- src/src/components/history.vue | 4 ++-- src/src/components/translateSetting.vue | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/src/components/favorite.vue b/src/src/components/favorite.vue index 9e174c7..081d706 100644 --- a/src/src/components/favorite.vue +++ b/src/src/components/favorite.vue @@ -78,6 +78,7 @@ import common from "@/utils/common"; import LanguageMixin from "@/mixins/languageMixin"; import IconSvg from "@/components/iconSvg.vue"; +import waitTick from '@/utils/waitTick'; export default { components: {IconSvg}, @@ -301,4 +302,4 @@ export default { }, } } - \ No newline at end of file + diff --git a/src/src/components/history.vue b/src/src/components/history.vue index 4bf12da..3d456c9 100644 --- a/src/src/components/history.vue +++ b/src/src/components/history.vue @@ -130,7 +130,7 @@ export default { let historyItem = this.histories.find(item => item.key === historyKey) if (!historyItem) return this.loading = true - this.gradioAPI.getHistories(historyKey).then(res => { + return this.gradioAPI.getHistories(historyKey).then(res => { if (res && res.length > 0) { // 倒序 res.reverse() @@ -282,4 +282,4 @@ export default { }, } } - \ No newline at end of file + diff --git a/src/src/components/translateSetting.vue b/src/src/components/translateSetting.vue index 4059dbe..c69a97e 100644 --- a/src/src/components/translateSetting.vue +++ b/src/src/components/translateSetting.vue @@ -267,7 +267,7 @@ Github: {{name}}` if (this.tagCompleteFilesLoading) return this.tagCompleteFilesLoading = true this.tagCompleteFiles = [] - this.gradioAPI.getCSVs().then(res => { + return this.gradioAPI.getCSVs().then(res => { this.tagCompleteFilesLoading = false if (!res || res.length <= 0) return this.tagCompleteFiles.push({ @@ -375,4 +375,4 @@ Github: {{name}}` }, }, } - \ No newline at end of file +