mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-12 17:43:30 +01:00
Fixed the fix and built
This commit is contained in:
@@ -14,28 +14,15 @@ var Cache = (function (_Array) {
|
||||
|
||||
_Array.call(this);
|
||||
this.discrim = discrim || "id";
|
||||
this.discrimCache = [];
|
||||
this.highPerformance = false;
|
||||
this.discrimCache = {};
|
||||
}
|
||||
|
||||
Cache.prototype.setHighPerformance = function setHighPerformance() {
|
||||
this.highPerformance = true;
|
||||
};
|
||||
|
||||
Cache.prototype.setNormalPerformance = function setNormalPerformance() {
|
||||
this.discrimCache = [];
|
||||
this.highPerformance = false;
|
||||
};
|
||||
|
||||
Cache.prototype.get = function get(key, value) {
|
||||
var found = null;
|
||||
this.forEach(function (val, index, array) {
|
||||
if (val[key] == value) {
|
||||
found = val;
|
||||
return;
|
||||
}
|
||||
});
|
||||
return found;
|
||||
if (key === this.discrim) return this.discrimCache[value] || null;
|
||||
|
||||
var l = this.length;
|
||||
for (var i = 0; i < l; i++) if (this[i][key] == value) return this[i];
|
||||
return null;
|
||||
};
|
||||
|
||||
Cache.prototype.has = function has(object) {
|
||||
@@ -54,18 +41,16 @@ var Cache = (function (_Array) {
|
||||
};
|
||||
|
||||
Cache.prototype.add = function add(data) {
|
||||
var exit = false;
|
||||
exit = ~this.discrimCache.indexOf(data[this.discrim]);
|
||||
if (exit) {
|
||||
return data;
|
||||
} else {
|
||||
if (this.limit && this.length >= this.limit) {
|
||||
this.splice(0, 1);
|
||||
}
|
||||
this.push(data);
|
||||
this.discrimCache.push(data[this.discrim]);
|
||||
return data;
|
||||
var cacheKey = this.discrim === "id" ? data.id : data[this.discrim];
|
||||
if (this.discrimCache[cacheKey]) {
|
||||
return this.discrimCache[cacheKey];
|
||||
}
|
||||
if (this.limit && this.length >= this.limit) {
|
||||
this.splice(0, 1);
|
||||
}
|
||||
this.push(data);
|
||||
this.discrimCache[cacheKey] = data;
|
||||
return data;
|
||||
};
|
||||
|
||||
Cache.prototype.update = function update(old, data) {
|
||||
@@ -73,6 +58,7 @@ var Cache = (function (_Array) {
|
||||
if (item) {
|
||||
var index = this.indexOf(item);
|
||||
this[index] = data;
|
||||
this.discrimCache[data[this.discrim]] = data;
|
||||
return this[index];
|
||||
} else {
|
||||
return false;
|
||||
@@ -84,6 +70,7 @@ var Cache = (function (_Array) {
|
||||
};
|
||||
|
||||
Cache.prototype.remove = function remove(data) {
|
||||
delete this.discrimCache[data[this.discrim]];
|
||||
var index = this.indexOf(data);
|
||||
if (~index) {
|
||||
this.splice(index, 1);
|
||||
|
||||
Reference in New Issue
Block a user