<commit_before>import { bus, Constants, cache } from '../../core-base';
import Counter from '../../lib/counter';

function validateTime (changes, next) {
	if (!changes.entities) return next();
	const counter = new Counter(),
		now = Date.now();

	for (const id in changes.entities) {
		const entity = changes.entities[id];

		counter.inc();
		cache.getEntity(id, (err, result) => {
			if (err) {
				counter.err(err);
				return;
			}

			console.log("Getting: ", id, result);
			if (result) {
				entity.createTime = result.createTime;
			} else {
				entity.createTime = now;
			}

			entity.updateTime = now;
			counter.dec();
		});
	}
	return counter.then(next);
}

bus.on('change', validateTime, Constants.APP_PRIORITIES.TIMES_VALIDATION1);
bus.on('change', validateTime, Constants.APP_PRIORITIES.TIMES_VALIDATION2);
<commit_msg>fix(times): make sure no two entities have same createTime<commit_after>import { bus, Constants, cache } from '../../core-base';
import Counter from '../../lib/counter';

function validateTime(changes, next) {
	let i = 0;
	if (!changes.entities) return next();
	const counter = new Counter(),
		now = Date.now();

	for (const id in changes.entities) {
		const entity = changes.entities[id];

		counter.inc();
		cache.getEntity(id, (err, result) => { // eslint-disable-line no-loop-func
			if (err) {
				counter.err(err);
				return;
			}

			i++;
			if (result) {
				entity.createTime = result.createTime;
			} else {
				entity.createTime = now + i;
			}

			entity.updateTime = now + i;
			counter.dec();
		});
	}
	return counter.then(next);
}

bus.on('change', validateTime, Constants.APP_PRIORITIES.TIMES_VALIDATION1);
bus.on('change', validateTime, Constants.APP_PRIORITIES.TIMES_VALIDATION2);

{'fraction_non_alphanumeric': 0.16080691642651296, 'fraction_numerical': 0.002881844380403458, 'mean_word_length': 3.5925925925925926, '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': '5365572', 'n_tokens_mistral': 655, 'n_tokens_neox': 584, 'n_words': 134}