Better sync
This commit is contained in:
parent
227fa2208b
commit
744984fc46
2 changed files with 30 additions and 10 deletions
|
|
@ -308,8 +308,8 @@ button {
|
||||||
|
|
||||||
n2-syncprogress {
|
n2-syncprogress {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 16px;
|
top: 8px;
|
||||||
right: 16px;
|
right: 8px;
|
||||||
padding: 8px 16px;
|
padding: 8px 16px;
|
||||||
z-index: 16384;
|
z-index: 16384;
|
||||||
border-radius: 6px;
|
border-radius: 6px;
|
||||||
|
|
|
||||||
|
|
@ -17,10 +17,12 @@ export class Sync {
|
||||||
const state = await nodeStore.getAppState('latest_sync_node')
|
const state = await nodeStore.getAppState('latest_sync_node')
|
||||||
const oldMax = (state?.value ? state.value : 0)
|
const oldMax = (state?.value ? state.value : 0)
|
||||||
|
|
||||||
let nodeCount = await this.getNodeCount(oldMax)
|
let nodeCountDownload = await this.getNodeCount(oldMax)
|
||||||
nodeCount += await nodeStore.sendQueue.count()
|
let nodeCountUpload = await nodeStore.sendQueue.count()
|
||||||
|
console.log(nodeCountUpload)
|
||||||
|
|
||||||
_mbus.dispatch('SYNC_COUNT', { count: nodeCount })
|
_mbus.dispatch('SYNC_DOWNLOAD_COUNT', { count: nodeCountDownload })
|
||||||
|
_mbus.dispatch('SYNC_UPLOAD_COUNT', { count: nodeCountUpload })
|
||||||
|
|
||||||
await this.nodesFromServer(oldMax)
|
await this.nodesFromServer(oldMax)
|
||||||
.then(durationNodes => {
|
.then(durationNodes => {
|
||||||
|
|
@ -28,6 +30,7 @@ export class Sync {
|
||||||
console.log(`Total time: ${Math.round(1000 * durationNodes) / 1000}s`)
|
console.log(`Total time: ${Math.round(1000 * durationNodes) / 1000}s`)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Uploads of modified nodes to server.
|
||||||
await this.nodesToServer()
|
await this.nodesToServer()
|
||||||
} finally {
|
} finally {
|
||||||
_mbus.dispatch('SYNC_DONE')
|
_mbus.dispatch('SYNC_DONE')
|
||||||
|
|
@ -175,25 +178,35 @@ export class N2SyncProgress extends CustomHTMLElement {
|
||||||
super()
|
super()
|
||||||
|
|
||||||
this.reset()
|
this.reset()
|
||||||
_mbus.subscribe('SYNC_COUNT', event => this.progressHandler(event))
|
_mbus.subscribe('SYNC_DOWNLOAD_COUNT', event => this.progressHandler(event))
|
||||||
|
_mbus.subscribe('SYNC_UPLOAD_COUNT', event => this.progressHandler(event))
|
||||||
_mbus.subscribe('SYNC_HANDLED', event => this.progressHandler(event))
|
_mbus.subscribe('SYNC_HANDLED', event => this.progressHandler(event))
|
||||||
_mbus.subscribe('SYNC_DONE', event => this.progressHandler(event))
|
_mbus.subscribe('SYNC_DONE', event => this.progressHandler(event))
|
||||||
|
_mbus.subscribe('SYNC_UPLOADED', event => this.progressHandler(event))
|
||||||
}//}}}
|
}//}}}
|
||||||
reset() {//{{{
|
reset() {//{{{
|
||||||
this.state = {
|
this.state = {
|
||||||
nodesToSync: 0,
|
nodesToDownload: 0,
|
||||||
|
nodesToUpload: 0,
|
||||||
nodesSynced: 0,
|
nodesSynced: 0,
|
||||||
|
nodesUploaded: 0,
|
||||||
}
|
}
|
||||||
}//}}}
|
}//}}}
|
||||||
progressHandler(event) {//{{{
|
progressHandler(event) {//{{{
|
||||||
const eventData = event.detail.data
|
const eventData = event.detail.data
|
||||||
switch (event.type) {
|
switch (event.type) {
|
||||||
case 'SYNC_COUNT':
|
case 'SYNC_DOWNLOAD_COUNT':
|
||||||
this.state.nodesToSync = eventData.count
|
this.state.nodesToDownload = eventData.count
|
||||||
|
this.setSyncState(true)
|
||||||
|
break
|
||||||
|
|
||||||
|
case 'SYNC_UPLOAD_COUNT':
|
||||||
|
this.state.nodesToUpload = eventData.count
|
||||||
this.setSyncState(true)
|
this.setSyncState(true)
|
||||||
break
|
break
|
||||||
|
|
||||||
case 'SYNC_HANDLED':
|
case 'SYNC_HANDLED':
|
||||||
|
console.log('SYNC_HANDLED', eventData.handled)
|
||||||
this.state.nodesSynced = eventData.handled
|
this.state.nodesSynced = eventData.handled
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
@ -208,12 +221,19 @@ export class N2SyncProgress extends CustomHTMLElement {
|
||||||
// Reload the tree nodes to reflect the new/updated nodes.
|
// Reload the tree nodes to reflect the new/updated nodes.
|
||||||
window._app.tree.reset()
|
window._app.tree.reset()
|
||||||
break
|
break
|
||||||
|
|
||||||
|
case 'SYNC_UPLOADED':
|
||||||
|
this.state.nodesUploaded += eventData.count
|
||||||
|
break
|
||||||
}
|
}
|
||||||
this.render()
|
this.render()
|
||||||
}//}}}
|
}//}}}
|
||||||
render() {//{{{
|
render() {//{{{
|
||||||
this.elDownloadTransferred.innerText = this.state.nodesSynced
|
this.elDownloadTransferred.innerText = this.state.nodesSynced
|
||||||
this.elDownloadTotal.innerText = this.state.nodesToSync
|
this.elDownloadTotal.innerText = this.state.nodesToDownload
|
||||||
|
|
||||||
|
this.elUploadTransferred.innerText = this.state.nodesUploaded
|
||||||
|
this.elUploadTotal.innerText = this.state.nodesToUpload
|
||||||
}//}}}
|
}//}}}
|
||||||
setSyncState(state) {// {{{
|
setSyncState(state) {// {{{
|
||||||
if (state)
|
if (state)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue