mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-27 18:52:14 +03:00
f30d3cd2c2
no issue - tested performance between knex raw, knex `count()` and bookshelf `count()` and found no difference over 1000 iterations of each (each ~19,500ms +- 500ms for 104k members locally) - switched to using bookshelf as the code is the simplest
30 lines
1.0 KiB
JavaScript
30 lines
1.0 KiB
JavaScript
const config = require('../../../shared/config');
|
|
const models = require('../../models');
|
|
const errors = require('@tryghost/errors');
|
|
|
|
// Get total members direct from DB
|
|
async function getTotalMembers() {
|
|
return models.Member.count('id');
|
|
}
|
|
|
|
module.exports = async () => {
|
|
const membersHostLimit = config.get('host_settings:limits:members');
|
|
if (membersHostLimit) {
|
|
const allowedMembersLimit = membersHostLimit.max;
|
|
const hostUpgradeLink = config.get('host_settings:limits').upgrade_url;
|
|
|
|
const totalMembers = await getTotalMembers();
|
|
|
|
if (totalMembers > allowedMembersLimit) {
|
|
throw new errors.HostLimitError({
|
|
message: `Your current plan allows you to have up to ${allowedMembersLimit} members, but you currently have ${totalMembers} members`,
|
|
help: hostUpgradeLink,
|
|
errorDetails: {
|
|
limit: allowedMembersLimit,
|
|
total: totalMembers
|
|
}
|
|
});
|
|
}
|
|
}
|
|
};
|