From 6eb8717f55aade5b6405ebd482cdb4194c40c23d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20V=C3=A9ril?= Date: Sun, 1 Nov 2020 16:57:16 +0100 Subject: [PATCH] Save indexDB to window.indexDB automaticaly to avoid re-created it --- content/dataset.html | 2 +- static/js/indexDB.js | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/content/dataset.html b/content/dataset.html index 08b978cf..1a813649 100644 --- a/content/dataset.html +++ b/content/dataset.html @@ -126,7 +126,7 @@ draft: false window.defaultDats = window.defaultDats.concat(sub) } - window.indexDB = await indexDB.loadAsync() + await indexDB.loadAsync() window.defaultDats = window.defaultDats.sort((datfA, datfB) => { const exSetA = datfA.set const exSetB = datfB.set diff --git a/static/js/indexDB.js b/static/js/indexDB.js index e736599b..f5d3bb88 100644 --- a/static/js/indexDB.js +++ b/static/js/indexDB.js @@ -1,11 +1,15 @@ class indexDB { static async loadAsync() { + if (window.indexDB) { + return window.indexDB + } var db = new indexDB const maxAge= (DebugMode.Enabled,0,600) const text = await getTextFromFileUrlAsync("/data/index.yaml",{"Cache-Control":`max-age=${maxAge}`}) const myYaml = jsyaml.load(text); db.sets = ((myYaml.sets === null) ? new Map() : new Map(Object.entries(myYaml.sets))); db.others = ((myYaml.others === null) ? [] : Array.from(myYaml.others)); + window.indexDB=db return db } } \ No newline at end of file