Skip to content

Commit 194bbfc

Browse files
authored
Merge pull request #412 from nono/start-sync
Improve the start synchronisation sequence
2 parents a989af6 + 73c2a45 commit 194bbfc

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

gui/app/main.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,15 @@ const startSync = (force) => {
370370
})
371371
}
372372

373+
const appLoaded = () => {
374+
if (desktop.config.hasDevice()) {
375+
device = desktop.config.getDevice()
376+
if (device.deviceName && device.url && device.path) {
377+
setTimeout(startSync, 20)
378+
}
379+
}
380+
}
381+
373382
const createWindow = () => {
374383
runAsService = new BrowserWindow({ show: false })
375384
mainWindow = new BrowserWindow(windowOptions)
@@ -381,21 +390,16 @@ const createWindow = () => {
381390
mainWindow.setMenu(null)
382391
}
383392
mainWindow.on('closed', () => { mainWindow = null })
384-
mainWindow.webContents.on('dom-ready', () => {
385-
if (desktop.config.hasDevice()) {
386-
device = desktop.config.getDevice()
387-
if (device.deviceName && device.url && device.path) {
388-
setTimeout(startSync, 20)
389-
}
390-
}
391-
})
393+
mainWindow.webContents.on('dom-ready', appLoaded)
392394
}
393395

394396
loadLastFiles()
395397

396398
app.on('ready', () => {
397399
if (process.argv.indexOf('--hidden') === -1) {
398400
createWindow()
401+
} else {
402+
appLoaded()
399403
}
400404
tray = new electron.Tray(`${__dirname}/images/tray-icon-linux/idle.png`)
401405
setTrayIcon('idle')

src/local/watcher.coffee

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ class LocalWatcher
2020
constructor: (@syncPath, @prep, @pouch) ->
2121
@side = 'local'
2222

23+
# Use a queue for checksums to avoid computing many checksums at the
24+
# same time. It's better for performance (hard disk are faster with
25+
# linear readings).
26+
@checksumer = async.queue @computeChecksum
27+
28+
2329
# Start chokidar, the filesystem watcher
2430
# https://github.com/paulmillr/chokidar
2531
#
@@ -140,9 +146,13 @@ class LocalWatcher
140146
else "file"
141147
return [mimeType, fileClass]
142148

143-
# Get checksum for given file
149+
# Put a checksum computation in the queue
144150
checksum: (filePath, callback) ->
145-
stream = fs.createReadStream filePath
151+
@checksumer.push filePath: filePath, callback
152+
153+
# Get checksum for given file
154+
computeChecksum: (task, callback) ->
155+
stream = fs.createReadStream task.filePath
146156
checksum = crypto.createHash 'sha1'
147157
checksum.setEncoding 'hex'
148158
stream.on 'end', ->

0 commit comments

Comments
 (0)