<commit_before>use std::io::BufRead;
use std::io::BufReader;
use std::io::BufWriter;
use std::io::Write;
use std::net::TcpStream;

use ::Repository;

use ::misc::*;

pub fn handle_client (
	repository: & Repository,
	stream: TcpStream,
) {

	let peer_address =
		stream.peer_addr ().unwrap ();

	println! (
		"Connection from: {}",
		peer_address);

	match handle_client_real (
		repository,
		stream) {

		Ok (_) => {

			println! (
				"Disconnection from: {}",
				peer_address);

		},

		Err (error) => {

			println! (
				"Error from: {}: {}",
				peer_address,
				error);

		},

	}

}

fn handle_client_real (
	repository: & Repository,
	stream: TcpStream,
) -> Result <(), String> {

	let mut reader =
		BufReader::new (
			& stream);

	loop {

		let mut line =
			String::new ();

		try! (
			io_result (
				reader.read_line (
					& mut line)));

		if line.is_empty () {

			println! (
				"Disconnect");

			return Ok (());

		}

		let parts: Vec <& str> =
			line.splitn (2, ' ').collect ();

		let command_string =
			parts [0].trim ().to_lowercase ();

		let command =
			& command_string;

		let rest =
			if parts.len () > 1 {
				parts [1].trim ()
			} else {
				""
			};

		if command == "exit" {

			println! (
				"Exiting");

			return Ok (());

		} else if command == "reindex" {

			try! (
				handle_reindex (
					repository,
					& stream));

		} else if command == "restore" {

			try! (
				handle_restore (
					repository,
					& stream,
					rest));

			return Ok (());

		} else {

			try! (
				handle_command_not_recognised (
					& stream,
					command));

		}

	}

}

fn handle_reindex (
	repository: & Repository,
	stream: & TcpStream,
) -> Result <(), String> {

	println! (
		"Will reindex");

	let mut writer =
		BufWriter::new (
			stream);

	try! (

		repository.load_indexes (
		).map_err (
			|error|

			format! (
				"Error during reindex: {}",
				error)

		)

	);

	try! (
		io_result (
			writer.write_fmt (
				format_args! (
					"OK\n"))));

	Ok (())

}
<commit_msg>fix reload command which was calling lazy one-off load by accident<commit_after>use std::io::BufRead;
use std::io::BufReader;
use std::io::BufWriter;
use std::io::Write;
use std::net::TcpStream;

use ::Repository;

use ::misc::*;

pub fn handle_client (
	repository: & Repository,
	stream: TcpStream,
) {

	let peer_address =
		stream.peer_addr ().unwrap ();

	println! (
		"Connection from: {}",
		peer_address);

	match handle_client_real (
		repository,
		stream) {

		Ok (_) => {

			println! (
				"Disconnection from: {}",
				peer_address);

		},

		Err (error) => {

			println! (
				"Error from: {}: {}",
				peer_address,
				error);

		},

	}

}

fn handle_client_real (
	repository: & Repository,
	stream: TcpStream,
) -> Result <(), String> {

	let mut reader =
		BufReader::new (
			& stream);

	loop {

		let mut line =
			String::new ();

		try! (
			io_result (
				reader.read_line (
					& mut line)));

		if line.is_empty () {

			println! (
				"Disconnect");

			return Ok (());

		}

		let parts: Vec <& str> =
			line.splitn (2, ' ').collect ();

		let command_string =
			parts [0].trim ().to_lowercase ();

		let command =
			& command_string;

		let rest =
			if parts.len () > 1 {
				parts [1].trim ()
			} else {
				""
			};

		if command == "exit" {

			println! (
				"Exiting");

			return Ok (());

		} else if command == "reindex" {

			try! (
				handle_reindex (
					repository,
					& stream));

		} else if command == "restore" {

			try! (
				handle_restore (
					repository,
					& stream,
					rest));

			return Ok (());

		} else {

			try! (
				handle_command_not_recognised (
					& stream,
					command));

		}

	}

}

fn handle_reindex (
	repository: & Repository,
	stream: & TcpStream,
) -> Result <(), String> {

	println! (
		"Will reindex");

	let mut writer =
		BufWriter::new (
			stream);

	try! (

		repository.reload_indexes (
		).map_err (
			|error|

			format! (
				"Error during reindex: {}",
				error)

		)

	);

	try! (
		io_result (
			writer.write_fmt (
				format_args! (
					"OK\n"))));

	Ok (())

}

{'fraction_non_alphanumeric': 0.16573102269953624, 'fraction_numerical': 0.001952648279228704, 'mean_word_length': 2.4321608040201004, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 19, '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': '2951046', 'n_tokens_mistral': 1874, 'n_tokens_neox': 1470, 'n_words': 328}