<commit_before><?php namespace App\Http\Controllers;

use Topic;
use Discussion;
use Illuminate\Http\Request;
use App\Filters\DiscussionFilters;

class DiscussionsController extends Controller
{
	public function __construct()
	{
		parent::__construct();
		
		if (app()->environment() != 'testing') {
			auth()->setUser(\User::find(1));
			view()->share('_user', auth()->user());
		}

		$this->middleware('auth')->except(['all', 'index', 'show']);
	}

	public function index(DiscussionFilters $filters)
	{
		// Get all the discussions sorted by the latest
		$discussions = Discussion::with([
			'replies.author',
			'topic.parent',
			'author'
		])->latest()->filter($filters);

		if (request()->wantsJson()) {
			return $discussions->get();
		}

		return view('pages.discussions.all', [
			'discussions' => $discussions->paginate(20),
			'topics' => cache('topics', collect())->where('parent_id', null),
		]);
	}

	public function create()
	{
		$topics = Topic::get()->pluck('name', 'id');

		return view('pages.discussions.create', compact('topics'));
	}

	public function show(Topic $topic, Discussion $discussion)
	{
		$discussion->load(['author', 'replies.author', 'topic', 'answer.author']);

		return view('pages.discussions.show', [
			'discussion' => $discussion,
			'replies' => $discussion->replies()->paginate(25),
			'topic' => $topic
		]);
	}
<commit_msg>Clean up eager loads<commit_after><?php namespace App\Http\Controllers;

use Topic;
use Discussion;
use Illuminate\Http\Request;
use App\Filters\DiscussionFilters;

class DiscussionsController extends Controller
{
	public function __construct()
	{
		parent::__construct();
		
		if (app()->environment() != 'testing') {
			auth()->setUser(\User::find(1));
			view()->share('_user', auth()->user());
		}

		$this->middleware('auth')->except(['all', 'index', 'show']);
	}

	public function index(DiscussionFilters $filters)
	{
		// Get all the discussions sorted by the latest
		$discussions = Discussion::with([
			'author',
			'replies.author',
			'topic',
		])->latest()->filter($filters);

		if (request()->wantsJson()) {
			return $discussions->get();
		}

		return view('pages.discussions.all', [
			'discussions' => $discussions->paginate(20),
			'topics' => cache('topics', collect())->where('parent_id', null),
		]);
	}

	public function create()
	{
		$topics = Topic::get()->pluck('name', 'id');

		return view('pages.discussions.create', compact('topics'));
	}

	public function show(Topic $topic, Discussion $discussion)
	{
		$discussion->load(['author', 'topic', 'answer.author']);

		return view('pages.discussions.show', [
			'discussion' => $discussion,
			'replies' => $discussion->replies()->paginate(20),
			'topic' => $topic->load('parent')
		]);
	}

{'fraction_non_alphanumeric': 0.20182815356489944, 'fraction_numerical': 0.003656307129798903, 'mean_word_length': 4.772151898734177, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 46, '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': '405585', 'n_tokens_mistral': 989, 'n_tokens_neox': 869, 'n_words': 172}