mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-23 22:11:09 +03:00
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:
parent
69228b2947
commit
9c12a2a043
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user