From 2b26d8c59fccd82fc9e0daf8d315bebe01943dd7 Mon Sep 17 00:00:00 2001 From: Spythere Date: Sat, 1 Jan 2022 20:25:53 +0100 Subject: [PATCH] =?UTF-8?q?Uproszczono=20spos=C3=B3b=20zapyta=C5=84=20do?= =?UTF-8?q?=20API=20z=20danymi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/index.ts | 29 +++-------------------------- 1 file changed, 3 insertions(+), 26 deletions(-) diff --git a/src/store/index.ts b/src/store/index.ts index ed63af4..6cd9bca 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -89,37 +89,14 @@ export const store = createStore({ async synchronizeData({ commit, dispatch, state }) { if (state.listenerLaunched) return; - const queryDate = new Date(); - - const nextRefreshDate = new Date(); - - if (queryDate.getHours() < 8) - nextRefreshDate.setHours(8, 0, 0, 0); - else if (queryDate.getHours() < 20) - nextRefreshDate.setHours(20, 0, 0, 0); - else { - nextRefreshDate.setDate(nextRefreshDate.getDate() + 1); - nextRefreshDate.setHours(8, 0, 0, 0); - } - - let sceneryDataQuery = URLs.sceneryData; - if (!StorageManager.isRegistered("nextSceneryDataRefreshTime") || StorageManager.isRegistered("nextSceneryDataRefreshTime") - && queryDate.getTime() >= StorageManager.getNumericValue("nextSceneryDataRefreshTime")) { - StorageManager.setNumericValue("nextSceneryDataRefreshTime", nextRefreshDate.getTime()); - sceneryDataQuery += "?time=" + queryDate.getTime(); - } - - const sceneryData: StationJSONData = await (await axios.get(sceneryDataQuery)).data; + // Nowy parametr żądania co godzinę + const sceneryData: StationJSONData = await (await axios.get(`${URLs.sceneryData}?time=${Math.floor(Date.now() / 1800000)}`)).data; commit(MUTATIONS.SET_SCENERY_DATA, sceneryData); commit(MUTATIONS.SET_SCENERY_DATA_STATUS, DataStatus.Loaded); - dispatch(ACTIONS.fetchOnlineData); - - const randIntervalTime = Math.floor(Math.random() * 5000) + 25000; - - setInterval(() => dispatch(ACTIONS.fetchOnlineData), randIntervalTime); + setInterval(() => dispatch(ACTIONS.fetchOnlineData), Math.floor(Math.random() * 5000) + 2500); }, async fetchOnlineData({ commit, dispatch }) {