REST API speed improvement (#1577)

This commit is contained in:
Gus Caplan
2017-07-01 04:14:17 -05:00
committed by Amish Shah
parent 6bc7b3e068
commit 5ecd5f7d69
25 changed files with 114 additions and 109 deletions

View File

@@ -50,13 +50,6 @@ class Client extends EventEmitter {
*/
this.rest = new RESTManager(this);
/**
* API shortcut
* @type {Object}
* @private
*/
this.api = this.rest.api;
/**
* The data manager of the client
* @type {ClientDataManager}
@@ -198,6 +191,15 @@ class Client extends EventEmitter {
return this.ws.connection ? this.ws.connection.lastPingTimestamp : 0;
}
/**
* API shortcut
* @type {Object}
* @private
*/
get api() {
return this.rest.api;
}
/**
* Current status of the client's connection to Discord
* @type {?Status}
@@ -330,7 +332,7 @@ class Client extends EventEmitter {
*/
fetchUser(id, cache = true) {
if (this.users.has(id)) return Promise.resolve(this.users.get(id));
return this.api.users(id).get().then(data =>
return this.api.users[id].get().then(data =>
cache ? this.dataManager.newUser(data) : new User(this, data)
);
}
@@ -342,7 +344,7 @@ class Client extends EventEmitter {
*/
fetchInvite(invite) {
const code = this.resolver.resolveInviteCode(invite);
return this.api.invites(code).get({ query: { with_counts: true } })
return this.api.invites[code].get({ query: { with_counts: true } })
.then(data => new Invite(this, data));
}
@@ -353,7 +355,7 @@ class Client extends EventEmitter {
* @returns {Promise<Webhook>}
*/
fetchWebhook(id, token) {
return this.api.webhooks(id, token).get().then(data => new Webhook(this, data));
return this.api.webhooks.opts(id, token).get().then(data => new Webhook(this, data));
}
/**