Skip to content

Commit

Permalink
🔀 Merge pull request #1681 from TF2Autobot/less-pricelist-rewrite
Browse files Browse the repository at this point in the history
An option to limit pricelist rewrite
  • Loading branch information
idinium96 authored Oct 27, 2023
2 parents b77307d + fd77438 commit 60dec30
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/classes/Options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ export const DEFAULTS: JsonOptions = {
},
priceAge: {
maxInSeconds: 28800
},
rewriteFile: {
count: 1
}
},

Expand Down Expand Up @@ -1284,6 +1287,7 @@ interface Pricelist {
autoAddInvalidUnusual?: OnlyEnable;
autoAddPaintedItems?: OnlyEnable;
priceAge?: PriceAge;
rewriteFile?: RewriteFile;
}

interface PartialPriceUpdate extends OnlyEnable {
Expand All @@ -1295,6 +1299,10 @@ interface PriceAge {
maxInSeconds?: number;
}

interface RewriteFile {
count: number;
}

// ------------ Bypass ------------

interface Bypass {
Expand Down
10 changes: 9 additions & 1 deletion src/classes/Pricelist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ export default class Pricelist extends EventEmitter {

autoResetPartialPriceBulk: string[] = [];

private priceChangeCounter = 0;

assetidInPricelist: AssetidInPricelist = {};

checkAssetidInPricelistInterval: NodeJS.Timeout;
Expand Down Expand Up @@ -1337,7 +1339,13 @@ export default class Pricelist extends EventEmitter {

private priceChanged(priceKey: string | number, entry: Entry): void {
this.emit('price', priceKey, entry);
this.emit('pricelist', this.prices);

if (++this.priceChangeCounter % this.options.pricelist.rewriteFile.count === 0) {
// reference: https://github.com/Hhanuska/tf2autobot/commit/54c408936cc923d56d525f01726c042a84e1ec75
this.emit('pricelist', this.prices);

this.priceChangeCounter = 0;
}
}

private get getOld(): PricesObject {
Expand Down
14 changes: 13 additions & 1 deletion src/schemas/options-json/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,17 @@ export const optionsSchema: jsonschema.Schema = {
},
required: ['maxInSeconds'],
additionalProperties: false
},
rewriteFile: {
type: 'object',
properties: {
count: {
type: 'integer',
minimum: 1
}
},
required: ['count'],
additionalProperties: false
}
},
required: [
Expand All @@ -703,7 +714,8 @@ export const optionsSchema: jsonschema.Schema = {
'autoAddInvalidItems',
'autoAddInvalidUnusual',
'autoAddPaintedItems',
'priceAge'
'priceAge',
'rewriteFile'
],
additionalProperties: false
},
Expand Down

0 comments on commit 60dec30

Please sign in to comment.