<commit_before>'use strict';

var EventEmitter = require('events').EventEmitter;
var util = require('util');

var DETAIL_OPLOG = 'detailOplog';

var DetailedOplog = function(oplog, mongoreader) {
  EventEmitter.call(this);
  var self = this;
  this.mongoreader = mongoreader;
  this.events = oplog.events;
  this.oplog = oplog;
  oplog.on('op', this._onop.bind(this));
};

util.inherits(DetailedOplog, EventEmitter);

// intercept only update
DetailedOplog.prototype._onop = function(opDoc) {
  var self = this;
  var oplog = this.oplog;
  if (opDoc.op !== 'u') {
    oplog.emit(DETAIL_OPLOG, opDoc);
    return;
  }

  this.mongoreader.read(opDoc.ns, opDoc.o2._id).then(function(doc) {
    opDoc.o = doc;
    self.emit(DETAIL_OPLOG, opDoc);
  }).catch(function(err) {
    console.error('Can\'t locate document ' + opDoc.o2._id.toString());
  });
};

DetailedOplog.prototype.filter = function(ns) {
  return new DetailedFilter(ns, this);
};

/** Behaves as default filter except it passes the detailed op */
var DetailedFilter = function(ns, dOplog) {
  EventEmitter.call(this);
  this.ns = regex(ns || '*');
  this.dOplog = dOplog;
  dOplog.on(DETAIL_OPLOG, this._onop.bind(this));
};

util.inherits(DetailedFilter, EventEmitter);

DetailedFilter.prototype._onop = function(doc) {
  this.emit('op', doc);
  this.emit(this.dOplog.events[doc.op], doc);
};

DetailedFilter.prototype.destroy = function() {
  this.dOplog.off(DETAIL_OPLOG, doc);
  this.removeAllListeners();
  return this;
};

var regex = function(pattern) {
  pattern = pattern.replace(/[\*]/g, '(.*?)');
  return new RegExp('^' + pattern + '$', 'i');
};

module.exports = DetailedOplog;
<commit_msg>off is expired using removeListener<commit_after>'use strict';

var EventEmitter = require('events').EventEmitter;
var util = require('util');

var DETAIL_OPLOG = 'detailOplog';

var DetailedOplog = function(oplog, mongoreader) {
  EventEmitter.call(this);
  var self = this;
  this.mongoreader = mongoreader;
  this.events = oplog.events;
  this.oplog = oplog;
  oplog.on('op', this._onop.bind(this));
};

util.inherits(DetailedOplog, EventEmitter);

// intercept only update
DetailedOplog.prototype._onop = function(opDoc) {
  var self = this;
  var oplog = this.oplog;
  if (opDoc.op !== 'u') {
    oplog.emit(DETAIL_OPLOG, opDoc);
    return;
  }

  this.mongoreader.read(opDoc.ns, opDoc.o2._id).then(function(doc) {
    opDoc.o = doc;
    self.emit(DETAIL_OPLOG, opDoc);
  }).catch(function(err) {
    console.error('Can\'t locate document ' + opDoc.o2._id.toString());
  });
};

DetailedOplog.prototype.filter = function(ns) {
  return new DetailedFilter(ns, this);
};

/** Behaves as default filter except it passes the detailed op */
var DetailedFilter = function(ns, dOplog) {
  EventEmitter.call(this);
  this.ns = regex(ns || '*');
  this.dOplog = dOplog;
  dOplog.on(DETAIL_OPLOG, this._onop.bind(this));
};

util.inherits(DetailedFilter, EventEmitter);

DetailedFilter.prototype._onop = function(doc) {
  this.emit('op', doc);
  this.emit(this.dOplog.events[doc.op], doc);
};

DetailedFilter.prototype.destroy = function() {
  this.dOplog.removeListener(DETAIL_OPLOG, this._onop);
  this.removeAllListeners();
  return this;
};

var regex = function(pattern) {
  pattern = pattern.replace(/[\*]/g, '(.*?)');
  return new RegExp('^' + pattern + '$', 'i');
};

module.exports = DetailedOplog;

{'fraction_non_alphanumeric': 0.16597387173396674, 'fraction_numerical': 0.0011876484560570072, 'mean_word_length': 4.451456310679611, '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': '2325919', 'n_tokens_mistral': 1267, 'n_tokens_neox': 1249, 'n_words': 226}