diff --git a/config.example.js b/config.example.js index 9581ea4..3b62a05 100644 --- a/config.example.js +++ b/config.example.js @@ -68,4 +68,6 @@ module.exports = { 'bulk_key': '', // OPTIONAL: Maximum queue size allowed before dropping requests 'max_queue_size': -1, + // OPTIONAL: If stickers are available, valve server shall prevail + 'realtime_sticker_wear': true, }; diff --git a/index.js b/index.js index 2180fd9..5c5ad65 100644 --- a/index.js +++ b/index.js @@ -23,6 +23,10 @@ if (CONFIG.max_simultaneous_requests === undefined) { CONFIG.max_simultaneous_requests = 1; } +if (CONFIG.realtime_sticker_wear === undefined) { + CONFIG.realtime_sticker_wear = false; +} + winston.level = CONFIG.logLevel || 'debug'; if (CONFIG.logins.length === 0) { @@ -85,7 +89,7 @@ const allowedRegexOrigins = CONFIG.allowed_regex_origins.map((origin) => new Reg async function handleJob(job) { // See which items have already been cached - const itemData = await postgres.getItemData(job.getRemainingLinks().map(e => e.link)); + const itemData = await postgres.getItemData(job.getRemainingLinks().map(e => e.link), CONFIG.realtime_sticker_wear); for (let item of itemData) { const link = job.getLink(item.a); diff --git a/lib/postgres.js b/lib/postgres.js index 043a62e..f731df5 100644 --- a/lib/postgres.js +++ b/lib/postgres.js @@ -299,17 +299,17 @@ class Postgres { return this.pool.query(`UPDATE items SET price = $1 WHERE a = $2`, [price, assetId]); } - async getItemData(links) { + async getItemData(links, realtimeStickerWear) { // Chunking into db calls of 100 each is more performant const chunked = utils.chunkArray(links, 100); - const promises = chunked.map(e => this._getItemData(e)); + const promises = chunked.map(e => this._getItemData(e, realtimeStickerWear)); const results = await Promise.all(promises); // Flatten results return results.reduce((acc, val) => acc.concat(val), []); } - async _getItemData(links) { + async _getItemData(links, realtimeStickerWear) { const aValues = links.map(e => utils.unsigned64ToSigned(e.getParams().a)); const result = await this.pool.query(` @@ -399,6 +399,13 @@ class Postgres { delete item.dupe_count; return item; + }).filter((item) => { + // If need to get sticker wear in real time, filter the current data + if (item.stickers.length > 0 && realtimeStickerWear) { + winston.debug(`Force data to be fetched from Valve ${item.a}`); + return false + } + return true }); }