mirror of
https://github.com/LCPQ/QUESTDB_website.git
synced 2024-08-24 21:21:52 +02:00
Accelerated load time
This commit is contained in:
parent
b16f494beb
commit
8961e3e06a
7
Makefile
7
Makefile
@ -1,8 +1,11 @@
|
|||||||
default:
|
default: data
|
||||||
hugo
|
hugo
|
||||||
|
|
||||||
serve:
|
serve: data
|
||||||
hugo -D server
|
hugo -D server
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf public
|
rm -rf public
|
||||||
|
|
||||||
|
data:
|
||||||
|
python3 tools/generate_data.py
|
||||||
|
@ -232,7 +232,8 @@ class dataFileBase {
|
|||||||
return /^#\s*([A-Za-z_]+)\s*:\s*(.*)$/;
|
return /^#\s*([A-Za-z_]+)\s*:\s*(.*)$/;
|
||||||
}
|
}
|
||||||
async getGeometryAsync(state = null) {
|
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 lines = text.split("\n")
|
||||||
var indexes = lines.findAllIndexes((line) => {
|
var indexes = lines.findAllIndexes((line) => {
|
||||||
return line.match(/^\d+$/)
|
return line.match(/^\d+$/)
|
||||||
@ -279,7 +280,8 @@ class dataFileBase {
|
|||||||
case String.name:
|
case String.name:
|
||||||
file = getFullDataPath(file)
|
file = getFullDataPath(file)
|
||||||
const maxAge= (DebugMode.Enabled,0,600)
|
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;
|
break;
|
||||||
case File.name:
|
case File.name:
|
||||||
var str = await getTextFromUploadedFileAsync(file)
|
var str = await getTextFromUploadedFileAsync(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={}) {
|
async function getTextFromFileUrlAsync(url,header={}) {
|
||||||
return new Promise(function (resolve, reject) {
|
return new Promise(function (resolve, reject) {
|
||||||
var req = new XMLHttpRequest();
|
var req = new XMLHttpRequest();
|
||||||
@ -21,7 +51,6 @@ async function getTextFromFileUrlAsync(url,header={}) {
|
|||||||
req.send();
|
req.send();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getTextFromUploadedFileAsync(inputFile){
|
async function getTextFromUploadedFileAsync(inputFile){
|
||||||
const temporaryFileReader = new FileReader();
|
const temporaryFileReader = new FileReader();
|
||||||
|
|
||||||
|
30
tools/generate_data.py
Executable file
30
tools/generate_data.py
Executable 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()
|
Loading…
Reference in New Issue
Block a user