Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional configuration whether to get real-time sticker wear or not #211

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions config.example.js
Original file line number Diff line number Diff line change
Expand Up @@ -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': false,
};
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);

Expand Down
13 changes: 10 additions & 3 deletions lib/postgres.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(`
Expand Down Expand Up @@ -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
});
}

Expand Down
Loading