so much for sessionStorage

This commit is contained in:
ed 2021-03-06 16:34:55 +01:00
parent bd769f5bdb
commit 6ecd745323
4 changed files with 48 additions and 30 deletions

View file

@ -9,7 +9,6 @@ from datetime import datetime, timedelta
import calendar import calendar
from .__init__ import PY2, WINDOWS, MACOS, VT100 from .__init__ import PY2, WINDOWS, MACOS, VT100
from .authsrv import AuthSrv
from .tcpsrv import TcpSrv from .tcpsrv import TcpSrv
from .up2k import Up2k from .up2k import Up2k
from .util import mp from .util import mp

View file

@ -64,7 +64,7 @@ class Up2k(object):
self.flags = {} self.flags = {}
self.cur = {} self.cur = {}
self.mtag = None self.mtag = None
self.n_mtag_tags_added = 0 self.n_mtag_tags_added = -1
self.mem_cur = None self.mem_cur = None
self.sqlite_ver = None self.sqlite_ver = None
@ -461,7 +461,10 @@ class Up2k(object):
# mp.pool.ThreadPool and concurrent.futures.ThreadPoolExecutor # mp.pool.ThreadPool and concurrent.futures.ThreadPoolExecutor
# both do crazy runahead so lets reinvent another wheel # both do crazy runahead so lets reinvent another wheel
nw = os.cpu_count() if hasattr(os, "cpu_count") else 4 nw = os.cpu_count() if hasattr(os, "cpu_count") else 4
if self.n_mtag_tags_added == -1:
self.log("using {}x {}".format(nw, self.mtag.backend)) self.log("using {}x {}".format(nw, self.mtag.backend))
self.n_mtag_tags_added = 0
mpool = Queue(nw) mpool = Queue(nw)
for _ in range(nw): for _ in range(nw):
thr = threading.Thread(target=self._tag_thr, args=(mpool,)) thr = threading.Thread(target=self._tag_thr, args=(mpool,))

View file

@ -467,8 +467,7 @@ function play(tid, call_depth) {
var o = ebi(oid); var o = ebi(oid);
o.setAttribute('id', 'thx_js'); o.setAttribute('id', 'thx_js');
if (window.history && history.replaceState) { if (window.history && history.replaceState) {
var nurl = (document.location + '').split('#')[0] + '#' + oid; hist_replace((document.location + '').split('#')[0] + '#' + oid);
hist_replace(ebi('files').innerHTML, nurl);
} }
else { else {
document.location.hash = oid; document.location.hash = oid;
@ -726,7 +725,6 @@ function autoplay_blocked() {
// tree // tree
(function () { (function () {
var treedata = null;
var dyn = bcfg_get('dyntree', true); var dyn = bcfg_get('dyntree', true);
var treesz = icfg_get('treesz', 16); var treesz = icfg_get('treesz', 16);
treesz = Math.min(Math.max(treesz, 4), 50); treesz = Math.min(Math.max(treesz, 4), 50);
@ -746,13 +744,15 @@ function autoplay_blocked() {
treefiles.appendChild(ebi('epi')); treefiles.appendChild(ebi('epi'));
swrite('entreed', 'tree'); swrite('entreed', 'tree');
get_tree("", get_vpath()); get_tree("", get_vpath(), true);
} }
function get_tree(top, dst) { function get_tree(top, dst, rst) {
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
xhr.top = top; xhr.top = top;
xhr.dst = dst; xhr.dst = dst;
xhr.rst = rst;
xhr.ts = new Date().getTime();
xhr.open('GET', dst + '?tree=' + top, true); xhr.open('GET', dst + '?tree=' + top, true);
xhr.onreadystatechange = recvtree; xhr.onreadystatechange = recvtree;
xhr.send(); xhr.send();
@ -768,6 +768,13 @@ function autoplay_blocked() {
return; return;
} }
var cur = ebi('treeul').getAttribute('ts');
if (cur && parseInt(cur) > this.ts) {
console.log("reject tree");
return;
}
ebi('treeul').setAttribute('ts', this.ts);
var top = this.top == '.' ? this.dst : this.top, var top = this.top == '.' ? this.dst : this.top,
name = top.split('/').slice(-2)[0], name = top.split('/').slice(-2)[0],
rtop = top.replace(/^\/+/, ""); rtop = top.replace(/^\/+/, "");
@ -781,7 +788,7 @@ function autoplay_blocked() {
var html = parsetree(res, rtop); var html = parsetree(res, rtop);
if (!this.top) { if (!this.top) {
html = '<li><a href="#">-</a><a href="/">[root]</a>\n<ul>' + html; html = '<li><a href="#">-</a><a href="/">[root]</a>\n<ul>' + html;
if (!ebi('treeul').getElementsByTagName('li').length) if (this.rst || !ebi('treeul').getElementsByTagName('li').length)
ebi('treeul').innerHTML = html + '</ul></li>'; ebi('treeul').innerHTML = html + '</ul></li>';
} }
else { else {
@ -841,12 +848,20 @@ function autoplay_blocked() {
treegrow.call(this.previousSibling, e); treegrow.call(this.previousSibling, e);
return; return;
} }
reqls(this.getAttribute('href'), true);
}
function reqls(url, hpush) {
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
xhr.top = this.getAttribute('href'); xhr.top = url;
xhr.hpush = hpush;
xhr.ts = new Date().getTime();
xhr.open('GET', xhr.top + '?ls', true); xhr.open('GET', xhr.top + '?ls', true);
xhr.onreadystatechange = recvls; xhr.onreadystatechange = recvls;
xhr.send(); xhr.send();
if (hpush)
get_tree('.', xhr.top); get_tree('.', xhr.top);
enspin('#files'); enspin('#files');
} }
@ -874,6 +889,13 @@ function autoplay_blocked() {
return; return;
} }
var cur = ebi('files').getAttribute('ts');
if (cur && parseInt(cur) > this.ts) {
console.log("reject ls");
return;
}
ebi('files').setAttribute('ts', this.ts);
try { try {
var res = JSON.parse(this.responseText); var res = JSON.parse(this.responseText);
} }
@ -913,7 +935,9 @@ function autoplay_blocked() {
html = html.join('\n'); html = html.join('\n');
ebi('files').innerHTML = html; ebi('files').innerHTML = html;
hist_push(html, this.top); if (this.hpush)
hist_push(this.top);
apply_perms(res.perms); apply_perms(res.perms);
despin('#files'); despin('#files');
@ -994,19 +1018,13 @@ function autoplay_blocked() {
entree(); entree();
window.onpopstate = function (e) { window.onpopstate = function (e) {
console.log(e.url + ' ,, ' + ((e.state + '').slice(0, 64))); console.log("h-pop " + e.state);
var html = sessionStorage.getItem(e.state || 1); get_tree("", e.state, true);
if (!html) reqls(e.state);
return;
ebi('files').innerHTML = html;
reload_tree();
reload_browser();
}; };
if (window.history && history.pushState) { if (window.history && history.pushState) {
var u = get_vpath() + window.location.hash; hist_replace(get_vpath() + window.location.hash);
hist_replace(ebi('files').innerHTML, u);
} }
})(); })();

View file

@ -335,14 +335,12 @@ function bcfg_upd_ui(name, val) {
} }
function hist_push(html, url) { function hist_push(url) {
var key = new Date().getTime(); console.log("h-push " + url);
sessionStorage.setItem(key, html); history.pushState(url, url, url);
history.pushState(key, url, url);
} }
function hist_replace(html, url) { function hist_replace(url) {
var key = new Date().getTime(); console.log("h-repl " + url);
sessionStorage.setItem(key, html); history.replaceState(url, url, url);
history.replaceState(key, url, url);
} }