0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-11 02:12:21 -05:00

Switched to bookshelf count in getTotalMembers()

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
This commit is contained in:
Kevin Ansfield 2020-08-27 01:52:36 +01:00
parent a995e9cc89
commit f30d3cd2c2

View file

@ -1,13 +1,10 @@
const config = require('../../../shared/config'); const config = require('../../../shared/config');
const db = require('../../data/db'); const models = require('../../models');
const errors = require('@tryghost/errors'); const errors = require('@tryghost/errors');
// Get total members direct from DB // Get total members direct from DB
// @TODO: determine performance difference between this, normal knex, and using the model layer
async function getTotalMembers() { async function getTotalMembers() {
const isSQLite = config.get('database:client') === 'sqlite3'; return models.Member.count('id');
const result = await db.knex.raw('SELECT COUNT(id) AS total FROM members');
return isSQLite ? result[0].total : result[0][0].total;
} }
module.exports = async () => { module.exports = async () => {