Merge pull request #2925 from specklesystems/fabians/stats-ioc-4
chore(server): stats IoC 4 - getTotalUserCountFactory
This commit is contained in:
@@ -9,7 +9,7 @@ import {
|
||||
} from '@/modules/core/services/admin'
|
||||
import {
|
||||
getTotalStreamCountFactory,
|
||||
getTotalUserCount
|
||||
getTotalUserCountFactory
|
||||
} from '@/modules/stats/repositories'
|
||||
|
||||
export = {
|
||||
@@ -46,7 +46,7 @@ export = {
|
||||
},
|
||||
|
||||
async totalUserCount() {
|
||||
return await getTotalUserCount()
|
||||
return await getTotalUserCountFactory({ db })()
|
||||
},
|
||||
async totalPendingInvites() {
|
||||
return 0
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
getTotalStreamCountFactory,
|
||||
getTotalCommitCountFactory,
|
||||
getTotalObjectCountFactory,
|
||||
getTotalUserCount
|
||||
getTotalUserCountFactory
|
||||
} from '@/modules/stats/repositories/index'
|
||||
import { Roles, Scopes } from '@speckle/shared'
|
||||
import { throwForNotHavingServerRole } from '@/modules/shared/authz'
|
||||
@@ -41,7 +41,7 @@ export = {
|
||||
},
|
||||
|
||||
async totalUserCount() {
|
||||
return await getTotalUserCount()
|
||||
return await getTotalUserCountFactory({ db })()
|
||||
},
|
||||
|
||||
async streamHistory() {
|
||||
|
||||
@@ -19,11 +19,11 @@ export const getTotalObjectCountFactory = (deps: { db: Knex }) => async () => {
|
||||
return parseInt(result.rows[0].count)
|
||||
}
|
||||
|
||||
export async function getTotalUserCount() {
|
||||
export const getTotalUserCountFactory = (deps: { db: Knex }) => async () => {
|
||||
// returns -1 for small tables, no good
|
||||
// const fastQuery = "SELECT reltuples::bigint AS estimate FROM pg_catalog.pg_class WHERE relname = 'users'"
|
||||
const query = 'SELECT COUNT(*) FROM users'
|
||||
const result = await knex.raw(query)
|
||||
const result = await deps.db.raw(query)
|
||||
return parseInt(result.rows[0].count)
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ import {
|
||||
getTotalStreamCountFactory,
|
||||
getTotalCommitCountFactory,
|
||||
getTotalObjectCountFactory,
|
||||
getTotalUserCount
|
||||
getTotalUserCountFactory
|
||||
} from '@/modules/stats/repositories/index'
|
||||
import { Scopes } from '@speckle/shared'
|
||||
import { Server } from 'node:http'
|
||||
@@ -34,7 +34,7 @@ describe('Server stats services @stats-services', function () {
|
||||
})
|
||||
|
||||
it('should return the total number of users on this server', async () => {
|
||||
const res = await getTotalUserCount()
|
||||
const res = await getTotalUserCountFactory({ db })()
|
||||
expect(res).to.equal(params.numUsers)
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user