<commit_before>'use strict';

const init = require('../base/init');
const config = require('../base/config');
const date2 = require('../base/date2');
const mongo2 = require('../mongodb/mongo2');
const my2 = require('../mysql/my2');
const imageb = require('../image/image-base');

init.add(
  (done) => {
    console.log('copy mongodb images to mysql image.');
    let c = 0;
    let cursor = mongo2.db.collection('images').find();
    (function read() {
      cursor.next(function (err, r) {
        if (err) return done(err);
        if (!r) return done();
        c++;
        if (c % 100 === 0) {
          process.stdout.write(c + ' ');
        }
        let img = {
          id: r._id,
          uid: r.uid,
          cdate: r.cdate,
          vers: JSON.stringify(r.vers || null),
          comment: r.comment,
        }
        my2.query('replace into image set ?', img, (err) => {
          if (err) return done(err);
          setImmediate(read);
        });
      });
    })();
  },
  (done) => {<commit_msg>use transaction on c2mysql images.<commit_after>'use strict';

const init = require('../base/init');
const config = require('../base/config');
const date2 = require('../base/date2');
const mongo2 = require('../mongodb/mongo2');
const my2 = require('../mysql/my2');
const imageb = require('../image/image-base');

init.add(
  (done) => {
    console.log('copy mongodb images to mysql image.');
    done();
  },
  (done) => {
    my2.query('start transaction', done);
  },
  (done) => {
    let c = 0;
    let cursor = mongo2.db.collection('images').find();
    (function read() {
      cursor.next(function (err, r) {
        if (err) return done(err);
        if (!r) return done();
        c++;
        if (c % 100 === 0) {
          process.stdout.write(c + ' ');
        }
        let img = {
          id: r._id,
          uid: r.uid,
          cdate: r.cdate,
          vers: JSON.stringify(r.vers || null),
          comment: r.comment,
        }
        my2.query('replace into image set ?', img, (err) => {
          if (err) return done(err);
          setImmediate(read);
        });
      });
    })();
  },
  (done) => {
    my2.query('commit', done);
  },
  (done) => {
{'fraction_non_alphanumeric': 0.19491140390731485, 'fraction_numerical': 0.013175829168559746, 'mean_word_length': 2.0, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, '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': '5307456', 'n_tokens_mistral': 734, 'n_tokens_neox': 721, 'n_words': 169}