mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-23 22:11:09 +03:00
Optimized queries for tiers (aka products)
refs https://github.com/TryGhost/Toolbox/issues/515 refsdd4d6aeae5
- The `productRepository.list` call produced 5 db queries and a transaction wrapping this call. - Transaction is not needed in this situation as there are no possible writes in the meantime (transaction wrapping code was put in there through refed commit to guard against failing Stripe API calls, which are no longer involved when calling the list method) - The `limit: 'all'` makes sure all product entries are fetched AND removes an extra aggregation query called over stripe_prices join - The 'monthlyPrice' and 'yearlyPrice' relations are not needed because this data is not used in downstream code - only slug and type are used for visiblity/content gating (ref. 13b6759ca6d/ghost/core/core/server/services/members/content-gating.js (L44-L55)
, ref. 23b6759ca6d/ghost/core/core/server/api/endpoints/utils/serializers/output/mappers/posts.js (L39-L54)
)
This commit is contained in:
parent
ca568817dd
commit
93a10d8f4f
@ -5,7 +5,7 @@ const membersService = require('../../../../../services/members');
|
||||
module.exports = {
|
||||
async read(model, apiConfig, frame) {
|
||||
const tiersModels = await membersService.api.productRepository.list({
|
||||
withRelated: ['monthlyPrice', 'yearlyPrice']
|
||||
limit: 'all'
|
||||
});
|
||||
const tiers = tiersModels.data && tiersModels.data.map(tierModel => tierModel.toJSON());
|
||||
|
||||
|
@ -13,7 +13,7 @@ module.exports = {
|
||||
let pages = [];
|
||||
|
||||
const tiersModels = await membersService.api.productRepository.list({
|
||||
withRelated: ['monthlyPrice', 'yearlyPrice']
|
||||
limit: 'all'
|
||||
});
|
||||
const tiers = tiersModels.data ? tiersModels.data.map(tierModel => tierModel.toJSON()) : [];
|
||||
|
||||
|
@ -13,7 +13,7 @@ module.exports = {
|
||||
let posts = [];
|
||||
|
||||
const tiersModels = await membersService.api.productRepository.list({
|
||||
withRelated: ['monthlyPrice', 'yearlyPrice']
|
||||
limit: 'all'
|
||||
});
|
||||
const tiers = tiersModels.data ? tiersModels.data.map(tierModel => tierModel.toJSON()) : [];
|
||||
if (models.meta) {
|
||||
|
@ -4,7 +4,7 @@ const membersService = require('../../../../../services/members');
|
||||
module.exports = {
|
||||
async all(model, apiConfig, frame) {
|
||||
const tiersModels = await membersService.api.productRepository.list({
|
||||
withRelated: ['monthlyPrice', 'yearlyPrice']
|
||||
limit: 'all'
|
||||
});
|
||||
const tiers = tiersModels.data ? tiersModels.data.map(tierModel => tierModel.toJSON()) : [];
|
||||
|
||||
|
@ -650,14 +650,6 @@ class ProductRepository {
|
||||
* @returns {Promise<{data: ProductModel[], meta: object}>}
|
||||
**/
|
||||
async list(options = {}) {
|
||||
if (!options.transacting) {
|
||||
return this._Product.transaction((transacting) => {
|
||||
return this.list({
|
||||
...options,
|
||||
transacting
|
||||
});
|
||||
});
|
||||
}
|
||||
return this._Product.findPage(options);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user