1
0
mirror of https://github.com/mgerb/mywebsite synced 2026-01-12 10:52:47 +00:00

updated bunch of file paths and changed the way posts are loaded

This commit is contained in:
2016-01-05 12:28:04 -06:00
parent 4bb8cae81e
commit 6ab45fe935
13249 changed files with 317868 additions and 2101398 deletions

View File

@@ -1,12 +1,13 @@
/* eslint no-empty: 1 */
/*!
* Module dependencies.
*/
var Stream = require('stream').Stream
var utils = require('./utils')
var helpers = require('./queryhelpers')
var K = function(k){ return k }
var Stream = require('stream').Stream;
var utils = require('./utils');
var helpers = require('./queryhelpers');
var K = function(k) { return k; };
/**
* Provides a Node.js 0.8 style [ReadStream](http://nodejs.org/docs/v0.8.21/api/stream.html#stream_readable_stream) interface for Queries.
@@ -49,7 +50,7 @@ var K = function(k){ return k }
* @api public
*/
function QueryStream (query, options) {
function QueryStream(query, options) {
Stream.call(this);
this.query = query;
@@ -67,7 +68,7 @@ function QueryStream (query, options) {
// give time to hook up events
var self = this;
process.nextTick(function () {
process.nextTick(function() {
self._init();
});
}
@@ -107,13 +108,13 @@ var T_CONT = 2;
* @api private
*/
QueryStream.prototype._init = function () {
QueryStream.prototype._init = function() {
if (this._destroyed) return;
var query = this.query
, model = query.model
, options = query._optionsForExec(model)
, self = this
var query = this.query,
model = query.model,
options = query._optionsForExec(model),
self = this;
try {
query.cast(model);
@@ -124,12 +125,12 @@ QueryStream.prototype._init = function () {
self._fields = utils.clone(query._fields);
options.fields = query._castFields(self._fields);
model.collection.find(query._conditions, options, function (err, cursor) {
model.collection.find(query._conditions, options, function(err, cursor) {
if (err) return self.destroy(err);
self._cursor = cursor;
self._next();
});
}
};
/**
* Trampoline for pulling the next doc from cursor.
@@ -138,7 +139,7 @@ QueryStream.prototype._init = function () {
* @api private
*/
QueryStream.prototype._next = function _next () {
QueryStream.prototype._next = function _next() {
if (this.paused || this._destroyed) {
return this._running = false;
}
@@ -155,7 +156,7 @@ QueryStream.prototype._next = function _next () {
// avoid stack overflows with large result sets.
// trampoline instead of recursion.
while (this.__next()) {}
}
};
/**
* Pulls the next doc from the cursor.
@@ -164,14 +165,14 @@ QueryStream.prototype._next = function _next () {
* @api private
*/
QueryStream.prototype.__next = function () {
QueryStream.prototype.__next = function() {
if (this.paused || this._destroyed)
return this._running = false;
var self = this;
self._inline = T_INIT;
self._cursor.nextObject(function cursorcb (err, doc) {
self._cursor.nextObject(function cursorcb(err, doc) {
self._onNextObject(err, doc);
});
@@ -185,7 +186,7 @@ QueryStream.prototype.__next = function () {
// the trampoline anymore.
this._inline = T_IDLE;
}
}
};
/**
* Transforms raw `doc`s returned from the cursor into a model instance.
@@ -195,7 +196,7 @@ QueryStream.prototype.__next = function () {
* @api private
*/
QueryStream.prototype._onNextObject = function _onNextObject (err, doc) {
QueryStream.prototype._onNextObject = function _onNextObject(err, doc) {
if (this._destroyed) return;
if (this.paused) {
@@ -223,21 +224,26 @@ QueryStream.prototype._onNextObject = function _onNextObject (err, doc) {
var self = this;
var pop = helpers.preparePopulationOptionsMQ(self.query, self.query._mongooseOptions);
self.query.model.populate(doc, pop, function (err, doc) {
// Hack to work around gh-3108
pop.forEach(function(option) {
delete option.model;
});
self.query.model.populate(doc, pop, function(err, doc) {
if (err) return self.destroy(err);
return true === opts.lean ?
emit(self, doc) :
createAndEmit(self, pop, doc);
});
}
};
function createAndEmit (self, populatedIds, doc) {
function createAndEmit(self, populatedIds, doc) {
var instance = helpers.createModel(self.query.model, doc, self._fields);
var opts = populatedIds ?
{ populated: populatedIds } :
undefined;
instance.init(doc, opts, function (err) {
instance.init(doc, opts, function(err) {
if (err) return self.destroy(err);
emit(self, instance);
});
@@ -247,7 +253,7 @@ function createAndEmit (self, populatedIds, doc) {
* Emit a data event and manage the trampoline state
*/
function emit (self, doc) {
function emit(self, doc) {
self.emit('data', self._transform(doc));
// trampoline management
@@ -267,9 +273,9 @@ function emit (self, doc) {
* @api public
*/
QueryStream.prototype.pause = function () {
QueryStream.prototype.pause = function() {
this.paused = true;
}
};
/**
* Resumes this stream.
@@ -277,7 +283,7 @@ QueryStream.prototype.pause = function () {
* @api public
*/
QueryStream.prototype.resume = function () {
QueryStream.prototype.resume = function() {
this.paused = false;
if (!this._cursor) {
@@ -294,7 +300,7 @@ QueryStream.prototype.resume = function () {
// outside QueryStream control, need manual restart
return this._next();
}
}
};
/**
* Destroys the stream, closing the underlying cursor. No more events will be emitted.
@@ -303,7 +309,7 @@ QueryStream.prototype.resume = function () {
* @api public
*/
QueryStream.prototype.destroy = function (err) {
QueryStream.prototype.destroy = function(err) {
if (this._destroyed) return;
this._destroyed = true;
this._running = false;
@@ -318,7 +324,7 @@ QueryStream.prototype.destroy = function (err) {
}
this.emit('close');
}
};
/**
* Pipes this query stream into another stream. This method is inherited from NodeJS Streams.