-
Notifications
You must be signed in to change notification settings - Fork 54
perf: Use Apify-provided environment variables to obtain PPE pricing information #483
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
base: master
Are you sure you want to change the base?
Conversation
janbuchar
commented
Oct 7, 2025
- closes Load Actor pricing and charged events from env vars #481
Let's call this perf optimization, that's the main point of why we do it, right? |
E2E test is failing - I probably broke the charge limit logic |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
https://github.com/apify/apify-sdk-js/actions/runs/18348147670 e2e test run - should be OK now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, thank you! 👍
I have a few ideas about the code quality, but neither is strictly necessary
this.chargingState[eventName] = { | ||
chargeCount, | ||
totalChargedAmount: | ||
chargeCount * (this.pricingInfo[eventName]?.price ?? 0), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: you have to call the new load*
methods in this specific order, as loadChargedEventCounts
reads variables initialized by loadPricingInfo
(temporal coupling)
title: eventPricing.eventTitle, | ||
}; | ||
if ( | ||
this.chargingState === undefined || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about removing the load*
method calls from the constructor, running them only once in the init
method (at one call site) and conditionally loading the config with something like
async function getPricingInfo() {
if (
configuration.get('actorPricingInfo') &&
configuration.get('chargedEventCounts')
) return { pricingInfo: JSON.parse(), ...
const run = await this.apifyClient.run(this.actorRunId).get();
...
}
This would allow us to load the pricing info + events at one point in init
like
...
const { pricingInfo ... } = await getPricingInfo();
this.loadPricingInfo( pricingInfo );
...
which is IMO cleaner than the current approach, which is conditional based on the current object state