this seems to improve sync speed

master
Ev Bogue 4 years ago
parent dccfda7a22
commit bca1b99d3a

@ -105,8 +105,10 @@ bog.keys().then(key => {
wserve.on('connection', function (ws) {
ws.on('message', function (message) {
var req = JSON.parse(message)
console.log(req)
if (req.sendpub) {
ws.send(key.publicKey)
ws.close()
} else {
bog.unbox(req.box, req.requester, key).then(unboxed => {
var unboxedreq = JSON.parse(unboxed)
@ -119,7 +121,8 @@ bog.keys().then(key => {
bog.open(feed[0]).then(msg => {
if (unboxedreq.seq === msg.seq) {
printFeedIdentical(msg, req)
}
ws.close()
}
if (unboxedreq.seq > msg.seq) {
printClientLonger(msg, req)
var reqdiff = JSON.stringify({author: unboxedreq.author, seq: msg.seq})
@ -129,6 +132,7 @@ bog.keys().then(key => {
box: boxed
}
ws.send(JSON.stringify(obj))
ws.close()
})
}
if (unboxedreq.seq < msg.seq) {
@ -163,6 +167,7 @@ bog.keys().then(key => {
box: boxed
}
ws.send(JSON.stringify(obj))
ws.close()
})
}
})
@ -182,6 +187,7 @@ bog.keys().then(key => {
printUpdateFeed(msg, req)
})
}
ws.close()
})
})
}

@ -63,7 +63,7 @@ function settingsPage (keys) {
onclick: function () {
if (add.value) {
servers.push(add.value)
localforage.setItem('pubs', servers).then(function () { location.reload() })
localforage.setItem('pubs', servers).then(function () { location.hash = '' })
}
}
}, ['Add a pub'])
@ -75,7 +75,7 @@ function settingsPage (keys) {
h('button', {
onclick: function () {
var newServers = servers.filter(item => item !== pub)
localforage.setItem('pubs', newServers).then(function () { location.reload() })
localforage.setItem('pubs', newServers).then(function () { location.hash = '' })
}
}, ['Remove'])
]))

@ -19,20 +19,26 @@ function getLoc (src) {
return loc
}
function profilePage (src, keys) {
var interval = 500
var timer = setInterval(function () {
if (window.location.hash.substring(1) != src) {
clearInterval(timer)
console.log('stop syncing')
}
sync([src], keys)
console.log('syncing ' + src)
}, 2500)
timer = function() {
/*timer = function() {
if (src === window.location.hash.substring(1)) {
if (interval < 10000) { interval = interval + 50 }
//if (interval < 10000) { interval = interval + 50 }
sync([src], keys)
setTimeout(timer, interval)
}
}
timer()
timer()*/
var msg = {}
msg.author = src
@ -70,7 +76,6 @@ function profilePage (src, keys) {
})
}
getBg(src, profile)
profileDiv.appendChild(banner)
@ -115,14 +120,14 @@ function profilePage (src, keys) {
profile.appendChild(h('button', {
onclick: function () {
subs = subs.filter(a => a !== src)
localforage.setItem('subscriptions', subs).then(function () { location.reload() })
localforage.setItem('subscriptions', subs).then(function () { location.hash = '' })
}
}, ['Unsubscribe from ' + name]))
} else {
profile.appendChild(h('button', {
onclick: function () {
subs.push(src)
localforage.setItem('subscriptions', subs).then(function () { location.reload() })
localforage.setItem('subscriptions', subs).then(function () { location.hash = '' })
}
}, ['Subscribe to ' + name]))
}
@ -164,7 +169,6 @@ function profilePage (src, keys) {
function searchPage (src, keys) {
var search = src.substring(1).replace("%20"," ").toUpperCase()
async function addPosts (posts, keys) {
posts.forEach(function (msg) {
if (msg.text) {
@ -202,28 +206,30 @@ function publicPage (keys) {
})
localforage.getItem('subscriptions').then(subs => {
var interval = 1000
timer = function() {
if ('' === window.location.hash.substring(1)) {
if (interval < 10000) { interval = interval + 1000 }
sync(subs, keys)
setTimeout(timer, interval)
}
}
if (subs) {
// the next two lines just fix a bug where the first sub was being set to null. Delete this code after March 2020.
subs.forEach(sub => {
subs.forEach(function (sub, index) {
var timer = setInterval(function () {
setTimeout(function () {
if (window.location.hash.substring(1) != '') {
clearInterval(timer)
console.log('stop syncing')
}
sync([sub], keys)
console.log('syncing ' + sub)
}, 1000 * index)
}, 2500)
if (sub == null) {
var subs = [keys.publicKey]
localforage.setItem('subscriptions', subs)
}
})
timer()
} else {
var subs = [keys.publicKey]
console.log(subs)
localforage.setItem('subscriptions', subs)
timer()
}
})
@ -253,5 +259,3 @@ function publicPage (keys) {
}
})
}

Loading…
Cancel
Save