diff options
author | Ev Bogue <ev@evbogue.com> | 2020-01-11 11:10:20 -0600 |
---|---|---|
committer | Ev Bogue <ev@evbogue.com> | 2020-01-11 11:10:20 -0600 |
commit | bca1b99d3a844c7ed6b956be20b026dd3666b188 (patch) | |
tree | 8f07c775f466f0070bb0a4737afda28b5be50b80 | |
parent | dccfda7a227fdcf834a3b5e167f30af53e6c6507 (diff) |
this seems to improve sync speed
-rw-r--r-- | server.js | 8 | ||||
-rw-r--r-- | settings.js | 4 | ||||
-rw-r--r-- | views.js | 48 |
3 files changed, 35 insertions, 25 deletions
@@ -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() }) }) } diff --git a/settings.js b/settings.js index b0cb561..9a20dc3 100644 --- a/settings.js +++ b/settings.js @@ -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) { } }) } - - |