Skip to content

Commit

Permalink
Change updateQueue to a Set
Browse files Browse the repository at this point in the history
  • Loading branch information
builder-247 authored and ChristianDobbie committed Jan 10, 2022
1 parent cd31c31 commit 7e52927
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions svc/items.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const port = config.PORT || config.ITEMS_PORT;
let discoveredItems;
let bazaarProducts = [];
let itemList = {};
const updateQueue = [];
const updateQueue = new Set();

(async function init() {
try {
Expand Down Expand Up @@ -72,7 +72,7 @@ app.post('/', (request, response, _callback) => {
let updates = false;
items.forEach((item) => {
const { id } = item;
if (!discoveredItems.has(id) || updateQueue.includes(id)) {
if (!discoveredItems.has(id) || updateQueue.has(id)) {
updates = true;
logger.info(`Found new item ID ${id}`);
if (item.texture === null) {
Expand All @@ -84,6 +84,9 @@ app.post('/', (request, response, _callback) => {
delete item.id;
itemList[id] = item;
discoveredItems.add(id);
if (updateQueue.has(id)) {
updateQueue.delete(id);
}
}
});
if (updates) {
Expand All @@ -95,7 +98,7 @@ app.delete('/:id', (request, response, _callback) => {
const { id } = request.params;
if (id in itemList) {
logger.info(`Adding item ${id} to update queue`);
updateQueue.push(id);
updateQueue.add(id);
}
response.json({ status: 'ok' });
});
Expand Down

0 comments on commit 7e52927

Please sign in to comment.