Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating static tool #113

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{
"presets": [["@babel/preset-flow", { "all": true }]]
}
// {
// "presets": [["@babel/preset-flow", { "all": true }]]
// }

{ "presets": ["@babel/preset-flow"] }
18 changes: 18 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"url": "http://127.0.0.1:4567",
"secret": "91e2cee9-57de-4dcd-bb08-d85eeda3067c",
"database": "redis",
"redis": {
"host": "127.0.0.1",
"port": "6379",
"password": "",
"database": "0"
},
"port": "4567",
"test_database": {
"host": "127.0.0.1",
"port": "6379",
"password": "",
"database": "1"
}
}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"test": "npx tsc && nyc --reporter=html --reporter=text-summary mocha",
"coverage": "nyc report --reporter=text-lcov > ./coverage/lcov.info",
"coveralls": "nyc report --reporter=text-lcov | coveralls && rm -r coverage",
"build": "babel src/ -d dist/"
"build": "babel src/ -d dist/",
"flow": "flow"
},
"nyc": {
"exclude": [
Expand Down Expand Up @@ -166,6 +167,7 @@
"eslint": "^8.31.0",
"eslint-config-nodebb": "^0.2.1",
"eslint-plugin-import": "2.26.0",
"flow-bin": "^0.219.2",
"grunt": "1.5.3",
"grunt-contrib-watch": "1.1.0",
"husky": "8.0.2",
Expand Down
72 changes: 36 additions & 36 deletions src/upgrades/1.4.6/delete_sessions.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
'use strict';
// 'use strict';

const nconf = require('nconf');
const db = require('../../database');
const batch = require('../../batch');
// const nconf = require('nconf');
// const db = require('../../database');
// const batch = require('../../batch');

module.exports = {
name: 'Delete accidentally long-lived sessions',
timestamp: Date.UTC(2017, 3, 16),
method: async function () {
let configJSON;
try {
configJSON = require('../../../config.json') || { [process.env.database]: true };
} catch (err) {
configJSON = { [process.env.database]: true };
}
// module.exports = {
// name: 'Delete accidentally long-lived sessions',
// timestamp: Date.UTC(2017, 3, 16),
// method: async function () {
// let configJSON;
// try {
// configJSON = require('../../../config.json') || { [process.env.database]: true };
// } catch (err) {
// configJSON = { [process.env.database]: true };
// }

const isRedisSessionStore = configJSON.hasOwnProperty('redis');
const { progress } = this;
// const isRedisSessionStore = configJSON.hasOwnProperty('redis');
// const { progress } = this;

if (isRedisSessionStore) {
const connection = require('../../database/redis/connection');
const client = await connection.connect(nconf.get('redis'));
const sessionKeys = await client.keys('sess:*');
progress.total = sessionKeys.length;
// if (isRedisSessionStore) {
// const connection = require('../../database/redis/connection');
// const client = await connection.connect(nconf.get('redis'));
// const sessionKeys = await client.keys('sess:*');
// progress.total = sessionKeys.length;

await batch.processArray(sessionKeys, async (keys) => {
const multi = client.multi();
keys.forEach((key) => {
progress.incr();
multi.del(key);
});
await multi.exec();
}, {
batch: 1000,
});
} else if (db.client && db.client.collection) {
await db.client.collection('sessions').deleteMany({}, {});
}
},
};
// await batch.processArray(sessionKeys, async (keys) => {
// const multi = client.multi();
// keys.forEach((key) => {
// progress.incr();
// multi.del(key);
// });
// await multi.exec();
// }, {
// batch: 1000,
// });
// } else if (db.client && db.client.collection) {
// await db.client.collection('sessions').deleteMany({}, {});
// }
// },
// };
82 changes: 41 additions & 41 deletions src/upgrades/1.7.3/key_value_schema_change.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
/* eslint-disable no-await-in-loop */
// /* eslint-disable no-await-in-loop */

'use strict';
// 'use strict';

const db = require('../../database');
// const db = require('../../database');

module.exports = {
name: 'Change the schema of simple keys so they don\'t use value field (mongodb only)',
timestamp: Date.UTC(2017, 11, 18),
method: async function () {
let configJSON;
try {
configJSON = require('../../../config.json') || { [process.env.database]: true, database: process.env.database };
} catch (err) {
configJSON = { [process.env.database]: true, database: process.env.database };
}
const isMongo = configJSON.hasOwnProperty('mongo') && configJSON.database === 'mongo';
const { progress } = this;
if (!isMongo) {
return;
}
const { client } = db;
const query = {
_key: { $exists: true },
value: { $exists: true },
score: { $exists: false },
};
progress.total = await client.collection('objects').countDocuments(query);
const cursor = await client.collection('objects').find(query).batchSize(1000);
// module.exports = {
// name: 'Change the schema of simple keys so they don\'t use value field (mongodb only)',
// timestamp: Date.UTC(2017, 11, 18),
// method: async function () {
// let configJSON;
// try {
// configJSON = require('../../../config.json') || { [process.env.database]: true, database: process.env.database };
// } catch (err) {
// configJSON = { [process.env.database]: true, database: process.env.database };
// }
// const isMongo = configJSON.hasOwnProperty('mongo') && configJSON.database === 'mongo';
// const { progress } = this;
// if (!isMongo) {
// return;
// }
// const { client } = db;
// const query = {
// _key: { $exists: true },
// value: { $exists: true },
// score: { $exists: false },
// };
// progress.total = await client.collection('objects').countDocuments(query);
// const cursor = await client.collection('objects').find(query).batchSize(1000);

let done = false;
while (!done) {
const item = await cursor.next();
progress.incr();
if (item === null) {
done = true;
} else {
delete item.expireAt;
if (Object.keys(item).length === 3 && item.hasOwnProperty('_key') && item.hasOwnProperty('value')) {
await client.collection('objects').updateOne({ _key: item._key }, { $rename: { value: 'data' } });
}
}
}
},
};
// let done = false;
// while (!done) {
// const item = await cursor.next();
// progress.incr();
// if (item === null) {
// done = true;
// } else {
// delete item.expireAt;
// if (Object.keys(item).length === 3 && item.hasOwnProperty('_key') && item.hasOwnProperty('value')) {
// await client.collection('objects').updateOne({ _key: item._key }, { $rename: { value: 'data' } });
// }
// }
// }
// },
// };
134 changes: 67 additions & 67 deletions webpack.common.js
Original file line number Diff line number Diff line change
@@ -1,72 +1,72 @@
'use strict';
// 'use strict';

const path = require('path');
const url = require('url');
const nconf = require('nconf');
// const path = require('path');
// const url = require('url');
// const nconf = require('nconf');

const activePlugins = require('./build/active_plugins.json');
// const activePlugins = require('./build/active_plugins.json');

let relativePath = nconf.get('relative_path');
if (relativePath === undefined) {
nconf.file({
file: path.resolve(__dirname, nconf.any(['config', 'CONFIG']) || 'config.json'),
});
// let relativePath = nconf.get('relative_path');
// if (relativePath === undefined) {
// nconf.file({
// file: path.resolve(__dirname, nconf.any(['config', 'CONFIG']) || 'config.json'),
// });

const urlObject = url.parse(nconf.get('url'));
relativePath = urlObject.pathname !== '/' ? urlObject.pathname.replace(/\/+$/, '') : '';
}
// const urlObject = url.parse(nconf.get('url'));
// relativePath = urlObject.pathname !== '/' ? urlObject.pathname.replace(/\/+$/, '') : '';
// }

module.exports = {
plugins: [],
entry: {
nodebb: './build/public/src/client.js',
admin: './build/public/src/admin/admin.js',
},
output: {
filename: '[name].min.js',
chunkFilename: '[name].[contenthash].min.js',
path: path.resolve(__dirname, 'build/public'),
publicPath: `${relativePath}/assets/`,
clean: {
keep(asset) {
return asset === 'installer.min.js' ||
!asset.endsWith('.min.js');
},
},
},
watchOptions: {
poll: 500,
aggregateTimeout: 250,
},
resolve: {
symlinks: false,
modules: [
'build/public/src/modules',
'build/public/src',
'node_modules',
...activePlugins.map(p => `node_modules/${p}/node_modules`),
],
extensions: ['.js', '.json', '.wasm', '.mjs'],
alias: {
assets: path.resolve(__dirname, 'build/public'),
forum: path.resolve(__dirname, 'build/public/src/client'),
admin: path.resolve(__dirname, 'build/public/src/admin'),
vendor: path.resolve(__dirname, 'public/vendor'),
benchpress: path.resolve(__dirname, 'node_modules/benchpressjs'),
Chart: path.resolve(__dirname, 'node_modules/chart.js'),
Sortable: path.resolve(__dirname, 'node_modules/sortablejs'),
cropper: path.resolve(__dirname, 'node_modules/cropperjs'),
'jquery-ui/widgets': path.resolve(__dirname, 'node_modules/jquery-ui/ui/widgets'),
'ace/ace': path.resolve(__dirname, 'build/public/src/modules/ace-editor.js'),
},
},
module: {
rules: [
{
test: /\.(ts|tsx)$/,
exclude: /node_modules/,
loader: 'ignore-loader',
},
],
},
};
// module.exports = {
// plugins: [],
// entry: {
// nodebb: './build/public/src/client.js',
// admin: './build/public/src/admin/admin.js',
// },
// output: {
// filename: '[name].min.js',
// chunkFilename: '[name].[contenthash].min.js',
// path: path.resolve(__dirname, 'build/public'),
// publicPath: `${relativePath}/assets/`,
// clean: {
// keep(asset) {
// return asset === 'installer.min.js' ||
// !asset.endsWith('.min.js');
// },
// },
// },
// watchOptions: {
// poll: 500,
// aggregateTimeout: 250,
// },
// resolve: {
// symlinks: false,
// modules: [
// 'build/public/src/modules',
// 'build/public/src',
// 'node_modules',
// ...activePlugins.map(p => `node_modules/${p}/node_modules`),
// ],
// extensions: ['.js', '.json', '.wasm', '.mjs'],
// alias: {
// assets: path.resolve(__dirname, 'build/public'),
// forum: path.resolve(__dirname, 'build/public/src/client'),
// admin: path.resolve(__dirname, 'build/public/src/admin'),
// vendor: path.resolve(__dirname, 'public/vendor'),
// benchpress: path.resolve(__dirname, 'node_modules/benchpressjs'),
// Chart: path.resolve(__dirname, 'node_modules/chart.js'),
// Sortable: path.resolve(__dirname, 'node_modules/sortablejs'),
// cropper: path.resolve(__dirname, 'node_modules/cropperjs'),
// 'jquery-ui/widgets': path.resolve(__dirname, 'node_modules/jquery-ui/ui/widgets'),
// 'ace/ace': path.resolve(__dirname, 'build/public/src/modules/ace-editor.js'),
// },
// },
// module: {
// rules: [
// {
// test: /\.(ts|tsx)$/,
// exclude: /node_modules/,
// loader: 'ignore-loader',
// },
// ],
// },
// };