From 524ac65b0cb15999d73c201367f3ec21387a8bac Mon Sep 17 00:00:00 2001 From: owl1753 Date: Wed, 25 Sep 2024 17:17:39 +0900 Subject: [PATCH 1/4] =?UTF-8?q?fix:=2010=EB=B2=88=EC=A7=B8=20=EB=A1=9C?= =?UTF-8?q?=EA=B7=B8=20=EC=8C=93=EC=9D=BC=20=EC=8B=9C=20=EC=A6=89=EC=8B=9C?= =?UTF-8?q?=20=EC=A0=84=EC=86=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../logging-system/src/SetLocalStorage.ts | 34 +++++++------------ 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/packages/logging-system/src/SetLocalStorage.ts b/packages/logging-system/src/SetLocalStorage.ts index 44b3435..54d91d6 100644 --- a/packages/logging-system/src/SetLocalStorage.ts +++ b/packages/logging-system/src/SetLocalStorage.ts @@ -9,28 +9,20 @@ export const SetLocalStorage = async ( logger: LogType, putLog: (data: LogRequestList) => Promise ) => { - if (window.localStorage.getItem('yls-web') == undefined) { - const list: any[] = []; - list.push(logger); - localStorage.setItem('yls-web', JSON.stringify(list)); - } else { - const remainList: any[] = JSON.parse(localStorage.getItem('yls-web') as string) || []; - if (remainList.length < 10) { - const updateList = [...remainList, logger]; - localStorage.setItem('yls-web', JSON.stringify(updateList)); - } else { - const req: LogRequestList = { - logRequestList: remainList, - }; + const list: LogType[] = JSON.parse(localStorage.getItem('yls-web') as string) || []; + list.push(logger); + localStorage.setItem('yls-web', JSON.stringify(list)); + + if (list.length >= 10) { + const req: LogRequestList = { + logRequestList: list, + }; + SetLocalStorageClear(); - try { - const res = await putLog(req); - if (res.success) { - SetLocalStorageClear(); - } - } catch (e) { - console.error('Failed to post log'); - } + try { + await putLog(req); + } catch (e) { + console.error('Failed to post log'); } } }; From e1225c48c59e748781b888d67ed84e93d81b05b8 Mon Sep 17 00:00:00 2001 From: owl1753 Date: Wed, 25 Sep 2024 20:08:48 +0900 Subject: [PATCH 2/4] =?UTF-8?q?fix:=20=EC=A0=84=EC=86=A1=EC=97=90=20?= =?UTF-8?q?=EC=8B=A4=ED=8C=A8=ED=95=9C=20=EB=A1=9C=EA=B7=B8=20=EC=8A=A4?= =?UTF-8?q?=ED=86=A0=EB=A6=AC=EC=A7=80=EC=97=90=20=EC=8C=93=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../logging-system/src/SetLocalStorage.ts | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/packages/logging-system/src/SetLocalStorage.ts b/packages/logging-system/src/SetLocalStorage.ts index 54d91d6..54b45bb 100644 --- a/packages/logging-system/src/SetLocalStorage.ts +++ b/packages/logging-system/src/SetLocalStorage.ts @@ -1,8 +1,10 @@ import { LogRequestList, LogResponse, LogType } from './types/LogType'; -export const SetLocalStorageClear = () => { - const list: any[] = []; - localStorage.setItem('yls-web', JSON.stringify(list)); +const logSize = 10; + +export const SetLocalStorageSlice = () => { + const list: LogType[] = JSON.parse(localStorage.getItem('yls-web') as string) || []; + localStorage.setItem('yls-web', JSON.stringify(list.slice(logSize, list.length))); }; export const SetLocalStorage = async ( @@ -13,16 +15,21 @@ export const SetLocalStorage = async ( list.push(logger); localStorage.setItem('yls-web', JSON.stringify(list)); - if (list.length >= 10) { + const slicingList = list.slice(0, logSize); + + if (list.length >= logSize) { const req: LogRequestList = { - logRequestList: list, + logRequestList: slicingList, }; - SetLocalStorageClear(); + SetLocalStorageSlice(); try { await putLog(req); } catch (e) { console.error('Failed to post log'); + const remainList: LogType[] = JSON.parse(localStorage.getItem('yls-web') as string) || []; + remainList.unshift(...slicingList); + localStorage.setItem('yls-web', JSON.stringify(remainList)); } } }; From 1e1a3aeb9dbb8f1c55afcff502876867aeed4e24 Mon Sep 17 00:00:00 2001 From: owl1753 Date: Wed, 30 Oct 2024 13:01:28 +0900 Subject: [PATCH 3/4] =?UTF-8?q?fix:=20=EB=B3=B4=EB=82=B4=EC=A7=80=EC=A7=80?= =?UTF-8?q?=20=EC=95=8A=EC=9D=80=20=EB=A1=9C=EA=B7=B8=EB=8A=94=20=EB=8B=A4?= =?UTF-8?q?=EC=8B=9C=20=EB=A1=9C=EC=BB=AC=20=EC=8A=A4=ED=86=A0=EB=A6=AC?= =?UTF-8?q?=EC=A7=80=EC=97=90=20=EC=8C=93=EC=9D=B4=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../logging-system/src/SetLocalStorage.ts | 33 ++++++++----------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/packages/logging-system/src/SetLocalStorage.ts b/packages/logging-system/src/SetLocalStorage.ts index 54b45bb..158969f 100644 --- a/packages/logging-system/src/SetLocalStorage.ts +++ b/packages/logging-system/src/SetLocalStorage.ts @@ -1,10 +1,8 @@ import { LogRequestList, LogResponse, LogType } from './types/LogType'; -const logSize = 10; - -export const SetLocalStorageSlice = () => { - const list: LogType[] = JSON.parse(localStorage.getItem('yls-web') as string) || []; - localStorage.setItem('yls-web', JSON.stringify(list.slice(logSize, list.length))); +export const SetLocalStorageClear = () => { + const list: LogType[] = []; + localStorage.setItem('yls-web', JSON.stringify(list)); }; export const SetLocalStorage = async ( @@ -15,21 +13,18 @@ export const SetLocalStorage = async ( list.push(logger); localStorage.setItem('yls-web', JSON.stringify(list)); - const slicingList = list.slice(0, logSize); + const req: LogRequestList = { + logRequestList: list, + }; - if (list.length >= logSize) { - const req: LogRequestList = { - logRequestList: slicingList, - }; - SetLocalStorageSlice(); + SetLocalStorageClear(); - try { - await putLog(req); - } catch (e) { - console.error('Failed to post log'); - const remainList: LogType[] = JSON.parse(localStorage.getItem('yls-web') as string) || []; - remainList.unshift(...slicingList); - localStorage.setItem('yls-web', JSON.stringify(remainList)); - } + try { + await putLog(req); + } catch (e) { + console.error('Failed to post log'); + const remainList: LogType[] = JSON.parse(localStorage.getItem('yls-web') as string) || []; + remainList.unshift(...list); + localStorage.setItem('yls-web', JSON.stringify(remainList)); } }; From 5d440772672b92f79ce192ecc9c4f82366dd7426 Mon Sep 17 00:00:00 2001 From: owl1753 Date: Wed, 6 Nov 2024 16:09:07 +0900 Subject: [PATCH 4/4] =?UTF-8?q?fix:=20=EB=A1=9C=EA=B7=B8=EA=B0=80=2010?= =?UTF-8?q?=EA=B0=9C=20=EC=8C=93=EC=9D=B4=EB=A9=B4=20=EC=A0=84=EC=86=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../logging-system/src/SetLocalStorage.ts | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/packages/logging-system/src/SetLocalStorage.ts b/packages/logging-system/src/SetLocalStorage.ts index 158969f..583e89d 100644 --- a/packages/logging-system/src/SetLocalStorage.ts +++ b/packages/logging-system/src/SetLocalStorage.ts @@ -13,18 +13,20 @@ export const SetLocalStorage = async ( list.push(logger); localStorage.setItem('yls-web', JSON.stringify(list)); - const req: LogRequestList = { - logRequestList: list, - }; + if (list.length >= 10) { + const req: LogRequestList = { + logRequestList: list, + }; - SetLocalStorageClear(); + SetLocalStorageClear(); - try { - await putLog(req); - } catch (e) { - console.error('Failed to post log'); - const remainList: LogType[] = JSON.parse(localStorage.getItem('yls-web') as string) || []; - remainList.unshift(...list); - localStorage.setItem('yls-web', JSON.stringify(remainList)); + try { + await putLog(req); + } catch (e) { + console.error('Failed to post log'); + const remainList: LogType[] = JSON.parse(localStorage.getItem('yls-web') as string) || []; + remainList.unshift(...list); + localStorage.setItem('yls-web', JSON.stringify(remainList)); + } } };