Skip to content

Commit

Permalink
Prevent unnecesary re-renders during sync
Browse files Browse the repository at this point in the history
  • Loading branch information
Rik Smith-Unna committed Jul 3, 2017
1 parent 3c83cc0 commit 815134d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
13 changes: 10 additions & 3 deletions app/client/lib/datasource.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const yuno = require('yunodb')
const sum = require('lodash/sum')
const remove = require('lodash/remove')
const assign = require('lodash/assign')
const equals = require('lodash/isEqual')
const speed = require('speedometer')
const discover = require('hyperdiscovery')
const defaults = require('lodash/defaults')
Expand Down Expand Up @@ -74,6 +75,9 @@ function Datasource (key, opts) {
const dbopts = {
location: path.join(self.datadir, 'yuno.db'),
keyField: '$.id',
appendOnly: true,
compositeField: false,
wildcard: false,
indexMap: {
title: true,
authorstr: true,
Expand Down Expand Up @@ -226,16 +230,19 @@ function Datasource (key, opts) {

const getentry = require('./hyperdrive-sync-entry')(self.metadata)

n = 0
let n = 0
let lastprogress = null
const getprogress = through.ctor({ objectMode: true }, (data, _, next) => {
n++
if (n % 150 === 0) {
const progress = {
done: n,
total: self.articleCount
}
self.stats.get('metadataSync').assign(progress).write()
self.emit('progress', progress)
if (!equals(lastprogress, progress)) {
self.stats.get('metadataSync').assign(progress).write()
self.emit('progress', progress)
}
}
next(null, data)
})
Expand Down
1 change: 1 addition & 0 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"pumpify": "^1.3.5",
"raven": "^2.1.0",
"raven-js": "^3.16.0",
"search-index-adder": "blahah/search-index-adder#patch-2",
"sodium-native": "^1.10.1",
"speedometer": "^1.0.0",
"stream-from-array": "^1.0.0",
Expand Down

0 comments on commit 815134d

Please sign in to comment.