<commit_before>Template.discussion.onCreated(function() {
	subs.subscribe('discussion', this.data._id);

	this.count = new ReactiveVar(0);
	this.limit = new ReactiveVar(3);
});

Template.discussion.helpers({
	posts: function() {
		var instance = Template.instance();
		var posts = CourseDiscussions.find(
			{
				courseId: this._id,
				parentId: { $exists: false }
			},
			{
				sort: { time_updated: -1 }
			})
			.fetch();

		var count = posts.length;
		instance.count.set(count);

		var limit = instance.limit.get();
		if (limit) posts = posts.slice(0, limit);

		return posts;
	},

	newPost: function() {
		return {
			'new': true,
			courseId: this._id,
			userId: Meteor.userId(),
			text: ''
		};
	},

	limited: function() {
		var instance = Template.instance();
		var limit = instance.limit.get();

		if (limit) return instance.count.get() >= limit;
	},

	count: function() {
		return Template.instance().count.get();
	}
});

Template.discussion.events({<commit_msg>fix logic of limited helper<commit_after>Template.discussion.onCreated(function() {
	subs.subscribe('discussion', this.data._id);

	this.count = new ReactiveVar(0);
	this.limit = new ReactiveVar(3);
});

Template.discussion.helpers({
	posts: function() {
		var instance = Template.instance();
		var posts = CourseDiscussions.find(
			{
				courseId: this._id,
				parentId: { $exists: false }
			},
			{
				sort: { time_updated: -1 }
			})
			.fetch();

		var count = posts.length;
		instance.count.set(count);

		var limit = instance.limit.get();
		if (limit) posts = posts.slice(0, limit);

		return posts;
	},

	newPost: function() {
		return {
			'new': true,
			courseId: this._id,
			userId: Meteor.userId(),
			text: ''
		};
	},

	limited: function() {
		var instance = Template.instance();
		var limit = instance.limit.get();

		if (limit) return instance.count.get() > limit;
	},

	count: function() {
		return Template.instance().count.get();
	}
});

Template.discussion.events({
{'fraction_non_alphanumeric': 0.16725978647686832, 'fraction_numerical': 0.004067107269954245, 'mean_word_length': 3.4625850340136055, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1456349', 'n_tokens_mistral': 761, 'n_tokens_neox': 660, 'n_words': 141}