10
0
mirror of https://github.com/LCPQ/QUESTDB_website.git synced 2024-12-25 05:43:46 +01:00

Accelerated load time

This commit is contained in:
Anthony Scemama 2020-11-16 12:44:21 +01:00
parent b16f494beb
commit 8961e3e06a
4 changed files with 71 additions and 7 deletions

View File

@ -1,8 +1,11 @@
default:
default: data
hugo
serve:
serve: data
hugo -D server
clean:
rm -rf public
data:
python3 tools/generate_data.py

View File

@ -232,7 +232,8 @@ class dataFileBase {
return /^#\s*([A-Za-z_]+)\s*:\s*(.*)$/;
}
async getGeometryAsync(state = null) {
var text = await getTextFromFileUrlAsync(`/data/structures/${this.set.name.replace("#", "")}/${this.molecule.toLowerCase()}.xyz`)
// var text = await getTextFromFileUrlAsync(`/data/structures/${this.set.name.replace("#", "")}/${this.molecule.toLowerCase()}.xyz`)
var text = getTextFromFileUrl(`/data/structures/${this.set.name.replace("#", "")}/${this.molecule.toLowerCase()}.xyz`)
var lines = text.split("\n")
var indexes = lines.findAllIndexes((line) => {
return line.match(/^\d+$/)
@ -279,7 +280,8 @@ class dataFileBase {
case String.name:
file = getFullDataPath(file)
const maxAge= (DebugMode.Enabled,0,600)
var str = await getTextFromFileUrlAsync(file,{"Cache-Control":`max-age=${maxAge}`})
// var str = await getTextFromFileUrlAsync(file,{"Cache-Control":`max-age=${maxAge}`})
var str = await getTextFromFileUrl(file)
break;
case File.name:
var str = await getTextFromUploadedFileAsync(file)

View File

@ -1,3 +1,33 @@
var fileCache = function () {
var json_url = "/data/database.json";
var req = new XMLHttpRequest();
req.open("GET",json_url, true);
req.responseType = 'json';
return new Promise(function (resolve, reject) {
req.onreadystatechange = function() {
if (req.readyState == 4) {
if (req.status == 200 || req.status==304) {//when a good response is given do this
resolve(req.response);
} else {
reject({
status: req.status,
statusText: req.statusText
});
}
}
}
req.send();
});
}
_cache = fileCache();
async function getTextFromFileUrl(url,header={}) {
var cache = await _cache;
return cache[url];
}
async function getTextFromFileUrlAsync(url,header={}) {
return new Promise(function (resolve, reject) {
var req = new XMLHttpRequest();
@ -21,7 +51,6 @@ async function getTextFromFileUrlAsync(url,header={}) {
req.send();
});
}
async function getTextFromUploadedFileAsync(inputFile){
const temporaryFileReader = new FileReader();

30
tools/generate_data.py Executable file
View File

@ -0,0 +1,30 @@
#!/usr/bin/env python3
import os
import os.path
import json
def main():
d = {}
os.chdir("static")
try:
os.remove(os.path.join("data","database.json"))
except FileNotFoundError:
pass
for root, dirs, files in os.walk('data'):
for name in files:
filename = os.path.join(root,name)
with open(filename,'r',encoding="utf8") as f:
try:
d["/"+filename] = f.read()
except UnicodeDecodeError:
pass
with open(os.path.join("data","database.json"),'w') as f:
f.write(json.dumps(d,indent=1))
if __name__ == "__main__":
main()