Skip to content

Commit

Permalink
Merge pull request #46 from algolia/fix/mem-leak-second-pass
Browse files Browse the repository at this point in the history
fix(memleak): in watch mode, do not use promise chain
  • Loading branch information
vvo authored May 14, 2017
2 parents 4484836 + 3f2e860 commit 4460c2b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
13 changes: 9 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import PouchDB from 'pouchdb-http';
import * as npm from './npm.js';
import log from './log.js';
import ms from 'ms';
import queue from 'async/queue';

log.info('🗿 npm ↔️ Algolia replication starts ⛷ 🐌 🛰');

Expand Down Expand Up @@ -168,9 +169,8 @@ function watch({ seq }) {
limit: undefined,
});

changes.on('change', change => {
Promise.resolve()
.then(() => saveDocs([change]), reject)
const q = queue((change, done) => {
saveDocs([change])
.then(() => infoChange(change.seq, 1, '🛰'))
.then(() =>
stateManager.save({
Expand All @@ -195,7 +195,12 @@ function watch({ seq }) {
});
}
})
.catch(reject);
.then(() => done(null))
.catch(done);
}, 1);

changes.on('change', change => {
q.push(change);
});
changes.on('error', reject);
});
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"license": "MIT",
"dependencies": {
"algoliasearch": "^3.22.1",
"async": "^2.4.0",
"babel-cli": "^6.24.1",
"babel-preset-env": "^1.4.0",
"babel-preset-stage-2": "^6.24.1",
Expand Down
8 changes: 7 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,12 @@ async-each@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/async-each/-/async-each-1.0.1.tgz#19d386a1d9edc6e7c1c85d388aedbcc56d33602d"

async@^2.4.0:
version "2.4.0"
resolved "https://registry.yarnpkg.com/async/-/async-2.4.0.tgz#4990200f18ea5b837c2cc4f8c031a6985c385611"
dependencies:
lodash "^4.14.0"

asynckit@^0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79"
Expand Down Expand Up @@ -2581,7 +2587,7 @@ lodash.isnull@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/lodash.isnull/-/lodash.isnull-3.0.0.tgz#fafbe59ea1dca27eed786534039dd84c2e07c56e"

lodash@^4.0.0, lodash@^4.17.2, lodash@^4.17.4, lodash@^4.2.0, lodash@^4.3.0:
lodash@^4.0.0, lodash@^4.14.0, lodash@^4.17.2, lodash@^4.17.4, lodash@^4.2.0, lodash@^4.3.0:
version "4.17.4"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae"

Expand Down

0 comments on commit 4460c2b

Please sign in to comment.