From 2d77cecfd7766aef42f34932d1e714935f7bf876 Mon Sep 17 00:00:00 2001 From: secondl1ght Date: Wed, 29 Nov 2023 12:35:38 -0700 Subject: [PATCH 1/3] update local table versions --- src/lib/sync/areas.js | 27 ++++++++++++++++++++++++--- src/lib/sync/elements.js | 30 +++++++++++++++++++++++++++--- src/lib/sync/events.js | 27 ++++++++++++++++++++++++--- src/lib/sync/reports.js | 29 ++++++++++++++++++++++++++--- src/lib/sync/users.js | 27 ++++++++++++++++++++++++--- 5 files changed, 125 insertions(+), 15 deletions(-) diff --git a/src/lib/sync/areas.js b/src/lib/sync/areas.js index 4a3f16aa..5d8c365d 100644 --- a/src/lib/sync/areas.js +++ b/src/lib/sync/areas.js @@ -8,9 +8,30 @@ axiosRetry(axios, { retries: 3 }); const limit = 500; export const areasSync = async () => { - // get areas from local + // clear v1 table if present await localforage .getItem('areas') + .then(function (value) { + if (value) { + localforage + .removeItem('areas') + .then(function () { + console.log('Key is cleared!'); + }) + .catch(function (err) { + areaError.set('Could not clear areas locally, please try again or contact BTC Map.'); + console.log(err); + }); + } + }) + .catch(function (err) { + areaError.set('Could not check areas locally, please try again or contact BTC Map.'); + console.log(err); + }); + + // get areas from local + await localforage + .getItem('areas_v2') .then(async function (value) { // get areas from API if initial sync if (!value) { @@ -48,7 +69,7 @@ export const areasSync = async () => { // set response to local localforage - .setItem('areas', areasData) + .setItem('areas_v2', areasData) // eslint-disable-next-line no-unused-vars .then(function (value) { // set response to store @@ -123,7 +144,7 @@ export const areasSync = async () => { // set updated areas locally localforage - .setItem('areas', areasData) + .setItem('areas_v2', areasData) // eslint-disable-next-line no-unused-vars .then(function (value) { // set updated areas to store diff --git a/src/lib/sync/elements.js b/src/lib/sync/elements.js index b0471b9e..afef88d8 100644 --- a/src/lib/sync/elements.js +++ b/src/lib/sync/elements.js @@ -10,9 +10,33 @@ const limit = 5000; export const elementsSync = async () => { mapLoading.set('Checking local cache...'); - // get elements from local + + // clear v1 table if present await localforage .getItem('elements') + .then(function (value) { + if (value) { + localforage + .removeItem('elements') + .then(function () { + console.log('Key is cleared!'); + }) + .catch(function (err) { + elementError.set( + 'Could not clear elements locally, please try again or contact BTC Map.' + ); + console.log(err); + }); + } + }) + .catch(function (err) { + elementError.set('Could not check elements locally, please try again or contact BTC Map.'); + console.log(err); + }); + + // get elements from local + await localforage + .getItem('elements_v2') .then(async function (value) { // get elements from API if initial sync if (!value) { @@ -58,7 +82,7 @@ export const elementsSync = async () => { mapLoading.set('Storing data...'); // set response to local localforage - .setItem('elements', elementsData) + .setItem('elements_v2', elementsData) // eslint-disable-next-line no-unused-vars .then(function (value) { mapLoading.set('Initial sync complete!'); @@ -144,7 +168,7 @@ export const elementsSync = async () => { mapLoading.set('Storing data...'); localforage - .setItem('elements', elementsData) + .setItem('elements_v2', elementsData) // eslint-disable-next-line no-unused-vars .then(function (value) { mapLoading.set('Map loading complete!'); diff --git a/src/lib/sync/events.js b/src/lib/sync/events.js index 4130c563..6bbf0beb 100644 --- a/src/lib/sync/events.js +++ b/src/lib/sync/events.js @@ -8,9 +8,30 @@ axiosRetry(axios, { retries: 3 }); const limit = 50000; export const eventsSync = async () => { - // get events from local + // clear v1 table if present await localforage .getItem('events') + .then(function (value) { + if (value) { + localforage + .removeItem('events') + .then(function () { + console.log('Key is cleared!'); + }) + .catch(function (err) { + eventError.set('Could not clear events locally, please try again or contact BTC Map.'); + console.log(err); + }); + } + }) + .catch(function (err) { + eventError.set('Could not check events locally, please try again or contact BTC Map.'); + console.log(err); + }); + + // get events from local + await localforage + .getItem('events_v2') .then(async function (value) { // get events from API if initial sync if (!value) { @@ -48,7 +69,7 @@ export const eventsSync = async () => { // set response to local localforage - .setItem('events', eventsData) + .setItem('events_v2', eventsData) // eslint-disable-next-line no-unused-vars .then(function (value) { // set response to store @@ -127,7 +148,7 @@ export const eventsSync = async () => { // set updated events locally localforage - .setItem('events', eventsData) + .setItem('events_v2', eventsData) // eslint-disable-next-line no-unused-vars .then(function (value) { // set updated events to store diff --git a/src/lib/sync/reports.js b/src/lib/sync/reports.js index 0568a5e8..a58b432e 100644 --- a/src/lib/sync/reports.js +++ b/src/lib/sync/reports.js @@ -8,9 +8,32 @@ axiosRetry(axios, { retries: 3 }); const limit = 20000; export const reportsSync = async () => { - // get reports from local + // clear v1 table if present await localforage .getItem('reports') + .then(function (value) { + if (value) { + localforage + .removeItem('reports') + .then(function () { + console.log('Key is cleared!'); + }) + .catch(function (err) { + reportError.set( + 'Could not clear reports locally, please try again or contact BTC Map.' + ); + console.log(err); + }); + } + }) + .catch(function (err) { + reportError.set('Could not check reports locally, please try again or contact BTC Map.'); + console.log(err); + }); + + // get reports from local + await localforage + .getItem('reports_v2') .then(async function (value) { // get reports from API if initial sync if (!value) { @@ -50,7 +73,7 @@ export const reportsSync = async () => { // set response to local localforage - .setItem('reports', reportsData) + .setItem('reports_v2', reportsData) // eslint-disable-next-line no-unused-vars .then(function (value) { // set response to store @@ -129,7 +152,7 @@ export const reportsSync = async () => { // set updated reports locally localforage - .setItem('reports', reportsData) + .setItem('reports_v2', reportsData) // eslint-disable-next-line no-unused-vars .then(function (value) { // set updated reports to store diff --git a/src/lib/sync/users.js b/src/lib/sync/users.js index e78d2d6a..1ef6aa6f 100644 --- a/src/lib/sync/users.js +++ b/src/lib/sync/users.js @@ -29,9 +29,30 @@ export const usersSync = async () => { console.log(err); }); - // get users from local + // clear v2 table if present await localforage .getItem('users_v2') + .then(function (value) { + if (value) { + localforage + .removeItem('users_v2') + .then(function () { + console.log('Key is cleared!'); + }) + .catch(function (err) { + userError.set('Could not clear users locally, please try again or contact BTC Map.'); + console.log(err); + }); + } + }) + .catch(function (err) { + userError.set('Could not check users locally, please try again or contact BTC Map.'); + console.log(err); + }); + + // get users from local + await localforage + .getItem('users_v3') .then(async function (value) { // get users from API if initial sync if (!value) { @@ -69,7 +90,7 @@ export const usersSync = async () => { // set response to local localforage - .setItem('users_v2', usersData) + .setItem('users_v3', usersData) // eslint-disable-next-line no-unused-vars .then(function (value) { // set response to store @@ -144,7 +165,7 @@ export const usersSync = async () => { // set updated users locally localforage - .setItem('users_v2', usersData) + .setItem('users_v3', usersData) // eslint-disable-next-line no-unused-vars .then(function (value) { // set updated users to store From 86a4797e4dcffff7cf4236b4e1b52e4ebf740b9e Mon Sep 17 00:00:00 2001 From: secondl1ght Date: Wed, 29 Nov 2023 12:40:50 -0700 Subject: [PATCH 2/3] remove netlify toml --- netlify.toml | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 netlify.toml diff --git a/netlify.toml b/netlify.toml deleted file mode 100644 index 8dae2b77..00000000 --- a/netlify.toml +++ /dev/null @@ -1,4 +0,0 @@ -[[headers]] - for = "/images/communities/*" - [headers.values] - Cache-Control = "public, max-age=15552000" From bef91b4e5c2c8b0a6ee93d04dabef3a36134d2b0 Mon Sep 17 00:00:00 2001 From: secondl1ght Date: Thu, 30 Nov 2023 21:03:16 -0700 Subject: [PATCH 3/3] fix sync --- src/lib/sync/areas.js | 40 ++++++++++++++++++++++++++++++++------ src/lib/sync/elements.js | 40 ++++++++++++++++++++++++++++++++------ src/lib/sync/events.js | 40 ++++++++++++++++++++++++++++++++------ src/lib/sync/reports.js | 42 ++++++++++++++++++++++++++++++++++------ src/lib/sync/users.js | 40 ++++++++++++++++++++++++++++++++------ 5 files changed, 172 insertions(+), 30 deletions(-) diff --git a/src/lib/sync/areas.js b/src/lib/sync/areas.js index 5d8c365d..71d836be 100644 --- a/src/lib/sync/areas.js +++ b/src/lib/sync/areas.js @@ -29,9 +29,30 @@ export const areasSync = async () => { console.log(err); }); - // get areas from local + // clear v2 table if present await localforage .getItem('areas_v2') + .then(function (value) { + if (value) { + localforage + .removeItem('areas_v2') + .then(function () { + console.log('Key is cleared!'); + }) + .catch(function (err) { + areaError.set('Could not clear areas locally, please try again or contact BTC Map.'); + console.log(err); + }); + } + }) + .catch(function (err) { + areaError.set('Could not check areas locally, please try again or contact BTC Map.'); + console.log(err); + }); + + // get areas from local + await localforage + .getItem('areas_v3') .then(async function (value) { // get areas from API if initial sync if (!value) { @@ -48,7 +69,10 @@ export const areasSync = async () => { if (response.data.length) { updatedSince = response.data[response.data.length - 1]['updated_at']; responseCount = response.data.length; - areasData.filter((area) => !response.data.find((data) => data.id === area.id)); + const areasUpdated = areasData.filter( + (area) => !response.data.find((data) => data.id === area.id) + ); + areasData = areasUpdated; response.data.forEach((data) => areasData.push(data)); } else { areaError.set( @@ -69,7 +93,7 @@ export const areasSync = async () => { // set response to local localforage - .setItem('areas_v2', areasData) + .setItem('areas_v3', areasData) // eslint-disable-next-line no-unused-vars .then(function (value) { // set response to store @@ -109,13 +133,14 @@ export const areasSync = async () => { updatedSince = newAreas[newAreas.length - 1]['updated_at']; responseCount = newAreas.length; - areasData.filter((value) => { + const areasUpdated = areasData.filter((value) => { if (newAreas.find((area) => area.id === value.id)) { return false; } else { return true; } }); + areasData = areasUpdated; // add new areas newAreas.forEach((area) => { @@ -144,7 +169,7 @@ export const areasSync = async () => { // set updated areas locally localforage - .setItem('areas_v2', areasData) + .setItem('areas_v3', areasData) // eslint-disable-next-line no-unused-vars .then(function (value) { // set updated areas to store @@ -178,7 +203,10 @@ export const areasSync = async () => { if (response.data.length) { updatedSince = response.data[response.data.length - 1]['updated_at']; responseCount = response.data.length; - areasData.filter((area) => !response.data.find((data) => data.id === area.id)); + const areasUpdated = areasData.filter( + (area) => !response.data.find((data) => data.id === area.id) + ); + areasData = areasUpdated; response.data.forEach((data) => areasData.push(data)); } else { areaError.set( diff --git a/src/lib/sync/elements.js b/src/lib/sync/elements.js index afef88d8..91682e76 100644 --- a/src/lib/sync/elements.js +++ b/src/lib/sync/elements.js @@ -34,9 +34,32 @@ export const elementsSync = async () => { console.log(err); }); - // get elements from local + // clear v2 table if present await localforage .getItem('elements_v2') + .then(function (value) { + if (value) { + localforage + .removeItem('elements_v2') + .then(function () { + console.log('Key is cleared!'); + }) + .catch(function (err) { + elementError.set( + 'Could not clear elements locally, please try again or contact BTC Map.' + ); + console.log(err); + }); + } + }) + .catch(function (err) { + elementError.set('Could not check elements locally, please try again or contact BTC Map.'); + console.log(err); + }); + + // get elements from local + await localforage + .getItem('elements_v3') .then(async function (value) { // get elements from API if initial sync if (!value) { @@ -59,9 +82,10 @@ export const elementsSync = async () => { if (response.data.length) { updatedSince = response.data[response.data.length - 1]['updated_at']; responseCount = response.data.length; - elementsData.filter( + const elementsUpdated = elementsData.filter( (element) => !response.data.find((data) => data.id === element.id) ); + elementsData = elementsUpdated; response.data.forEach((data) => elementsData.push(data)); } else { elementError.set( @@ -82,7 +106,7 @@ export const elementsSync = async () => { mapLoading.set('Storing data...'); // set response to local localforage - .setItem('elements_v2', elementsData) + .setItem('elements_v3', elementsData) // eslint-disable-next-line no-unused-vars .then(function (value) { mapLoading.set('Initial sync complete!'); @@ -131,13 +155,14 @@ export const elementsSync = async () => { updatedSince = newElements[newElements.length - 1]['updated_at']; responseCount = newElements.length; - elementsData.filter((value) => { + const elementsUpdated = elementsData.filter((value) => { if (newElements.find((element) => element.id === value.id)) { return false; } else { return true; } }); + elementsData = elementsUpdated; // add new elements newElements.forEach((element) => { @@ -168,7 +193,7 @@ export const elementsSync = async () => { mapLoading.set('Storing data...'); localforage - .setItem('elements_v2', elementsData) + .setItem('elements_v3', elementsData) // eslint-disable-next-line no-unused-vars .then(function (value) { mapLoading.set('Map loading complete!'); @@ -217,7 +242,10 @@ export const elementsSync = async () => { if (response.data.length) { updatedSince = response.data[response.data.length - 1]['updated_at']; responseCount = response.data.length; - elementsData.filter((element) => !response.data.find((data) => data.id === element.id)); + const elementsUpdated = elementsData.filter( + (element) => !response.data.find((data) => data.id === element.id) + ); + elementsData = elementsUpdated; response.data.forEach((data) => elementsData.push(data)); } else { elementError.set( diff --git a/src/lib/sync/events.js b/src/lib/sync/events.js index 6bbf0beb..a2b96669 100644 --- a/src/lib/sync/events.js +++ b/src/lib/sync/events.js @@ -29,9 +29,30 @@ export const eventsSync = async () => { console.log(err); }); - // get events from local + // clear v2 table if present await localforage .getItem('events_v2') + .then(function (value) { + if (value) { + localforage + .removeItem('events_v2') + .then(function () { + console.log('Key is cleared!'); + }) + .catch(function (err) { + eventError.set('Could not clear events locally, please try again or contact BTC Map.'); + console.log(err); + }); + } + }) + .catch(function (err) { + eventError.set('Could not check events locally, please try again or contact BTC Map.'); + console.log(err); + }); + + // get events from local + await localforage + .getItem('events_v3') .then(async function (value) { // get events from API if initial sync if (!value) { @@ -48,7 +69,10 @@ export const eventsSync = async () => { if (response.data.length) { updatedSince = response.data[response.data.length - 1]['updated_at']; responseCount = response.data.length; - eventsData.filter((event) => !response.data.find((data) => data.id === event.id)); + const eventsUpdated = eventsData.filter( + (event) => !response.data.find((data) => data.id === event.id) + ); + eventsData = eventsUpdated; response.data.forEach((data) => eventsData.push(data)); } else { eventError.set( @@ -69,7 +93,7 @@ export const eventsSync = async () => { // set response to local localforage - .setItem('events_v2', eventsData) + .setItem('events_v3', eventsData) // eslint-disable-next-line no-unused-vars .then(function (value) { // set response to store @@ -111,13 +135,14 @@ export const eventsSync = async () => { updatedSince = newEvents[newEvents.length - 1]['updated_at']; responseCount = newEvents.length; - eventsData.filter((value) => { + const eventsUpdated = eventsData.filter((value) => { if (newEvents.find((event) => event.id === value.id)) { return false; } else { return true; } }); + eventsData = eventsUpdated; // add new events newEvents.forEach((event) => { @@ -148,7 +173,7 @@ export const eventsSync = async () => { // set updated events locally localforage - .setItem('events_v2', eventsData) + .setItem('events_v3', eventsData) // eslint-disable-next-line no-unused-vars .then(function (value) { // set updated events to store @@ -184,7 +209,10 @@ export const eventsSync = async () => { if (response.data.length) { updatedSince = response.data[response.data.length - 1]['updated_at']; responseCount = response.data.length; - eventsData.filter((event) => !response.data.find((data) => data.id === event.id)); + const eventsUpdated = eventsData.filter( + (event) => !response.data.find((data) => data.id === event.id) + ); + eventsData = eventsUpdated; response.data.forEach((data) => eventsData.push(data)); } else { eventError.set( diff --git a/src/lib/sync/reports.js b/src/lib/sync/reports.js index a58b432e..82578fc3 100644 --- a/src/lib/sync/reports.js +++ b/src/lib/sync/reports.js @@ -31,9 +31,32 @@ export const reportsSync = async () => { console.log(err); }); - // get reports from local + // clear v2 table if present await localforage .getItem('reports_v2') + .then(function (value) { + if (value) { + localforage + .removeItem('reports_v2') + .then(function () { + console.log('Key is cleared!'); + }) + .catch(function (err) { + reportError.set( + 'Could not clear reports locally, please try again or contact BTC Map.' + ); + console.log(err); + }); + } + }) + .catch(function (err) { + reportError.set('Could not check reports locally, please try again or contact BTC Map.'); + console.log(err); + }); + + // get reports from local + await localforage + .getItem('reports_v3') .then(async function (value) { // get reports from API if initial sync if (!value) { @@ -50,7 +73,10 @@ export const reportsSync = async () => { if (response.data.length) { updatedSince = response.data[response.data.length - 1]['updated_at']; responseCount = response.data.length; - reportsData.filter((report) => !response.data.find((data) => data.id === report.id)); + const reportsUpdated = reportsData.filter( + (report) => !response.data.find((data) => data.id === report.id) + ); + reportsData = reportsUpdated; response.data.forEach((data) => reportsData.push(data)); } else { reportError.set( @@ -73,7 +99,7 @@ export const reportsSync = async () => { // set response to local localforage - .setItem('reports_v2', reportsData) + .setItem('reports_v3', reportsData) // eslint-disable-next-line no-unused-vars .then(function (value) { // set response to store @@ -115,13 +141,14 @@ export const reportsSync = async () => { updatedSince = newReports[newReports.length - 1]['updated_at']; responseCount = newReports.length; - reportsData.filter((value) => { + const reportsUpdated = reportsData.filter((value) => { if (newReports.find((report) => report.id === value.id)) { return false; } else { return true; } }); + reportsData = reportsUpdated; // add new reports newReports.forEach((report) => { @@ -152,7 +179,7 @@ export const reportsSync = async () => { // set updated reports locally localforage - .setItem('reports_v2', reportsData) + .setItem('reports_v3', reportsData) // eslint-disable-next-line no-unused-vars .then(function (value) { // set updated reports to store @@ -188,7 +215,10 @@ export const reportsSync = async () => { if (response.data.length) { updatedSince = response.data[response.data.length - 1]['updated_at']; responseCount = response.data.length; - reportsData.filter((report) => !response.data.find((data) => data.id === report.id)); + const reportsUpdated = reportsData.filter( + (report) => !response.data.find((data) => data.id === report.id) + ); + reportsData = reportsUpdated; response.data.forEach((data) => reportsData.push(data)); } else { reportError.set( diff --git a/src/lib/sync/users.js b/src/lib/sync/users.js index 1ef6aa6f..c5ea758e 100644 --- a/src/lib/sync/users.js +++ b/src/lib/sync/users.js @@ -50,9 +50,30 @@ export const usersSync = async () => { console.log(err); }); - // get users from local + // clear v3 table if present await localforage .getItem('users_v3') + .then(function (value) { + if (value) { + localforage + .removeItem('users_v3') + .then(function () { + console.log('Key is cleared!'); + }) + .catch(function (err) { + userError.set('Could not clear users locally, please try again or contact BTC Map.'); + console.log(err); + }); + } + }) + .catch(function (err) { + userError.set('Could not check users locally, please try again or contact BTC Map.'); + console.log(err); + }); + + // get users from local + await localforage + .getItem('users_v4') .then(async function (value) { // get users from API if initial sync if (!value) { @@ -69,7 +90,10 @@ export const usersSync = async () => { if (response.data.length) { updatedSince = response.data[response.data.length - 1]['updated_at']; responseCount = response.data.length; - usersData.filter((user) => !response.data.find((data) => data.id === user.id)); + const usersUpdated = usersData.filter( + (user) => !response.data.find((data) => data.id === user.id) + ); + usersData = usersUpdated; response.data.forEach((data) => usersData.push(data)); } else { userError.set( @@ -90,7 +114,7 @@ export const usersSync = async () => { // set response to local localforage - .setItem('users_v3', usersData) + .setItem('users_v4', usersData) // eslint-disable-next-line no-unused-vars .then(function (value) { // set response to store @@ -130,13 +154,14 @@ export const usersSync = async () => { updatedSince = newUsers[newUsers.length - 1]['updated_at']; responseCount = newUsers.length; - usersData.filter((value) => { + const usersUpdated = usersData.filter((value) => { if (newUsers.find((user) => user.id == value.id)) { return false; } else { return true; } }); + usersData = usersUpdated; // add new users newUsers.forEach((user) => { @@ -165,7 +190,7 @@ export const usersSync = async () => { // set updated users locally localforage - .setItem('users_v3', usersData) + .setItem('users_v4', usersData) // eslint-disable-next-line no-unused-vars .then(function (value) { // set updated users to store @@ -199,7 +224,10 @@ export const usersSync = async () => { if (response.data.length) { updatedSince = response.data[response.data.length - 1]['updated_at']; responseCount = response.data.length; - usersData.filter((user) => !response.data.find((data) => data.id === user.id)); + const usersUpdated = usersData.filter( + (user) => !response.data.find((data) => data.id === user.id) + ); + usersData = usersUpdated; response.data.forEach((data) => usersData.push(data)); } else { userError.set(