<commit_before>'use strict';

var Steppy = require('twostep').Steppy,
	_ = require('underscore'),
	EventEmitter = require('events').EventEmitter,
	inherits = require('util').inherits;

/**
 * Facade entity which accumulates operations with currently running and
 * db saved builds.
 */
function BuildsCollection(params) {
	this.db = params.db;
	this.distributor = params.distributor;

	this._proxyDistributorEvent('buildUpdate', 'buildUpdated');
	this._proxyDistributorEvent('buildCancel', 'buildCanceled');
	this._proxyDistributorEvent('buildLogLines', 'buildLogLines');
}

exports.BuildsCollection = BuildsCollection;

inherits(BuildsCollection, EventEmitter);

BuildsCollection.prototype._proxyDistributorEvent = function(source, dest) {
	var self = this;

	self.distributor.on(source, function() {
		self.emit.apply(self, [dest].concat(_(arguments).toArray()));
	});
};

BuildsCollection.prototype.create = function(params, callback) {
	this.distributor.run(params, callback);
};

BuildsCollection.prototype.cancel = function(params, callback) {
	this.distributor.cancel(params, callback);
};

BuildsCollection.prototype.get = function(id, callback) {
	this.find({start: {id: id}}, function(err, builds) {
		callback(err, builds && builds[0]);
	});
};

BuildsCollection.prototype.getLogLines = function(params, callback) {
	var self = this;

	Steppy(
		function() {
			var findParams = {
				start: {buildId: params.buildId},
				end: {buildId: params.buildId}
			};
			if (params.from) findParams.start.number = params.from;
			if (params.to) findParams.end.number = params.to;

			var count = params.from && params.to ? params.to - params.from + 1: 0;

			self.db.logLines.find(findParams, this.slot());

			this.pass(count);<commit_msg>fix build get after remove find<commit_after>'use strict';

var Steppy = require('twostep').Steppy,
	_ = require('underscore'),
	EventEmitter = require('events').EventEmitter,
	inherits = require('util').inherits;

/**
 * Facade entity which accumulates operations with currently running and
 * db saved builds.
 */
function BuildsCollection(params) {
	this.db = params.db;
	this.distributor = params.distributor;

	this._proxyDistributorEvent('buildUpdate', 'buildUpdated');
	this._proxyDistributorEvent('buildCancel', 'buildCanceled');
	this._proxyDistributorEvent('buildLogLines', 'buildLogLines');
}

exports.BuildsCollection = BuildsCollection;

inherits(BuildsCollection, EventEmitter);

BuildsCollection.prototype._proxyDistributorEvent = function(source, dest) {
	var self = this;

	self.distributor.on(source, function() {
		self.emit.apply(self, [dest].concat(_(arguments).toArray()));
	});
};

BuildsCollection.prototype.create = function(params, callback) {
	this.distributor.run(params, callback);
};

BuildsCollection.prototype.cancel = function(params, callback) {
	this.distributor.cancel(params, callback);
};

BuildsCollection.prototype.get = function(id, callback) {
	this.db.builds.find({start: {id: id}}, function(err, builds) {
		callback(err, builds && builds[0]);
	});
};

BuildsCollection.prototype.getLogLines = function(params, callback) {
	var self = this;

	Steppy(
		function() {
			var findParams = {
				start: {buildId: params.buildId},
				end: {buildId: params.buildId}
			};
			if (params.from) findParams.start.number = params.from;
			if (params.to) findParams.end.number = params.to;

			var count = params.from && params.to ? params.to - params.from + 1: 0;

			self.db.logLines.find(findParams, this.slot());

			this.pass(count);
{'fraction_non_alphanumeric': 0.14684120660216277, 'fraction_numerical': 0.001707455890722823, 'mean_word_length': 5.321942446043166, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '857021', 'n_tokens_mistral': 1173, 'n_tokens_neox': 1092, 'n_words': 212}