<commit_before>var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var cookie = require('cookie')
var fs = require('fs');
var redis = require("redis");
var request = require('superagent');

var conf = get_conf();
var subscriber = redis.createClient(conf.redis_socketio || conf.redis_async_broker_port);

// serve socketio
http.listen(conf.socketio_port, function(){
  console.log('listening on *:', conf.socketio_port);
});

// test route
app.get('/', function(req, res){
  res.sendfile('index.html');
});

// on socket connection
io.on('connection', function(socket){
	if (get_hostname(socket.request.headers.host) != get_hostname(socket.request.headers.origin)) {
		return;
	}

	// console.log("connection!");
	var sid = cookie.parse(socket.request.headers.cookie).sid
	if(!sid) {
		return;
	}

	socket.user = cookie.parse(socket.request.headers.cookie).user_id;

	// console.log("firing get_user_info");
	request.get(get_url(socket, '/api/method/frappe.async.get_user_info'))
		.type('form')
		.query({
			sid: sid
		})
		.end(function(err, res) {
			if(err) {
				console.log(err);
				return;
			}
			if(res.status == 200) {
				var room = get_user_room(socket, res.body.message.user);
				// console.log('joining', room);
				socket.join(room);
				socket.join(get_site_room(socket));
			}
		});

	socket.on('task_subscribe', function(task_id) {
		var room = get_task_room(socket, task_id);
		socket.join(room);
	});

	socket.on('task_unsubscribe', function(task_id) {
		var room = get_task_room(socket, task_id);
		socket.leave(room);
	});<commit_msg>[temp] throttle socket io connection (#3260)<commit_after>var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var cookie = require('cookie')
var fs = require('fs');
var redis = require("redis");
var request = require('superagent');

var conf = get_conf();
var flags = {};
var subscriber = redis.createClient(conf.redis_socketio || conf.redis_async_broker_port);

// serve socketio
http.listen(conf.socketio_port, function(){
  console.log('listening on *:', conf.socketio_port);
});

// test route
app.get('/', function(req, res){
  res.sendfile('index.html');
});

// on socket connection
io.on('connection', function(socket){
	if (get_hostname(socket.request.headers.host) != get_hostname(socket.request.headers.origin)) {
		return;
	}

	// console.log("connection!");
	var sid = cookie.parse(socket.request.headers.cookie).sid
	if(!sid) {
		return;
	}

	if(flags[sid]) {
		// throttle this function
		return;
	}

	flags[sid] = sid;
	setTimeout(function() { flags[sid] = null; }, 10000);

	socket.user = cookie.parse(socket.request.headers.cookie).user_id;

	// console.log("firing get_user_info");
	request.get(get_url(socket, '/api/method/frappe.async.get_user_info'))
		.type('form')
		.query({
			sid: sid
		})
		.end(function(err, res) {
			if(err) {
				console.log(err);
				return;
			}
			if(res.status == 200) {
				var room = get_user_room(socket, res.body.message.user);
				// console.log('joining', room);
				socket.join(room);
				socket.join(get_site_room(socket));
			}
		});

	socket.on('task_subscribe', function(task_id) {
		var room = get_task_room(socket, task_id);
		socket.join(room);
	});

	socket.on('task_unsubscribe', function(task_id) {
		var room = get_task_room(socket, task_id);
		socket.leave(room);
	});
{'fraction_non_alphanumeric': 0.1817116060961313, 'fraction_numerical': 0.004396248534583822, 'mean_word_length': 4.540584415584416, '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': '5950054', 'n_tokens_mistral': 1303, 'n_tokens_neox': 1194, 'n_words': 208}