chore: eslint prefer-arrow-callback

This commit is contained in:
Peter Jaszkowiak
2021-02-04 00:01:39 -07:00
committed by Julian Lam
parent 707b55b6a5
commit b56d9e12b5
334 changed files with 4995 additions and 5182 deletions

View File

@@ -135,17 +135,15 @@ mongoModule.info = async function (db) {
stats.serverStatusError = serverStatusError;
const scale = 1024 * 1024 * 1024;
listCollections = listCollections.map(function (collectionInfo) {
return {
name: collectionInfo.ns,
count: collectionInfo.count,
size: collectionInfo.size,
avgObjSize: collectionInfo.avgObjSize,
storageSize: collectionInfo.storageSize,
totalIndexSize: collectionInfo.totalIndexSize,
indexSizes: collectionInfo.indexSizes,
};
});
listCollections = listCollections.map(collectionInfo => ({
name: collectionInfo.ns,
count: collectionInfo.count,
size: collectionInfo.size,
avgObjSize: collectionInfo.avgObjSize,
storageSize: collectionInfo.storageSize,
totalIndexSize: collectionInfo.totalIndexSize,
indexSizes: collectionInfo.indexSizes,
}));
stats.mem = serverStatus.mem || { resident: 0, virtual: 0, mapped: 0 };
stats.mem.resident = (stats.mem.resident / 1024).toFixed(3);

View File

@@ -115,7 +115,7 @@ module.exports = function (module) {
}
const map = helpers.toMap(data);
unCachedKeys.forEach(function (key) {
unCachedKeys.forEach((key) => {
cachedData[key] = map[key] || null;
cache.set(key, cachedData[key]);
});
@@ -123,7 +123,7 @@ module.exports = function (module) {
if (!fields.length) {
return keys.map(key => (cachedData[key] ? { ...cachedData[key] } : null));
}
return keys.map(function (key) {
return keys.map((key) => {
const item = cachedData[key] || {};
const result = {};
fields.forEach((field) => {
@@ -154,7 +154,7 @@ module.exports = function (module) {
}
const data = {};
fields.forEach(function (field) {
fields.forEach((field) => {
field = helpers.fieldToString(field);
data[field] = 1;
});
@@ -178,7 +178,7 @@ module.exports = function (module) {
}
var data = {};
fields.forEach(function (field) {
fields.forEach((field) => {
field = helpers.fieldToString(field);
data[field] = '';
});
@@ -211,7 +211,7 @@ module.exports = function (module) {
if (Array.isArray(key)) {
var bulk = module.client.collection('objects').initializeUnorderedBulkOp();
key.forEach(function (key) {
key.forEach((key) => {
bulk.find({ _key: key }).upsert().update({ $inc: increment });
});
await bulk.execute();

View File

@@ -22,7 +22,7 @@ module.exports = function (module) {
}, { _id: 0, _key: 1 }).toArray();
const map = {};
data.forEach(function (item) {
data.forEach((item) => {
map[item._key] = true;
});

View File

@@ -104,7 +104,7 @@ module.exports = function (module) {
const result = await module.client.collection('objects').find({ _key: { $in: sets }, members: value }, { projection: { _id: 0, members: 0 } }).toArray();
var map = {};
result.forEach(function (item) {
result.forEach((item) => {
map[item._key] = true;
});
@@ -127,7 +127,7 @@ module.exports = function (module) {
const data = await module.client.collection('objects').find({ _key: { $in: keys } }, { projection: { _id: 0 } }).toArray();
var sets = {};
data.forEach(function (set) {
data.forEach((set) => {
sets[set._key] = set.members || [];
});

View File

@@ -247,7 +247,7 @@ module.exports = function (module) {
return [await getSortedSetRank(reverse, key, values[0])];
}
const sortedSet = await module[reverse ? 'getSortedSetRevRange' : 'getSortedSetRange'](key, 0, -1);
return values.map(function (value) {
return values.map((value) => {
if (!value) {
return null;
}
@@ -272,7 +272,7 @@ module.exports = function (module) {
value = helpers.valueToString(value);
const result = await module.client.collection('objects').find({ _key: { $in: keys }, value: value }, { projection: { _id: 0, value: 0 } }).toArray();
var map = {};
result.forEach(function (item) {
result.forEach((item) => {
if (item) {
map[item._key] = item;
}
@@ -292,7 +292,7 @@ module.exports = function (module) {
const result = await module.client.collection('objects').find({ _key: key, value: { $in: values } }, { projection: { _id: 0, _key: 0 } }).toArray();
var valueToScore = {};
result.forEach(function (item) {
result.forEach((item) => {
if (item) {
valueToScore[item.value] = item.score;
}
@@ -329,7 +329,7 @@ module.exports = function (module) {
}).toArray();
var isMember = {};
results.forEach(function (item) {
results.forEach((item) => {
if (item) {
isMember[item.value] = true;
}
@@ -350,7 +350,7 @@ module.exports = function (module) {
}).toArray();
var isMember = {};
results.forEach(function (item) {
results.forEach((item) => {
if (item) {
isMember[item._key] = true;
}
@@ -381,7 +381,7 @@ module.exports = function (module) {
return [data.map(item => item.value)];
}
const sets = {};
data.forEach(function (item) {
data.forEach((item) => {
sets[item._key] = sets[item._key] || [];
sets[item._key].push(item.value);
});

View File

@@ -75,7 +75,7 @@ module.exports = function (module) {
return;
}
var bulk = module.client.collection('objects').initializeUnorderedBulkOp();
data.forEach(function (item) {
data.forEach((item) => {
if (!utils.isNumber(item[1])) {
throw new Error(`[[error:invalid-score, ${item[1]}]]`);
}

View File

@@ -140,7 +140,7 @@ module.exports = function (module) {
items.push(nextItem);
}
const members = await Promise.all(otherSets.map(async function (s) {
const members = await Promise.all(otherSets.map(async (s) => {
const data = await module.client.collection('objects').find({
_key: s, value: { $in: items.map(i => i.value) },
}, {
@@ -170,7 +170,7 @@ module.exports = function (module) {
}
const pipeline = [{ $match: { _key: { $in: params.sets } } }];
params.weights.forEach(function (weight, index) {
params.weights.forEach((weight, index) => {
if (weight !== 1) {
pipeline.push({
$project: {

View File

@@ -337,7 +337,7 @@ postgresModule.createIndices = function (callback) {
async.series([
async.apply(query, `CREATE INDEX IF NOT EXISTS "idx__legacy_zset__key__score" ON "legacy_zset"("_key" ASC, "score" DESC)`),
async.apply(query, `CREATE INDEX IF NOT EXISTS "idx__legacy_object__expireAt" ON "legacy_object"("expireAt" ASC)`),
], function (err) {
], (err) => {
if (err) {
winston.error(`Error creating index ${err.message}`);
return callback(err);

View File

@@ -12,7 +12,7 @@ module.exports = function (module) {
delete data[''];
}
await module.transaction(async function (client) {
await module.transaction(async (client) => {
const dataString = JSON.stringify(data);
async function setOne(key) {
await helpers.ensureLegacyObjectType(client, key, 'hash');
@@ -47,7 +47,7 @@ module.exports = function (module) {
return;
}
await module.transaction(async function (client) {
await module.transaction(async (client) => {
const valueString = JSON.stringify(value);
async function setOne(key) {
await helpers.ensureLegacyObjectType(client, key, 'hash');
@@ -159,7 +159,7 @@ SELECT (SELECT jsonb_object_agg(f, d."value")
}
var obj = {};
fields.forEach(function (f) {
fields.forEach((f) => {
obj[f] = null;
});
@@ -292,7 +292,7 @@ SELECT (h."data" ? $2::TEXT AND h."data"->>$2::TEXT IS NOT NULL) b
return null;
}
return await module.transaction(async function (client) {
return await module.transaction(async (client) => {
if (Array.isArray(key)) {
await helpers.ensureLegacyObjectsType(client, key, 'hash');
} else {

View File

@@ -88,9 +88,7 @@ SELECT "_key", "type"
throw new Error(`database: cannot insert multiple objects as ${type} because they already exist: ${parts.join(', ')}`);
}
var missing = keys.filter(function (k) {
return !res.rows.some(r => r._key === k);
});
var missing = keys.filter(k => !res.rows.some(r => r._key === k));
if (missing.length) {
throw new Error(`database: failed to insert keys for objects: ${JSON.stringify(missing)}`);

View File

@@ -8,7 +8,7 @@ module.exports = function (module) {
return;
}
await module.transaction(async function (client) {
await module.transaction(async (client) => {
await helpers.ensureLegacyObjectType(client, key, 'list');
await client.query({
name: 'listPrepend',
@@ -27,7 +27,7 @@ DO UPDATE SET "array" = ARRAY[$2::TEXT] || "legacy_list"."array"`,
return;
}
await module.transaction(async function (client) {
await module.transaction(async (client) => {
await helpers.ensureLegacyObjectType(client, key, 'list');
await client.query({
name: 'listAppend',

View File

@@ -26,9 +26,7 @@ module.exports = function (module) {
WHERE o."_key" = ANY($1::TEXT[])`,
values: [key],
});
return key.map(function (k) {
return res.rows.some(r => r.k === k);
});
return key.map(k => res.rows.some(r => r.k === k));
}
const res = await module.pool.query({
name: 'exists',
@@ -115,7 +113,7 @@ SELECT s."data" t
return;
}
await module.transaction(async function (client) {
await module.transaction(async (client) => {
await helpers.ensureLegacyObjectType(client, key, 'string');
await client.query({
name: 'set',
@@ -134,7 +132,7 @@ DO UPDATE SET "data" = $2::TEXT`,
return;
}
return await module.transaction(async function (client) {
return await module.transaction(async (client) => {
await helpers.ensureLegacyObjectType(client, key, 'string');
const res = await client.query({
name: 'increment',
@@ -151,7 +149,7 @@ RETURNING "data" d`,
};
module.rename = async function (oldKey, newKey) {
await module.transaction(async function (client) {
await module.transaction(async (client) => {
await client.query({
name: 'deleteRename',
text: `

View File

@@ -12,7 +12,7 @@ module.exports = function (module) {
if (!value.length) {
return;
}
await module.transaction(async function (client) {
await module.transaction(async (client) => {
await helpers.ensureLegacyObjectType(client, key, 'set');
await client.query({
name: 'setAdd',
@@ -38,7 +38,7 @@ DO NOTHING`,
keys = _.uniq(keys);
await module.transaction(async function (client) {
await module.transaction(async (client) => {
await helpers.ensureLegacyObjectsType(client, keys, 'set');
await client.query({
name: 'setsAdd',
@@ -129,9 +129,7 @@ SELECT s."member" m
values: [key, values],
});
return values.map(function (v) {
return res.rows.some(r => r.m === v);
});
return values.map(v => res.rows.some(r => r.m === v));
};
module.isMemberOfSets = async function (sets, value) {
@@ -154,9 +152,7 @@ SELECT o."_key" k
values: [sets, value],
});
return sets.map(function (s) {
return res.rows.some(r => r.k === s);
});
return sets.map(s => res.rows.some(r => r.k === s));
};
module.getSetMembers = async function (key) {
@@ -198,9 +194,7 @@ SELECT o."_key" k,
values: [keys],
});
return keys.map(function (k) {
return (res.rows.find(r => r.k === k) || { m: [] }).m;
});
return keys.map(k => (res.rows.find(r => r.k === k) || { m: [] }).m);
};
module.setCount = async function (key) {
@@ -238,9 +232,7 @@ SELECT o."_key" k,
values: [keys],
});
return keys.map(function (k) {
return (res.rows.find(r => r.k === k) || { c: 0 }).c;
});
return keys.map(k => (res.rows.find(r => r.k === k) || { c: 0 }).c);
};
module.setRemoveRandom = async function (key) {

View File

@@ -218,9 +218,7 @@ SELECT o."_key" k,
values: [keys],
});
return keys.map(function (k) {
return parseInt((res.rows.find(r => r.k === k) || { c: 0 }).c, 10);
});
return keys.map(k => parseInt((res.rows.find(r => r.k === k) || { c: 0 }).c, 10));
};
module.sortedSetsCardSum = async function (keys) {
@@ -347,7 +345,7 @@ SELECT o."_key" k,
values: [keys, value],
});
return keys.map(function (k) {
return keys.map((k) => {
var s = res.rows.find(r => r.k === k);
return s ? parseFloat(s.s) : null;
});
@@ -376,7 +374,7 @@ SELECT z."value" v,
values: [key, values],
});
return values.map(function (v) {
return values.map((v) => {
var s = res.rows.find(r => r.v === v);
return s ? parseFloat(s.s) : null;
});
@@ -428,9 +426,7 @@ SELECT z."value" v
values: [key, values],
});
return values.map(function (v) {
return res.rows.some(r => r.v === v);
});
return values.map(v => res.rows.some(r => r.v === v));
};
module.isMemberOfSortedSets = async function (keys, value) {
@@ -453,9 +449,7 @@ SELECT o."_key" k
values: [keys, value],
});
return keys.map(function (k) {
return res.rows.some(r => r.k === k);
});
return keys.map(k => res.rows.some(r => r.k === k));
};
module.getSortedSetMembers = async function (key) {
@@ -477,9 +471,7 @@ SELECT "_key" k,
values: [keys],
});
return keys.map(function (k) {
return (res.rows.find(r => r.k === k) || {}).m || [];
});
return keys.map(k => (res.rows.find(r => r.k === k) || {}).m || []);
};
module.sortedSetIncrBy = async function (key, increment, value) {
@@ -490,7 +482,7 @@ SELECT "_key" k,
value = helpers.valueToString(value);
increment = parseFloat(increment);
return await module.transaction(async function (client) {
return await module.transaction(async (client) => {
await helpers.ensureLegacyObjectType(client, key, 'zset');
const res = await client.query({
name: 'sortedSetIncrBy',

View File

@@ -18,7 +18,7 @@ module.exports = function (module) {
value = helpers.valueToString(value);
score = parseFloat(score);
await module.transaction(async function (client) {
await module.transaction(async (client) => {
await helpers.ensureLegacyObjectType(client, key, 'zset');
await client.query({
name: 'sortedSetAdd',
@@ -49,7 +49,7 @@ module.exports = function (module) {
helpers.removeDuplicateValues(values, scores);
await module.transaction(async function (client) {
await module.transaction(async (client) => {
await helpers.ensureLegacyObjectType(client, key, 'zset');
await client.query({
name: 'sortedSetAddBulk',
@@ -81,7 +81,7 @@ DO UPDATE SET "score" = EXCLUDED."score"`,
value = helpers.valueToString(value);
scores = isArrayOfScores ? scores.map(score => parseFloat(score)) : parseFloat(scores);
await module.transaction(async function (client) {
await module.transaction(async (client) => {
await helpers.ensureLegacyObjectsType(client, keys, 'zset');
await client.query({
name: isArrayOfScores ? 'sortedSetsAddScores' : 'sortedSetsAdd',
@@ -108,7 +108,7 @@ INSERT INTO "legacy_zset" ("_key", "value", "score")
const keys = [];
const values = [];
const scores = [];
data.forEach(function (item) {
data.forEach((item) => {
if (!utils.isNumber(item[1])) {
throw new Error(`[[error:invalid-score, ${item[1]}]]`);
}
@@ -116,7 +116,7 @@ INSERT INTO "legacy_zset" ("_key", "value", "score")
scores.push(item[1]);
values.push(item[2]);
});
await module.transaction(async function (client) {
await module.transaction(async (client) => {
await helpers.ensureLegacyObjectsType(client, keys, 'zset');
await client.query({
name: 'sortedSetAddBulk2',

View File

@@ -79,12 +79,10 @@ OFFSET $3::INTEGER`,
});
if (params.withScores) {
res.rows = res.rows.map(function (r) {
return {
value: r.value,
score: parseFloat(r.score),
};
});
res.rows = res.rows.map(r => ({
value: r.value,
score: parseFloat(r.score),
}));
} else {
res.rows = res.rows.map(r => r.value);
}

View File

@@ -71,12 +71,10 @@ OFFSET $3::INTEGER`,
});
if (params.withScores) {
res.rows = res.rows.map(function (r) {
return {
value: r.value,
score: parseFloat(r.score),
};
});
res.rows = res.rows.map(r => ({
value: r.value,
score: parseFloat(r.score),
}));
} else {
res.rows = res.rows.map(r => r.value);
}

View File

@@ -76,7 +76,7 @@ redisModule.info = async function (cxn) {
const data = await infoAsync();
const lines = data.toString().split('\r\n').sort();
const redisData = {};
lines.forEach(function (line) {
lines.forEach((line) => {
const parts = line.split(':');
if (parts[1]) {
redisData[parts[0]] = parts[1];

View File

@@ -20,7 +20,7 @@ connection.getConnectionOptions = function (redis) {
};
connection.connect = async function (options) {
return new Promise(function (resolve, reject) {
return new Promise((resolve, reject) => {
options = options || nconf.get('redis');
const redis_socket_or_host = options.host;
const connOptions = connection.getConnectionOptions(options);
@@ -39,11 +39,11 @@ connection.connect = async function (options) {
throw new Error('[[error:no-database-selected]]');
}
cxn.on('error', function (err) {
cxn.on('error', (err) => {
winston.error(err.stack);
reject(err);
});
cxn.on('ready', function () {
cxn.on('ready', () => {
resolve(cxn);
});

View File

@@ -16,7 +16,7 @@ module.exports = function (module) {
delete data[''];
}
Object.keys(data).forEach(function (key) {
Object.keys(data).forEach((key) => {
if (data[key] === undefined || data[key] === null) {
delete data[key];
}
@@ -99,7 +99,7 @@ module.exports = function (module) {
return [];
}
if (!Array.isArray(fields)) {
return keys.map(function () { return {}; });
return keys.map(() => ({}));
}
const cachedData = {};
const unCachedKeys = cache.getUnCachedKeys(keys, cachedData);
@@ -113,7 +113,7 @@ module.exports = function (module) {
data = [await module.client.async.hgetall(unCachedKeys[0])];
}
unCachedKeys.forEach(function (key, i) {
unCachedKeys.forEach((key, i) => {
cachedData[key] = data[i] || null;
cache.set(key, cachedData[key]);
});
@@ -121,7 +121,7 @@ module.exports = function (module) {
if (!fields.length) {
return keys.map(key => (cachedData[key] ? { ...cachedData[key] } : null));
}
return keys.map(function (key) {
return keys.map((key) => {
const item = cachedData[key] || {};
const result = {};
fields.forEach((field) => {

View File

@@ -11,10 +11,10 @@ const PubSub = function () {
const self = this;
channelName = `db:${nconf.get('redis:database')}:pubsub_channel`;
connection.connect().then(function (client) {
connection.connect().then((client) => {
self.subClient = client;
self.subClient.subscribe(channelName);
self.subClient.on('message', function (channel, message) {
self.subClient.on('message', (channel, message) => {
if (channel !== channelName) {
return;
}
@@ -28,7 +28,7 @@ const PubSub = function () {
});
});
connection.connect().then(function (client) {
connection.connect().then((client) => {
self.pubClient = client;
});
};

View File

@@ -65,7 +65,7 @@ module.exports = function (module) {
return;
}
var batch = module.client.batch();
data.forEach(function (item) {
data.forEach((item) => {
if (!utils.isNumber(item[1])) {
throw new Error(`[[error:invalid-score, ${item[1]}]]`);
}