penna.school/index_files/parse-cache-session.js

21 lines
691 B
JavaScript
Raw Normal View History

2025-07-09 10:36:49 +02:00
// monkeypath Session.current to memoize
var original = Parse.Session.current
Parse.Session.current = async (original) => {
let delay = 400
if( Parse.Session.group != undefined ){
//console.log("caching request for "+delay+" ms")
return new Promise( (resolve,reject) => Parse.Session.group.push(resolve) )
}
Parse.Session.group = []
return new Promise( async (resolve,reject) => {
Parse.Session.group.push(resolve)
var res = await original()
setTimeout( () => {
Parse.Session.group.map( (r) => r(res) )
delete Parse.Session.group
},delay)
})
}
Parse.Session.current = Parse.Session.current.bind(Parse.Session,original)