0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00

Lazyloaded dependencies

- these dependencies do not need to be eagerly loaded so we can move
  them down to where they are used
This commit is contained in:
Daniel Lockyer 2024-10-10 09:37:24 +01:00 committed by Daniel Lockyer
parent c07a884f23
commit 0862989b2e
3 changed files with 6 additions and 5 deletions

View file

@ -1,5 +1,3 @@
const downsize = require('downsize');
function generateExcerpt(excerpt, truncateOptions) {
truncateOptions = truncateOptions || {};
@ -8,6 +6,7 @@ function generateExcerpt(excerpt, truncateOptions) {
}
// Just uses downsize to truncate, not format
const downsize = require('downsize');
return downsize(excerpt, truncateOptions);
}

View file

@ -2,7 +2,6 @@ const ghostBookshelf = require('./base');
const crypto = require('crypto');
const _ = require('lodash');
const config = require('../../shared/config');
const {gravatar} = require('../lib/image');
const Member = ghostBookshelf.Model.extend({
tableName: 'members',
@ -397,6 +396,7 @@ const Member = ghostBookshelf.Model.extend({
// Will not use gravatar if privacy.useGravatar is false in config
attrs.avatar_image = null;
if (attrs.email && !config.isPrivacyDisabled('useGravatar')) {
const {gravatar} = require('../lib/image');
attrs.avatar_image = gravatar.url(attrs.email, {size: 250, default: 'blank'});
}

View file

@ -3,8 +3,6 @@ const {VersionMismatchError} = require('@tryghost/errors');
// @ts-ignore
const debug = require('@tryghost/debug')('stripe');
const Stripe = require('stripe').Stripe;
// @ts-ignore
const LeakyBucket = require('leaky-bucket');
/* Stripe has the following rate limits:
* - For most APIs, 100 read requests per second in live mode, 25 read requests per second in test mode
@ -78,6 +76,10 @@ module.exports = class StripeAPI {
this._configured = false;
return;
}
// Lazyloaded to protect sites without Stripe configured
const LeakyBucket = require('leaky-bucket');
this._stripe = new Stripe(config.secretKey, {
apiVersion: STRIPE_API_VERSION
});