<commit_before>'use strict';

import parse from 'misskey-text';
import db from '../db/mongodb';

// Init babel
require('babel-core/register');
require('babel-polyfill');

db(require('../config').default).then(async (db) => {
	const Post = db.collection('posts');
	const User = db.collection('users');

	const posts = await Post
		.find({})
		.toArray();

	posts.forEach(post => {

		let mentions = [];

		if (post.reply_to_id) {
			const replyTo = await Post.findOne({
				_id: post.reply_to_id
			});

			mentions.push(replyTo.user_id);
		}

		if (post.repost_id) {
			const repost = await Post.findOne({
				_id: post.repost_id
			});

			// If it is quote repost
			if (post.text) {
				// Add mention
				mentions.push(repost.user_id);
			}
		}

		if (post.text) {
			const tokens = parse(post.text);

			const atMentions = tokens
				.filter(t => t.type == 'mention')
				.map(m => m.username)
				.filter((v, i, s) => s.indexOf(v) == i);

			await Promise.all(atMentions.map(async (mention) => {
				const mentionee = await User
					.findOne({
						username_lower: mention.toLowerCase()
					}, { _id: true });

				if (mentionee == null) return;

				mentions.push(mentionee._id);

				return;
			}));
		}

		if (mentions.length == 0) return;

		mentions = mentions
			.filter((v, i, s) =>
				s.map(x => x.toString())
				.indexOf(v.toString()) == i);

		Post.updateOne({ _id: post._id }, {
			$set: {
				mentions: mentions
			}
		});
	});
});
<commit_msg>Fix bug<commit_after>'use strict';

import parse from 'misskey-text';
import db from '../db/mongodb';

// Init babel
require('babel-core/register');
require('babel-polyfill');

db(require('../config').default).then(async (db) => {
	const Post = db.collection('posts');
	const User = db.collection('users');

	const posts = await Post
		.find({})
		.toArray();

	posts.forEach(async post => {

		let mentions = [];

		if (post.reply_to_id) {
			const replyTo = await Post.findOne({
				_id: post.reply_to_id
			});

			mentions.push(replyTo.user_id);
		}

		if (post.repost_id) {
			const repost = await Post.findOne({
				_id: post.repost_id
			});

			// If it is quote repost
			if (post.text) {
				// Add mention
				mentions.push(repost.user_id);
			}
		}

		if (post.text) {
			const tokens = parse(post.text);

			const atMentions = tokens
				.filter(t => t.type == 'mention')
				.map(m => m.username)
				.filter((v, i, s) => s.indexOf(v) == i);

			await Promise.all(atMentions.map(async (mention) => {
				const mentionee = await User
					.findOne({
						username_lower: mention.toLowerCase()
					}, { _id: true });

				if (mentionee == null) return;

				mentions.push(mentionee._id);

				return;
			}));
		}

		if (mentions.length == 0) return;

		mentions = mentions
			.filter((v, i, s) =>
				s.map(x => x.toString())
				.indexOf(v.toString()) == i);

		Post.updateOne({ _id: post._id }, {
			$set: {
				mentions: mentions
			}
		});
	});
});

{'fraction_non_alphanumeric': 0.18064076346284935, 'fraction_numerical': 0.0006816632583503749, 'mean_word_length': 2.767650834403081, 'pattern_counts': {'":': 0, '<': 3, '<?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': '7525988', 'n_tokens_mistral': 1301, 'n_tokens_neox': 1064, 'n_words': 228}