Limited Stripe price lookups (#15823)

refs https://github.com/TryGhost/Team/issues/2262

Makes sure we only loop active Stripe prices. If we find an inactive
price, we also update it in our database now after this change.
This commit is contained in:
Simon Backx 2022-11-17 14:33:46 +01:00 committed by GitHub
parent 69228b2947
commit 9c12a2a043
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 4 deletions

View File

@ -214,8 +214,9 @@ class PaymentsService {
stripe_product_id: product.id,
currency,
interval: cadence,
amount
}).query().select('stripe_price_id');
amount,
active: true
}).query().select('id', 'stripe_price_id');
for (const row of rows) {
try {
@ -224,9 +225,15 @@ class PaymentsService {
return {
id: price.id
};
} else {
// Update the database model to prevent future Stripe fetches when it is not needed
await this.StripePriceModel.edit({
active: !!price.active
}, {id: row.id});
}
} catch (err) {
logging.warn(err);
logging.error(`Failed to lookup Stripe Price ${row.stripe_price_id}`);
logging.error(err);
}
}

View File

@ -1,5 +1,5 @@
const {VersionMismatchError} = require('@tryghost/errors');
const debug = require('@tryghost/debug');
const debug = require('@tryghost/debug')('stripe');
const Stripe = require('stripe').Stripe;
const LeakyBucket = require('leaky-bucket');
const EXPECTED_API_EFFICIENCY = 0.95;