mirror of
https://github.com/LCPQ/QUESTDB_website.git
synced 2024-12-25 13:53:48 +01:00
Performance improvement using the new DOICache class
This commit is contained in:
parent
1344c94807
commit
9cd212ab33
@ -16,10 +16,11 @@ draft: false
|
|||||||
<script src="/js/websiteFile.js"></script>
|
<script src="/js/websiteFile.js"></script>
|
||||||
<script src="https://cdn.rawgit.com/larsgw/citation.js/archive/citation.js/citation-0.4.0-9.js"
|
<script src="https://cdn.rawgit.com/larsgw/citation.js/archive/citation.js/citation-0.4.0-9.js"
|
||||||
type="text/javascript"></script>
|
type="text/javascript"></script>
|
||||||
|
<script src="/js/DOICache.js"></script>
|
||||||
<script src="https://unpkg.com/simple-statistics@7.0.2/dist/simple-statistics.min.js"></script>
|
<script src="https://unpkg.com/simple-statistics@7.0.2/dist/simple-statistics.min.js"></script>
|
||||||
<script>
|
<script>
|
||||||
window.onload = async () => {
|
window.onload = async () => {
|
||||||
window.Cite = require('citation-js');
|
window.doiCache = new DOICache()
|
||||||
$('#form_dat > fieldset > input[type=radio]').on('change', async function (event) {
|
$('#form_dat > fieldset > input[type=radio]').on('change', async function (event) {
|
||||||
processingIndicator.isActive = true
|
processingIndicator.isActive = true
|
||||||
$("#Geom_th,#GSGeom_th,#ESGeom_th").each(function () {
|
$("#Geom_th,#GSGeom_th,#ESGeom_th").each(function () {
|
||||||
@ -131,7 +132,7 @@ draft: false
|
|||||||
style: "white-space: nowrap;"
|
style: "white-space: nowrap;"
|
||||||
})
|
})
|
||||||
if (trueTypeOf(el) == "DOI") {
|
if (trueTypeOf(el) == "DOI") {
|
||||||
var publi = await window.Cite.async(el.string)
|
var publi = doiCache.get(el.string)
|
||||||
$("<a/>", {
|
$("<a/>", {
|
||||||
href: el.url,
|
href: el.url,
|
||||||
target: "_blank"
|
target: "_blank"
|
||||||
@ -190,6 +191,7 @@ draft: false
|
|||||||
processingIndicator.isActive = false
|
processingIndicator.isActive = false
|
||||||
}
|
}
|
||||||
async function reloadContent() {
|
async function reloadContent() {
|
||||||
|
doiCache.clear()
|
||||||
processingIndicator.isActive = true
|
processingIndicator.isActive = true
|
||||||
const LatexInline = ['\\(', '\\)']
|
const LatexInline = ['\\(', '\\)']
|
||||||
window.filt = window.dats
|
window.filt = window.dats
|
||||||
@ -206,6 +208,7 @@ draft: false
|
|||||||
var dtb = $("#dat_table > tbody");
|
var dtb = $("#dat_table > tbody");
|
||||||
dtb.empty()
|
dtb.empty()
|
||||||
sel_ref = $("#sel_ref")
|
sel_ref = $("#sel_ref")
|
||||||
|
await doiCache.addRange(window.filt.map((x)=>x.DOI.string))
|
||||||
for (const d of window.filt) {
|
for (const d of window.filt) {
|
||||||
var row = $("<tr/>")
|
var row = $("<tr/>")
|
||||||
var rowd = []
|
var rowd = []
|
||||||
@ -228,7 +231,7 @@ draft: false
|
|||||||
for (const el of tableels) {
|
for (const el of tableels) {
|
||||||
td=$(tdtemp).clone()
|
td=$(tdtemp).clone()
|
||||||
if (trueTypeOf(el) == "DOI") {
|
if (trueTypeOf(el) == "DOI") {
|
||||||
var publi = await window.Cite.async(el.string)
|
var publi = doiCache.get(el.string)
|
||||||
$("<a/>", {
|
$("<a/>", {
|
||||||
href: el.url,
|
href: el.url,
|
||||||
target: "_blank",
|
target: "_blank",
|
||||||
|
36
static/js/DOICache.js
Normal file
36
static/js/DOICache.js
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
class DOICache{
|
||||||
|
constructor(){
|
||||||
|
this._doimap=new Map()
|
||||||
|
this._Cite=require("citation-js")
|
||||||
|
}
|
||||||
|
clear(){
|
||||||
|
this._doimap.clear()
|
||||||
|
}
|
||||||
|
delete(doi){
|
||||||
|
return this._doimap.delete(doi)
|
||||||
|
}
|
||||||
|
forEach(callbackfn, thisArg=None){
|
||||||
|
return this._doimap.forEach(callbackfn,thisArg)
|
||||||
|
}
|
||||||
|
get(doi){
|
||||||
|
return this._doimap.get(doi)
|
||||||
|
}
|
||||||
|
has(doi){
|
||||||
|
return this._doimap.has(doi)
|
||||||
|
}
|
||||||
|
async add(doi){
|
||||||
|
if(!this.has(doi)){
|
||||||
|
const publi=await this._Cite.async(doi)
|
||||||
|
this._doimap.set(doi,publi)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async addRange(dois){
|
||||||
|
const set=new Set(dois)
|
||||||
|
for(const doi of set){
|
||||||
|
await this.add(doi)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
get size(){
|
||||||
|
return this._doimap.size()
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user