Skip to content

Instantly share code, notes, and snippets.

@thomsbg
Created January 9, 2017 20:50
Show Gist options
  • Save thomsbg/3044cf8be57ad21cbf3b998a3c2335e2 to your computer and use it in GitHub Desktop.
Save thomsbg/3044cf8be57ad21cbf3b998a3c2335e2 to your computer and use it in GitHub Desktop.
diff --git a/shared/find_each_model.js b/shared/find_each_model.js
index fb575db..bb671c8 100644
--- a/shared/find_each_model.js
+++ b/shared/find_each_model.js
@@ -1,10 +1,12 @@
var Bluebird = require('bluebird');
-module.exports = function findEach(Model, fn, since, success) {
- since = (since == null) ? 0 : since;
+module.exports = function findEach(Model, fn, lastId, success) {
success = (success == null) ? true : success;
return Model.query(function(q) {
- return q.where('id', '>', since).orderBy('id', 'asc').limit(100);
+ if (lastId) {
+ q.where('id', '<', lastId);
+ }
+ q.orderBy('id', 'asc').limit(100);
}).fetchAll().then(function(models) {
if (models.length > 0) {
return models.reduce(function(p, m) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment