Implement CSV download
This commit is contained in:
1 parent
24b047bd5e
commit
a49cbc5e40
20 files changed
+391
-215
No files matched your search
@@ -10,7 +10,7 @@ const validators = {
|
||||
class Authorizer {
|
||||
constructor(permissionSets) {
|
||||
this.permissionSets = permissionSets;
|
||||
this.validtorCache = new WeakMap();
|
||||
this.validatorCache = new WeakMap();
|
||||
this.hasAccessCache = {};
|
||||
}
|
||||
|
||||
@@ -34,8 +34,8 @@ class Authorizer {
|
||||
}
|
||||
|
||||
getValidator(resourceType, resource) {
|
||||
if (this.validtorCache.has(resource))
|
||||
return this.validtorCache.get(resource);
|
||||
if (this.validatorCache.has(resource))
|
||||
return this.validatorCache.get(resource);
|
||||
|
||||
let funcs = {};
|
||||
|
||||
@@ -70,7 +70,7 @@ class Authorizer {
|
||||
return valid;
|
||||
};
|
||||
|
||||
this.validtorCache.set(resource, validator);
|
||||
this.validatorCache.set(resource, validator);
|
||||
return validator;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ function reduce(exp, callback) {
|
||||
return exp;
|
||||
}
|
||||
|
||||
function evaluate(exp, obj, now) {
|
||||
function evaluate(exp, obj, now, cb) {
|
||||
function getRegExp(pat, esc) {
|
||||
const k = `${esc || ""}:${pat}`;
|
||||
let c = regExpCache.get(exp);
|
||||
@@ -46,6 +46,7 @@ function evaluate(exp, obj, now) {
|
||||
}
|
||||
|
||||
return expressionParser.map(exp, e => {
|
||||
if (cb) e = cb(e);
|
||||
if (!isArray(e)) return e;
|
||||
|
||||
if (e[0] === "FUNC") {
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
let cache1 = new WeakMap();
|
||||
let cache2 = new WeakMap();
|
||||
|
||||
function get(func, k) {
|
||||
let c1 = cache1.get(func);
|
||||
if (!c1) cache1.set(func, (c1 = new Map()));
|
||||
if (c1.has(k)) return c1.get(k);
|
||||
const c2 = cache2.get(func);
|
||||
const v = c2 && c2.has(k) ? c2.get(k) : func(k);
|
||||
c1.set(k, v);
|
||||
return v;
|
||||
}
|
||||
|
||||
function getter(func) {
|
||||
return k => get(func, k);
|
||||
}
|
||||
|
||||
function purge() {
|
||||
cache2 = cache1;
|
||||
cache1 = new WeakMap();
|
||||
}
|
||||
|
||||
setInterval(purge, 120000);
|
||||
|
||||
exports.get = get;
|
||||
exports.getter = getter;
|
||||
exports.purge = purge;
|
||||
@@ -0,0 +1,47 @@
|
||||
"use strict";
|
||||
|
||||
let cache1 = new Map();
|
||||
let cache2 = new Map();
|
||||
const keys = new WeakMap();
|
||||
|
||||
function getKey(obj) {
|
||||
if (obj === null) return "null";
|
||||
else if (obj === undefined) return "undefined";
|
||||
|
||||
const t = typeof obj;
|
||||
if (t === "number" || t === "boolean" || t === "string") return `${t}:${obj}`;
|
||||
if (t !== "function" && t !== "object")
|
||||
throw new Error(`Cannot memoize ${t} arguments`);
|
||||
|
||||
let k = keys.get(obj);
|
||||
if (!k) {
|
||||
const rnd = Math.trunc(Math.random() * Number.MAX_SAFE_INTEGER);
|
||||
k = `${t}:${rnd.toString(36)}`;
|
||||
keys.set(obj, k);
|
||||
}
|
||||
return k;
|
||||
}
|
||||
|
||||
function memoize(func) {
|
||||
return (...args) => {
|
||||
const key = JSON.stringify(args.map(getKey)) + getKey(func);
|
||||
|
||||
if (cache1.has(key)) return cache1.get(key);
|
||||
|
||||
let r;
|
||||
if (cache2.has(key)) r = cache2.get(key);
|
||||
else r = func(...args);
|
||||
cache1.set(key, r);
|
||||
return r;
|
||||
};
|
||||
}
|
||||
|
||||
const interval = setInterval(() => {
|
||||
cache2 = cache1;
|
||||
cache1 = new Map();
|
||||
}, 120000);
|
||||
|
||||
// Don't hold Node.js process
|
||||
if (interval.unref) interval.unref();
|
||||
|
||||
module.exports = memoize;
|
||||
Reference in new issue
Block a user