mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-24 01:16:15 -04:00
bugfix, lint and refactor all bin scripts (#4617)
* bugfix, lint and refactor all bin scripts * for squash: throw Error(message) rather than log(message); throw Error() * for squash: Exit non-0 on unhandled Promise rejection Many of the recent lint changes have converted normal functions to async functions, and an error thrown in an async function does not cause Node.js to exit by default. * for squash: fix `require()` paths * for squash: remove erroneous `Object.keys()` call * for squash: fix missing `continue` statements * for squash: Fix HTTP method for deleteSession * for squash: delete erroneous throw Throw is only for errors, not successful completion. * for squash: redo migrateDirtyDBtoRealDB.js to fix async bugs * for squash: fix erroneous use of `for..of` * for squash: Add line break between statements * for squash: put closing paren on same line as last arg * for squash: Move `log()` back up where it was to minimize the diff to develop * for squash: indentation fixes * for squash: typo fix * for squash: wrap long lines * for squash: use `util.callbackify` to silence promise/no-callback-in-promise warning * for squash: use double quotes to improve readability Co-authored-by: Richard Hansen <rhansen@rhansen.org>
This commit is contained in:
parent
c0d9881a62
commit
2fdc737355
13 changed files with 458 additions and 466 deletions
|
@ -1,4 +1,12 @@
|
|||
require('ep_etherpad-lite/node_modules/npm').load({}, (er, npm) => {
|
||||
'use strict';
|
||||
|
||||
// As of v14, Node.js does not exit when there is an unhandled Promise rejection. Convert an
|
||||
// unhandled rejection into an uncaught exception, which does cause Node.js to exit.
|
||||
process.on('unhandledRejection', (err) => { throw err; });
|
||||
|
||||
const util = require('util');
|
||||
|
||||
require('ep_etherpad-lite/node_modules/npm').load({}, async (er, npm) => {
|
||||
process.chdir(`${npm.root}/..`);
|
||||
|
||||
// This script requires that you have modified your settings.json file
|
||||
|
@ -10,39 +18,42 @@ require('ep_etherpad-lite/node_modules/npm').load({}, (er, npm) => {
|
|||
|
||||
|
||||
const settings = require('ep_etherpad-lite/node/utils/Settings');
|
||||
let dirty = require('../src/node_modules/dirty');
|
||||
const ueberDB = require('../src/node_modules/ueberdb2');
|
||||
const log4js = require('../src/node_modules/log4js');
|
||||
const dirtyDb = require('ep_etherpad-lite/node_modules/dirty');
|
||||
const ueberDB = require('ep_etherpad-lite/node_modules/ueberdb2');
|
||||
const log4js = require('ep_etherpad-lite/node_modules/log4js');
|
||||
const dbWrapperSettings = {
|
||||
cache: '0', // The cache slows things down when you're mostly writing.
|
||||
writeInterval: 0, // Write directly to the database, don't buffer
|
||||
};
|
||||
const db = new ueberDB.database(settings.dbType, settings.dbSettings, dbWrapperSettings, log4js.getLogger('ueberDB'));
|
||||
let i = 0;
|
||||
let length = 0;
|
||||
const db = new ueberDB.database( // eslint-disable-line new-cap
|
||||
settings.dbType,
|
||||
settings.dbSettings,
|
||||
dbWrapperSettings,
|
||||
log4js.getLogger('ueberDB'));
|
||||
await db.init();
|
||||
|
||||
db.init(() => {
|
||||
console.log('Waiting for dirtyDB to parse its file.');
|
||||
dirty = dirty('var/dirty.db').on('load', () => {
|
||||
dirty.forEach(() => {
|
||||
length++;
|
||||
});
|
||||
console.log(`Found ${length} records, processing now.`);
|
||||
console.log('Waiting for dirtyDB to parse its file.');
|
||||
const dirty = dirtyDb('var/dirty.db');
|
||||
const length = await new Promise((resolve) => { dirty.once('load', resolve); });
|
||||
|
||||
dirty.forEach(async (key, value) => {
|
||||
const error = await db.set(key, value);
|
||||
console.log(`Wrote record ${i}`);
|
||||
i++;
|
||||
|
||||
if (i === length) {
|
||||
console.log('finished, just clearing up for a bit...');
|
||||
setTimeout(() => {
|
||||
process.exit(0);
|
||||
}, 5000);
|
||||
}
|
||||
});
|
||||
console.log('Please wait for all records to flush to database, then kill this process.');
|
||||
});
|
||||
console.log('done?');
|
||||
console.log(`Found ${length} records, processing now.`);
|
||||
const p = [];
|
||||
let numWritten = 0;
|
||||
dirty.forEach((key, value) => {
|
||||
let bcb, wcb;
|
||||
p.push(new Promise((resolve, reject) => {
|
||||
bcb = (err) => { if (err != null) return reject(err); };
|
||||
wcb = (err) => {
|
||||
if (err != null) return reject(err);
|
||||
if (++numWritten % 100 === 0) console.log(`Wrote record ${numWritten} of ${length}`);
|
||||
resolve();
|
||||
};
|
||||
}));
|
||||
db.set(key, value, bcb, wcb);
|
||||
});
|
||||
await Promise.all(p);
|
||||
console.log(`Wrote all ${numWritten} records`);
|
||||
|
||||
await util.promisify(db.close.bind(db))();
|
||||
console.log('Finished.');
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue