mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-12 09:33:32 +01:00
REST API speed improvement (#1577)
This commit is contained in:
@@ -1,37 +1,30 @@
|
||||
const util = require('util');
|
||||
|
||||
const methods = ['get', 'post', 'delete', 'patch', 'put'];
|
||||
// Paramable exists so we don't return a function unless we actually need one #savingmemory
|
||||
const paramable = [
|
||||
'channels', 'users', 'guilds', 'members',
|
||||
'bans', 'emojis', 'pins', 'permissions',
|
||||
'reactions', 'webhooks', 'messages',
|
||||
'notes', 'roles', 'applications',
|
||||
'invites', 'bot',
|
||||
const reflectors = [
|
||||
'toString', 'valueOf', 'inspect', 'constructor',
|
||||
Symbol.toPrimitive, util.inspect.custom,
|
||||
];
|
||||
const reflectors = ['toString', 'valueOf', 'inspect', Symbol.toPrimitive, util.inspect.custom];
|
||||
|
||||
module.exports = restManager => {
|
||||
const handler = {
|
||||
get(list, name) {
|
||||
if (reflectors.includes(name)) return () => list.join('/');
|
||||
if (paramable.includes(name)) {
|
||||
if (name === 'opts') {
|
||||
function toReturn(...args) { // eslint-disable-line no-inner-declarations
|
||||
list = list.concat(name);
|
||||
for (const arg of args) {
|
||||
if (arg !== null && typeof arg !== 'undefined') list = list.concat(arg);
|
||||
}
|
||||
list.push(...args.filter(x => x !== null && typeof x !== 'undefined'));
|
||||
return new Proxy(list, handler);
|
||||
}
|
||||
const directJoin = () => `${list.join('/')}/${name}`;
|
||||
for (const r of reflectors) toReturn[r] = directJoin;
|
||||
for (const method of methods) {
|
||||
toReturn[method] = options => restManager.request(method, `${list.join('/')}/${name}`, options);
|
||||
toReturn[method] = options => restManager.request(method, directJoin(), options);
|
||||
}
|
||||
return toReturn;
|
||||
}
|
||||
if (reflectors.includes(name)) return () => list.join('/');
|
||||
if (methods.includes(name)) return options => restManager.request(name, list.join('/'), options);
|
||||
return new Proxy(list.concat(name), handler);
|
||||
list.push(name);
|
||||
return new Proxy(list, handler);
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user