Merge branch 'staging' of https://github.com/FreeCodeCamp/freecodecamp into greasan-translateDE
This commit is contained in:
@ -1758,8 +1758,8 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "bad87fee1348bd9aedc08830",
|
"id": "bad87fee1348bd9aedc08830",
|
||||||
"name": "waypoint-use-html5-to-require-a-field",
|
"name": "Waypoint: Use HTML5 to Require a Field",
|
||||||
"dashedName": "Waypoint: Use HTML5 to Require a Field",
|
"dashedName": "waypoint-use-html5-to-require-a-field",
|
||||||
"difficulty": 0.042,
|
"difficulty": 0.042,
|
||||||
"description": [
|
"description": [
|
||||||
"Make your text <code>input</code> a \"required\" field, so that your user can't submit the form without completing this field.",
|
"Make your text <code>input</code> a \"required\" field, so that your user can't submit the form without completing this field.",
|
||||||
|
@ -173,8 +173,8 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "bd7158d8c442eddfaeb5bd19",
|
"id": "bd7158d8c442eddfaeb5bd19",
|
||||||
"name": "zipline-wikipedia-viewer",
|
"name": "Zipline: Wikipedia Viewer",
|
||||||
"dashedName": "Zipline: Wikipedia Viewer",
|
"dashedName": "zipline-wikipedia-viewer",
|
||||||
"difficulty": 1.05,
|
"difficulty": 1.05,
|
||||||
"challengeSeed": ["126415131"],
|
"challengeSeed": ["126415131"],
|
||||||
"description": [
|
"description": [
|
||||||
|
2
index.js
2
index.js
@ -28,7 +28,7 @@ var CompletionMonitor = function() {
|
|||||||
|
|
||||||
Challenge.destroyAll(function(err, info) {
|
Challenge.destroyAll(function(err, info) {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.err(err);
|
console.error(err);
|
||||||
} else {
|
} else {
|
||||||
console.log('Deleted ', info);
|
console.log('Deleted ', info);
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,14 @@ var providers = [
|
|||||||
'linkedin'
|
'linkedin'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// create async console.logs
|
||||||
|
function debug() {
|
||||||
|
var args = [].slice.call(arguments);
|
||||||
|
process.nextTick(function() {
|
||||||
|
console.log.apply(console, args);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function createConnection(URI) {
|
function createConnection(URI) {
|
||||||
return Rx.Observable.create(function(observer) {
|
return Rx.Observable.create(function(observer) {
|
||||||
MongoClient.connect(URI, function(err, database) {
|
MongoClient.connect(URI, function(err, database) {
|
||||||
@ -23,32 +31,31 @@ function createConnection(URI) {
|
|||||||
return observer.onError(err);
|
return observer.onError(err);
|
||||||
}
|
}
|
||||||
observer.onNext(database);
|
observer.onNext(database);
|
||||||
|
observer.onCompleted();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function createQuery(db, collection, options, batchSize) {
|
function createQuery(db, collection, options, batchSize) {
|
||||||
return Rx.Observable.create(function (observer) {
|
return Rx.Observable.create(function (observer) {
|
||||||
console.log('Creating cursor...');
|
|
||||||
var cursor = db.collection(collection).find({}, options);
|
var cursor = db.collection(collection).find({}, options);
|
||||||
cursor.batchSize(batchSize || 20);
|
cursor.batchSize(batchSize || 20);
|
||||||
// Cursor.each will yield all doc from a batch in the same tick,
|
// Cursor.each will yield all doc from a batch in the same tick,
|
||||||
// or schedule getting next batch on nextTick
|
// or schedule getting next batch on nextTick
|
||||||
|
debug('opening cursor for %s', collection);
|
||||||
cursor.each(function (err, doc) {
|
cursor.each(function (err, doc) {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log(err);
|
|
||||||
return observer.onError(err);
|
return observer.onError(err);
|
||||||
}
|
}
|
||||||
if (!doc) {
|
if (!doc) {
|
||||||
console.log('hit complete');
|
console.log('onCompleted');
|
||||||
return observer.onCompleted();
|
return observer.onCompleted();
|
||||||
}
|
}
|
||||||
console.log('calling onnext');
|
|
||||||
observer.onNext(doc);
|
observer.onNext(doc);
|
||||||
});
|
});
|
||||||
|
|
||||||
return Rx.Disposable.create(function () {
|
return Rx.Disposable.create(function () {
|
||||||
console.log('Disposing cursor...');
|
debug('closing cursor for %s', collection);
|
||||||
cursor.close();
|
cursor.close();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -101,7 +108,6 @@ var userSavesCount = users
|
|||||||
})
|
})
|
||||||
.flatMap(function(dats) {
|
.flatMap(function(dats) {
|
||||||
// bulk insert into new collection for loopback
|
// bulk insert into new collection for loopback
|
||||||
console.log(dats);
|
|
||||||
return insertMany(dats.db, 'user', dats.users, { w: 1 });
|
return insertMany(dats.db, 'user', dats.users, { w: 1 });
|
||||||
})
|
})
|
||||||
// count how many times insert completes
|
// count how many times insert completes
|
||||||
@ -138,18 +144,44 @@ var userIdentityCount = users
|
|||||||
// count how many times insert completes
|
// count how many times insert completes
|
||||||
.count();
|
.count();
|
||||||
|
|
||||||
Rx.Observable.merge(
|
var storyCount = dbObservable
|
||||||
|
.flatMap(function(db) {
|
||||||
|
return createQuery(db, 'stories', {});
|
||||||
|
})
|
||||||
|
.bufferWithCount(20)
|
||||||
|
.withLatestFrom(dbObservable, function(stories, db) {
|
||||||
|
return {
|
||||||
|
stories: stories,
|
||||||
|
db: db
|
||||||
|
};
|
||||||
|
})
|
||||||
|
.flatMap(function(dats) {
|
||||||
|
return insertMany(dats.db, 'story', dats.stories, { w: 1 });
|
||||||
|
})
|
||||||
|
.count();
|
||||||
|
|
||||||
|
Rx.Observable.combineLatest(
|
||||||
userIdentityCount,
|
userIdentityCount,
|
||||||
userSavesCount
|
userSavesCount,
|
||||||
)
|
storyCount,
|
||||||
|
function(userIdentCount, userCount, storyCount) {
|
||||||
|
return {
|
||||||
|
userIdentCount: userIdentCount * 20,
|
||||||
|
userCount: userCount * 20,
|
||||||
|
storyCount: storyCount * 20
|
||||||
|
};
|
||||||
|
})
|
||||||
.subscribe(
|
.subscribe(
|
||||||
function(_count) {
|
function(countObj) {
|
||||||
count += _count * 20;
|
console.log('next');
|
||||||
|
count = countObj;
|
||||||
},
|
},
|
||||||
function(err) {
|
function(err) {
|
||||||
console.log('an error occured', err, err.stack);
|
console.error('an error occured', err, err.stack);
|
||||||
},
|
},
|
||||||
function() {
|
function() {
|
||||||
console.log('finished with %s documents processed', count);
|
|
||||||
|
console.log('finished with ', count);
|
||||||
|
process.exit(0);
|
||||||
}
|
}
|
||||||
);
|
);
|
Reference in New Issue
Block a user