Better sync

This commit is contained in:
Magnus Åhall 2026-06-09 10:27:16 +02:00
parent 227fa2208b
commit 744984fc46
2 changed files with 30 additions and 10 deletions

View file

@ -308,8 +308,8 @@ button {
n2-syncprogress {
position: absolute;
top: 16px;
right: 16px;
top: 8px;
right: 8px;
padding: 8px 16px;
z-index: 16384;
border-radius: 6px;

View file

@ -17,10 +17,12 @@ export class Sync {
const state = await nodeStore.getAppState('latest_sync_node')
const oldMax = (state?.value ? state.value : 0)
let nodeCount = await this.getNodeCount(oldMax)
nodeCount += await nodeStore.sendQueue.count()
let nodeCountDownload = await this.getNodeCount(oldMax)
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)
.then(durationNodes => {
@ -28,6 +30,7 @@ export class Sync {
console.log(`Total time: ${Math.round(1000 * durationNodes) / 1000}s`)
})
// Uploads of modified nodes to server.
await this.nodesToServer()
} finally {
_mbus.dispatch('SYNC_DONE')
@ -175,25 +178,35 @@ export class N2SyncProgress extends CustomHTMLElement {
super()
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_DONE', event => this.progressHandler(event))
_mbus.subscribe('SYNC_UPLOADED', event => this.progressHandler(event))
}//}}}
reset() {//{{{
this.state = {
nodesToSync: 0,
nodesToDownload: 0,
nodesToUpload: 0,
nodesSynced: 0,
nodesUploaded: 0,
}
}//}}}
progressHandler(event) {//{{{
const eventData = event.detail.data
switch (event.type) {
case 'SYNC_COUNT':
this.state.nodesToSync = eventData.count
case 'SYNC_DOWNLOAD_COUNT':
this.state.nodesToDownload = eventData.count
this.setSyncState(true)
break
case 'SYNC_UPLOAD_COUNT':
this.state.nodesToUpload = eventData.count
this.setSyncState(true)
break
case 'SYNC_HANDLED':
console.log('SYNC_HANDLED', eventData.handled)
this.state.nodesSynced = eventData.handled
break
@ -208,12 +221,19 @@ export class N2SyncProgress extends CustomHTMLElement {
// Reload the tree nodes to reflect the new/updated nodes.
window._app.tree.reset()
break
case 'SYNC_UPLOADED':
this.state.nodesUploaded += eventData.count
break
}
this.render()
}//}}}
render() {//{{{
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) {// {{{
if (state)