diff --git a/src/node/db/PadManager.js b/src/node/db/PadManager.js index 80283b1e..89e6a84a 100644 --- a/src/node/db/PadManager.js +++ b/src/node/db/PadManager.js @@ -49,8 +49,8 @@ var globalPads = { * Updated without db access as new pads are created/old ones removed. */ let padList = { - list: [], - sorted : false, + list: new Set(), + cachedList: undefined, initiated: false, init: async function() { let dbData = await db.findKeys("pad:*", "*:*:*"); @@ -78,29 +78,26 @@ let padList = { getPads: async function() { await this.load(); - if (!this.sorted) { - this.list.sort(); - this.sorted = true; + if (!this.cachedList) { + this.cachedList = Array.from(this.list).sort(); } - return this.list; + return this.cachedList; }, addPad: function(name) { if (!this.initiated) return; - if (this.list.indexOf(name) == -1) { - this.list.push(name); - this.sorted = false; + if (!this.list.has(name)) { + this.list.add(name); + this.cachedList = undefined; } }, removePad: function(name) { if (!this.initiated) return; - var index = this.list.indexOf(name); - - if (index > -1) { - this.list.splice(index, 1); - this.sorted = false; + if (this.list.has(name)) { + this.list.delete(name); + this.cachedList = undefined; } } };