From 76b9fbc267a9af137aee32d9a92e4a891ee4e122 Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 7 Jan 2025 08:21:09 +0100 Subject: [PATCH 1/5] perf: redirect transition list to card --- src/composables/useArrayData.js | 37 ++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/src/composables/useArrayData.js b/src/composables/useArrayData.js index fd6e3a9b3..d09030de1 100644 --- a/src/composables/useArrayData.js +++ b/src/composables/useArrayData.js @@ -124,8 +124,11 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) { const { limit } = filter; store.hasMoreData = limit && response.data.length >= limit; + if (!append && !isDialogOpened() && updateRouter) { + const res = updateStateParams(response.data); + if (res?.redirect) return; + } processData(response.data, { map: !!store.mapKey, append }); - if (!append && !isDialogOpened()) updateRouter && updateStateParams(); store.isLoading = false; canceller = null; @@ -259,7 +262,7 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) { if (Object.values(store.userParams).length) await fetch({}); } - function updateStateParams() { + function updateStateParams(data) { if (!route?.path) return; const newUrl = { path: route.path, query: { ...(route.query ?? {}) } }; if (store?.searchUrl) @@ -276,15 +279,15 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) { const { path } = matches.at(-1); const to = - store?.data?.length === 1 - ? path.replace(/\/(list|:id)|-list/, `/${store.data[0].id}`) + data?.length === 1 + ? path.replace(/\/(list|:id)|-list/, `/${data[0].id}`) : path.replace(/:id.*/, ''); if (route.path != to) { const pushUrl = { path: to }; if (to.endsWith('/list') || to.endsWith('/')) pushUrl.query = newUrl.query; - return router.push(pushUrl); + return router.push(pushUrl) && { redirect: true }; } } @@ -292,28 +295,32 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) { } function processData(data, { map = true, append = true }) { + let newData; + let newMap; if (!append) { - store.data = []; - store.map = new Map(); + newData = []; + newMap = new Map(); } - if (!Array.isArray(data)) store.data = data; - else if (!map && append) for (const row of data) store.data.push(row); + if (!Array.isArray(data)) newData = data; + else if (!map && append) for (const row of data) newData.push(row); else for (const row of data) { const key = row[store.mapKey]; const val = { ...row, key }; - if (key && store.map.has(key)) { + if (key && newMap.has(key)) { const { position } = store.map.get(key); val.position = position; - store.map.set(key, val); - store.data[position] = val; + newMap.set(key, val); + newData[position] = val; } else { - val.position = store.map.size; - store.map.set(key, val); - store.data.push(val); + val.position = newMap.size; + newMap.set(key, val); + newData.push(val); } } + store.data = data; + store.map = map; } const totalRows = computed(() => (store.data && store.data.length) || 0); From d8c3e6bce7e3afc1a73ae5207aed40aad9534ef7 Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 7 Jan 2025 08:24:37 +0100 Subject: [PATCH 2/5] perf: revert processData --- src/composables/useArrayData.js | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/src/composables/useArrayData.js b/src/composables/useArrayData.js index d09030de1..93d3a2e52 100644 --- a/src/composables/useArrayData.js +++ b/src/composables/useArrayData.js @@ -295,32 +295,28 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) { } function processData(data, { map = true, append = true }) { - let newData; - let newMap; if (!append) { - newData = []; - newMap = new Map(); + store.data = []; + store.map = new Map(); } - if (!Array.isArray(data)) newData = data; - else if (!map && append) for (const row of data) newData.push(row); + if (!Array.isArray(data)) store.data = data; + else if (!map && append) for (const row of data) store.data.push(row); else for (const row of data) { const key = row[store.mapKey]; const val = { ...row, key }; - if (key && newMap.has(key)) { + if (key && store.map.has(key)) { const { position } = store.map.get(key); val.position = position; - newMap.set(key, val); - newData[position] = val; + store.map.set(key, val); + store.data[position] = val; } else { - val.position = newMap.size; - newMap.set(key, val); - newData.push(val); + val.position = store.map.size; + store.map.set(key, val); + store.data.push(val); } } - store.data = data; - store.map = map; } const totalRows = computed(() => (store.data && store.data.length) || 0); From 97fee8d1d0f82dbf439a773c79024392fe70d519 Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 7 Jan 2025 08:26:33 +0100 Subject: [PATCH 3/5] perf: order --- src/composables/useArrayData.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/composables/useArrayData.js b/src/composables/useArrayData.js index 93d3a2e52..e59ee398f 100644 --- a/src/composables/useArrayData.js +++ b/src/composables/useArrayData.js @@ -128,11 +128,11 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) { const res = updateStateParams(response.data); if (res?.redirect) return; } - processData(response.data, { map: !!store.mapKey, append }); - store.isLoading = false; canceller = null; + processData(response.data, { map: !!store.mapKey, append }); + return response; } From 2505061b8c5fab22b9f9abfd435cf14c245ea69f Mon Sep 17 00:00:00 2001 From: alexm Date: Thu, 9 Jan 2025 08:06:35 +0100 Subject: [PATCH 4/5] perf: simplify if --- src/composables/useArrayData.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/composables/useArrayData.js b/src/composables/useArrayData.js index e59ee398f..f674b1dac 100644 --- a/src/composables/useArrayData.js +++ b/src/composables/useArrayData.js @@ -125,8 +125,7 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) { store.hasMoreData = limit && response.data.length >= limit; if (!append && !isDialogOpened() && updateRouter) { - const res = updateStateParams(response.data); - if (res?.redirect) return; + if (updateStateParams()?.redirect) return; } store.isLoading = false; canceller = null; From b28873c67df5b4be9dc6dbd8708ff891cf48370d Mon Sep 17 00:00:00 2001 From: alexm Date: Thu, 9 Jan 2025 08:30:23 +0100 Subject: [PATCH 5/5] perf: simplify if --- src/composables/useArrayData.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/composables/useArrayData.js b/src/composables/useArrayData.js index f674b1dac..412e17598 100644 --- a/src/composables/useArrayData.js +++ b/src/composables/useArrayData.js @@ -125,7 +125,7 @@ export function useArrayData(key = useRoute().meta.moduleName, userOptions) { store.hasMoreData = limit && response.data.length >= limit; if (!append && !isDialogOpened() && updateRouter) { - if (updateStateParams()?.redirect) return; + if (updateStateParams(response.data)?.redirect) return; } store.isLoading = false; canceller = null;