web4bio / webgen

WebGen Vertically Integrated Project
https://web4bio.github.io/webgen/main/html/
11 stars 26 forks source link

Update the app to use IndexedDB to save Sequence data #355

Closed ericr491 closed 2 years ago

ericr491 commented 2 years ago
kaczmarj commented 2 years ago

@ericr491 - i really like your current implementation with the cache object!

kaczmarj commented 2 years ago

@ericr491 - the changes look good to me. just two small comments. i would remove the big commented block of code at the bottom of the database file. i put the commented code below so we can use it as a reference for later.

lokiFetch, lokiRefetch, lokiTest ```javascript lokiFetch = async (url) => { if (db) { const queries = db.getCollection("queries"); if (queries) { const apiCall = await queries.findOne({ url }); if (apiCall && !(Math.floor(new Date().getTime() / 1000.0) - apiCall.dt >= 1209600)) { return apiCall.data; } else { return lokiRefetch(url); } } } else { console.warn("Loki library is not loaded in properly, no caching available."); try { const response = await fetch(url); if (response.ok) return await response.json(); else if (fetchedClinicalData.status === 404) { return Promise.reject({}); } else { throw new Error("Failed to fetch."); } } catch (e) { console.error(e); return Promise.reject({}); } } }; lokiRefetch = async (url) => { const queries = db.getCollection("queries"); try { const result = await fetch(url); if (result.ok) { const json = await result.json(); queries.insert({ url, data: json, dt: Math.floor(new Date().getTime() / 1000.0) }); db.saveDatabase((err) => { if (err) { console.error(err); } }); return json; } else if (result.status === 404) { return Promise.reject({}); // obtain result via await } else { throw new Error("Failed to fetch."); } } catch (e) { console.error(e); return Promise.reject({}); } }; lokiTest = () => { const queries = db.getCollection("queries"); let queriesCount = queries.count(); queries.insert({ url: "localhost", data: [{ asdf: "asdf" }], dt: Math.floor(new Date().getTime() / 1000.0) }); queriesCount = queries.count(); console.log(`old number of entries in database : ${ queriesCount}`); db.saveDatabase((err) => { if (err) { console.error(err); } else { console.log("Saved"); } }); }; ```

also let's resolve the conflicts and update the use of the cache object in the code base. then this will be good to merge on my end

kaczmarj commented 2 years ago

@ericr491 - did you want to make additional changes or is this ready to merge?