<commit_before>// Publish single user

Meteor.publish('user', function(username) {
	return Meteor.users.find({username: username});
});

Meteor.publishComposite('userWithProfilePosts', function(username) {
	return {
		find: function() {
			return Meteor.users.find({username: username});
		},
		children: [
			{
				find: function(user) {
					return ProfilePosts.find({userId: user._id});
				},
				children: [
					{
						// Publish the poster as well if it wasn't a status update
						find: function(profilePost, user) {
							if (profilePost.statusUpdate === false) {
								return Meteor.users.find({_id: profilePost.posterId}, {fields: requireCollectionFields.user.defaultFields});
							}
						}
					},
					{

						// Publish the profile post's comments
						find: function(profilePost, user) {

							return Comments.find({contentId: profilePost._id, type: 'profilePost'});

						},
						children : [
							{
								find: function(comment, profilePost, user) {
									// Publish users if it isn't published 
									if (comment.userId !== user._id && comment.userId !== profilePost.posterId) {
										return Meteor.users.find({_id: comment.userId}, {fields: requireCollectionFields.user.defaultFields});
									}
								}
							}

						]

					}

				]
			}
		]
	};

});

Meteor.publishComposite('userWithActivity', function(username, limit) {
	return {
		find: function() {
			return Meteor.users.find({username: username});
		},
		children: [
			{
				find: function(user) {
					return Activity.find({userId: user._id}, {sort: {createdAt: -1}, limit: limit});
				},
				children: [
					{
						// Get library entry children
						find: function(activity, user) {
							if (activity.type === 'libraryEntry') {
								// Grab content
								if (activity.libraryEntry.type === 'anime') {
									return Anime.find({_id: activity.libraryEntry.contentId});
								}
							}
						}
					}
				]
			}
		]
	};

});

Meteor.publishComposite('userWithLibraryEntries', function(username) {
	return {
		find: function() {
			return Meteor.users.find({username: username});
		},
		children: [
			{
				find: function(user) {
					
					// If user's profile is not current profile we don't publish private entries
					if (user._id !== this.userId) {
						return LibraryEntries.find({userId: user._id, privacy: {$ne: true}}, {sort: {createdAt: -1}});
					} else {
						return LibraryEntries.find({userId: user._id}, {sort: {createdAt: -1}});
					}
				},
				children: [
					{
						find: function(libraryEntry, user) {

							return Anime.find({_id: libraryEntry.animeId}, {fields: requireCollectionFields.anime.requiredLibraryEntry});

						}
					}
				]
			}

		]
	};

});


Meteor.publishComposite('userWithFollowers', function(username) {
	return {
		find: function() {<commit_msg>Slight fix in the initial publication of libraryEntries, this should improve load times by quite a bit<commit_after>// Publish single user

Meteor.publish('user', function(username) {
	return Meteor.users.find({username: username});
});

Meteor.publishComposite('userWithProfilePosts', function(username) {
	return {
		find: function() {
			return Meteor.users.find({username: username});
		},
		children: [
			{
				find: function(user) {
					return ProfilePosts.find({userId: user._id});
				},
				children: [
					{
						// Publish the poster as well if it wasn't a status update
						find: function(profilePost, user) {
							if (profilePost.statusUpdate === false) {
								return Meteor.users.find({_id: profilePost.posterId}, {fields: requireCollectionFields.user.defaultFields});
							}
						}
					},
					{

						// Publish the profile post's comments
						find: function(profilePost, user) {

							return Comments.find({contentId: profilePost._id, type: 'profilePost'});

						},
						children : [
							{
								find: function(comment, profilePost, user) {
									// Publish users if it isn't published 
									if (comment.userId !== user._id && comment.userId !== profilePost.posterId) {
										return Meteor.users.find({_id: comment.userId}, {fields: requireCollectionFields.user.defaultFields});
									}
								}
							}

						]

					}

				]
			}
		]
	};

});

Meteor.publishComposite('userWithActivity', function(username, limit) {
	return {
		find: function() {
			return Meteor.users.find({username: username});
		},
		children: [
			{
				find: function(user) {
					return Activity.find({userId: user._id}, {sort: {createdAt: -1}, limit: limit});
				},
				children: [
					{
						// Get library entry children
						find: function(activity, user) {
							if (activity.type === 'libraryEntry') {
								// Grab content
								if (activity.libraryEntry.type === 'anime') {
									return Anime.find({_id: activity.libraryEntry.contentId});
								}
							}
						}
					}
				]
			}
		]
	};

});

Meteor.publishComposite('userWithLibraryEntries', function(username) {
	return {
		find: function() {
			return Meteor.users.find({username: username});
		},
		children: [
			{
				find: function(user) {
					
					// If user's profile is not current profile we don't publish private entries
					if (user._id !== this.userId) {
						return LibraryEntries.find({userId: user._id, privacy: {$ne: true}}, {sort: {createdAt: -1}, limit: 6});
					} else {
						return LibraryEntries.find({userId: user._id}, {sort: {createdAt: -1}, limit: 6});
					}
				},
				children: [
					{
						find: function(libraryEntry, user) {

							return Anime.find({_id: libraryEntry.animeId}, {fields: requireCollectionFields.anime.requiredLibraryEntry});

						}
					}
				]
			}

		]
	};

});


Meteor.publishComposite('userWithFollowers', function(username) {
	return {
		find: function() {
{'fraction_non_alphanumeric': 0.14384868991844527, 'fraction_numerical': 0.0013881658858233559, 'mean_word_length': 2.6457938013915245, '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': '2238637', 'n_tokens_mistral': 2440, 'n_tokens_neox': 1749, 'n_words': 370}